From 57669d0f5cffd6b95dc47817f5ac045e3186de85 Mon Sep 17 00:00:00 2001 From: "halil.cakal" Date: Thu, 24 Apr 2025 09:47:57 +0100 Subject: [PATCH] Automate the CPS-NCMP metrics scraping - import ScrapeMetrics, test_ScrapeMetrics and run from conf .py to automate the scraping - the scripts will be running with tox when building the docs - update unit tests to use test specific names - highlight the header row of metrics' table Issue-ID: CPS-2778 Change-Id: I843221ec21454220ea1182c488f88813c0691c4a Signed-off-by: halil.cakal --- docs/admin-guide.rst | 1 + docs/conf.py | 10 +++++++++- docs/test_ScrapeMetrics.py | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/admin-guide.rst b/docs/admin-guide.rst index 447a1717d3..8f0634a525 100644 --- a/docs/admin-guide.rst +++ b/docs/admin-guide.rst @@ -225,6 +225,7 @@ Below table lists all CPS-NCMP custom metrics .. csv-table:: :file: csv/metrics.csv :widths: 50, 50 + :header-rows: 1 Prometheus Metrics can be checked at the following endpoint diff --git a/docs/conf.py b/docs/conf.py index 364efe8f1d..d3ec5df1ec 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (C) 2021 Nordix Foundation +# Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ from docutils.parsers.rst import directives +import subprocess + project = "onap" release = "master" version = "master" @@ -69,6 +71,12 @@ linkcheck_ignore = [ html_last_updated_fmt = '%d-%b-%y %H:%M' +# Run ScrapeMetrics.py +subprocess.run(["python3", "ScrapeMetrics.py"], check=True) + +# Run test_ScrapeMetrics.py +subprocess.run(["python3", "test_ScrapeMetrics.py"], check=True) + def setup(app): app.add_css_file("css/ribbon.css") diff --git a/docs/test_ScrapeMetrics.py b/docs/test_ScrapeMetrics.py index 62365fdaf0..cbcc92d2a1 100644 --- a/docs/test_ScrapeMetrics.py +++ b/docs/test_ScrapeMetrics.py @@ -55,7 +55,7 @@ class TestScrapeMetrics(unittest.TestCase): @Timed(value="timed", description="A timed metric") public void anotherMethod() {} - @TimedCustom(name="cps_ncmp_inventory_cm_handles_by_state{state=DELETING}", description="A custom timed metric") + @TimedCustom(name="custom counter name", description="A custom timed metric") public void anotherMethod() {} @NotTimed @@ -65,7 +65,7 @@ class TestScrapeMetrics(unittest.TestCase): expected_metrics = [ '"cm_handle_search_invocation_total","A description does not fit the a single line"', '"timed","A timed metric"', - '"cps_ncmp_inventory_cm_handles_by_state{state=DELETING}","A custom timed metric"' + '"custom counter name","A custom timed metric"' ] result = scrape_all_metrics_from_file(test_file) self.assertEqual(len(result), 3) -- 2.16.6