Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional url #12

Merged
merged 3 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 2.0.0

- Changed prometheus url to be optional.
(Existing actions passing url as an empty string must be updated by removing the url parameter.)

# 1.0.0

* Drop Python 2.7 support
Expand Down
1 change: 1 addition & 0 deletions actions/lib/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions actions/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
1 change: 1 addition & 0 deletions actions/query.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ parameters:
url:
description: "Prometheus Url"
type: string
required: false
4 changes: 2 additions & 2 deletions actions/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 2 additions & 4 deletions actions/series.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions actions/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
arm4b marked this conversation as resolved.
Show resolved Hide resolved
endpoint = "{}/api/v1/targets".format(url_temp)
return True, self._get(endpoint, None)
8 changes: 3 additions & 5 deletions actions/targets.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions config.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---

url:
description: "Prometheus Url"
type: string
required: true

2 changes: 1 addition & 1 deletion pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords:
- prometheus
- monitoring
- metrics
version: 1.0.0
version: 2.0.0
python_versions:
- "3"
author: Daniel Chamot
Expand Down