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

Add auth parameter on PrometheusRemoteWriteMetricsExporter to enable Custom HTTP authentication like AWS Sigv4 #2254

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class PrometheusRemoteWriteMetricsExporter(MetricExporter):
timeout: timeout for remote write requests in seconds, defaults to 30 (Optional)
proxies: dict mapping request proxy protocols to proxy urls (Optional)
tls_config: configuration for remote write TLS settings (Optional)
auth: auth tuple or callable to enable Basic/Digest/Custom HTTP Auth (Optional)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callable should be compatible with requests though, so it should take a requests' Request as parameter and set whatever header is required. The problem with that though is that it'll leak the implementation. So maybe is it better to expand the documentation of the exporter to add an example on how to add authentication using just headers instead?

"""

def __init__(
Expand All @@ -79,6 +80,7 @@ def __init__(
resources_as_labels: bool = True,
preferred_temporality: Dict[type, AggregationTemporality] = None,
preferred_aggregation: Dict = None,
auth = None,
):
self.endpoint = endpoint
self.basic_auth = basic_auth
Expand All @@ -87,6 +89,7 @@ def __init__(
self.tls_config = tls_config
self.proxies = proxies
self.resources_as_labels = resources_as_labels
self.auth = auth

if not preferred_temporality:
preferred_temporality = {
Expand Down Expand Up @@ -181,6 +184,14 @@ def headers(self):
def headers(self, headers: Dict):
self._headers = headers

@property
def auth(self):
return self._auth

@auth.setter
def auth(self, auth):
self._auth = auth

def export(
self,
metrics_data: MetricsData,
Expand Down Expand Up @@ -370,6 +381,8 @@ def _send_message(
auth = None
if self.basic_auth:
auth = (self.basic_auth["username"], self.basic_auth["password"])
elif self.auth:
auth = self.auth

cert = None
verify = True
Expand Down
Loading