From 8663abb9b9238622e23636f75c4ff91ce5bf0643 Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 8 Oct 2020 00:06:24 +0200 Subject: [PATCH 1/2] Make prometheus URL optional and use lowercase for "target" action names. --- actions/lib/prometheus.py | 1 + actions/query.py | 4 ++-- actions/series.py | 4 ++-- actions/series.yaml | 6 ++---- actions/targets.py | 4 ++-- actions/targets.yaml | 8 +++----- config.schema.yaml | 2 -- 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/actions/lib/prometheus.py b/actions/lib/prometheus.py index 1bf8b59..339e0dc 100644 --- a/actions/lib/prometheus.py +++ b/actions/lib/prometheus.py @@ -6,6 +6,7 @@ except ImportError: from urllib3.exceptions import InsecureRequestWarning from st2common.runners.base_action import Action + requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # pylint: disable=no-member diff --git a/actions/query.py b/actions/query.py index 2c92e8c..08eb963 100644 --- a/actions/query.py +++ b/actions/query.py @@ -7,7 +7,7 @@ class PrometheusQuery(PrometheusAPI): def __init__(self, config): super(PrometheusQuery, self).__init__(config=config) - def run(self, query, url): - url_temp = self.url if url == "" else url + def run(self, query, url=None): + url_temp = self.url if url is None else url endpoint = "{}/api/v1/query".format(url_temp) return True, self._get(endpoint, params={"query": query}) diff --git a/actions/series.py b/actions/series.py index 04cbc88..ad17a40 100644 --- a/actions/series.py +++ b/actions/series.py @@ -7,8 +7,8 @@ class PrometheusSeries(PrometheusAPI): def __init__(self, config): super(PrometheusSeries, self).__init__(config=config) - def run(self, queries, url): + def run(self, queries, url=None): params = ['match[]=' + query for __, query in queries.iteritems()] - url_temp = self.url if url == "" else url + url_temp = self.url if url is None else url endpoint = "{}/api/v1/series?{}".format(url_temp, '&'.join(params)) return True, self._get(endpoint, None) diff --git a/actions/series.yaml b/actions/series.yaml index 59c93fb..2373eb5 100644 --- a/actions/series.yaml +++ b/actions/series.yaml @@ -1,14 +1,12 @@ --- - name: series description: 'Query Prometheus Series API' - runner_type: python-script entry_point: series.py - parameters: queries: type: object url: - description: "Prometheus Url" + description: "Prometheus URL" type: string + required: false diff --git a/actions/targets.py b/actions/targets.py index d5cd8fc..4695c26 100644 --- a/actions/targets.py +++ b/actions/targets.py @@ -7,7 +7,7 @@ class PrometheusTarget(PrometheusAPI): def __init__(self, config): super(PrometheusTarget, self).__init__(config=config) - def run(self, url): - url_temp = self.url if url == "" else url + def run(self, url=None): + url_temp = self.url if url is None else url endpoint = "{}/api/v1/targets".format(url_temp) return True, self._get(endpoint, None) diff --git a/actions/targets.yaml b/actions/targets.yaml index a88b4dd..a2ef62f 100644 --- a/actions/targets.yaml +++ b/actions/targets.yaml @@ -1,12 +1,10 @@ --- - -name: Targets +name: targets description: 'Prometheus Targets API' - runner_type: python-script entry_point: targets.py - parameters: url: - description: "Prometheus Url" + description: "Prometheus URL" type: string + required: false diff --git a/config.schema.yaml b/config.schema.yaml index 5357baf..ecdeaed 100644 --- a/config.schema.yaml +++ b/config.schema.yaml @@ -1,7 +1,5 @@ --- - url: description: "Prometheus Url" type: string required: true - From 34fe70c09e7b63be112f67aa7f357846e3ce0822 Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 30 Nov 2020 18:19:18 +0100 Subject: [PATCH 2/2] changelog and pack version bump --- CHANGES.md | 4 ++++ actions/query.yaml | 1 + pack.yaml | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index beef4e3..880fd4b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Change Log +## 0.3.0 + +- Changed prometheus url to be optional. + ## 0.2.1 - Added action to get targets from prometheus diff --git a/actions/query.yaml b/actions/query.yaml index 3e15e83..9991453 100644 --- a/actions/query.yaml +++ b/actions/query.yaml @@ -12,3 +12,4 @@ parameters: url: description: "Prometheus Url" type: string + required: false diff --git a/pack.yaml b/pack.yaml index 550f518..766272c 100644 --- a/pack.yaml +++ b/pack.yaml @@ -6,7 +6,7 @@ keywords: - prometheus - monitoring - metrics -version: 0.2.1 +version: 0.3.0 python_versions: - "2" - "3"