Skip to content

Commit 31b910d

Browse files
committed
Setup Prometheus Remote Write Exporter
1 parent 7513d7b commit 31b910d

File tree

9 files changed

+411
-0
lines changed

9 files changed

+411
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
## Unreleased
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
OpenTelemetry Prometheus Remote Write Exporter
2+
==============================================
3+
4+
This library allows exporting metric data to `Prometheus Write Integrated Backends
5+
<https://prometheus.io/docs/operating/integrations/>`_. Development is currently in progress.
6+
7+
Installation
8+
------------
9+
10+
::
11+
12+
pip install opentelemetry-exporter-prometheus-remote-write
13+
14+
15+
.. _Prometheus: https://prometheus.io/
16+
.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/
17+
18+
19+
References
20+
----------
21+
22+
* `Datadog <https://prometheus.io/>`_
23+
* `OpenTelemetry Project <https://opentelemetry.io/>`_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
[metadata]
16+
name = opentelemetry-exporter-prometheus-remote-write
17+
description = Prometheus Remote Write Metrics Exporter for OpenTelemetry
18+
long_description = file: README.rst
19+
long_description_content_type = text/x-rst
20+
author = OpenTelemetry Authors
21+
author_email = [email protected]
22+
url = https://github.com/open-telemetry/opentelemetry-python/exporter/opentelemetry-exporter-datadog
23+
platforms = any
24+
license = Apache-2.0
25+
classifiers =
26+
Development Status :: 4 - Beta
27+
Intended Audience :: Developers
28+
License :: OSI Approved :: Apache Software License
29+
Programming Language :: Python
30+
Programming Language :: Python :: 3
31+
Programming Language :: Python :: 3.5
32+
Programming Language :: Python :: 3.6
33+
Programming Language :: Python :: 3.7
34+
Programming Language :: Python :: 3.8
35+
36+
[options]
37+
python_requires = >=3.5
38+
package_dir=
39+
=src
40+
packages=find_namespace:
41+
install_requires =
42+
ddtrace>=0.34.0
43+
opentelemetry-api == 0.16.dev0
44+
opentelemetry-sdk == 0.16.dev0
45+
46+
[options.packages.find]
47+
where = src
48+
49+
[options.extras_require]
50+
test =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
17+
import setuptools
18+
19+
BASE_DIR = os.path.dirname(__file__)
20+
VERSION_FILENAME = os.path.join(
21+
BASE_DIR,
22+
"src",
23+
"opentelemetry",
24+
"exporter",
25+
"prometheus_remote_write",
26+
"version.py",
27+
)
28+
PACKAGE_INFO = {}
29+
with open(VERSION_FILENAME) as f:
30+
exec(f.read(), PACKAGE_INFO)
31+
32+
setuptools.setup(version=PACKAGE_INFO["__version__"])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
from typing import Dict, Sequence
17+
18+
from opentelemetry.sdk.metrics.export import (
19+
MetricRecord,
20+
MetricsExporter,
21+
MetricsExportResult,
22+
)
23+
24+
25+
class TimeSeries:
26+
"""
27+
TimeSeries class used to store timeseries labels and samples that need to be sent
28+
Args:
29+
labels: timeseries labels
30+
samples: timeseries samples
31+
"""
32+
33+
def __init__(self):
34+
pass
35+
36+
37+
class Config:
38+
"""
39+
Configuration containing all necessary information to make remote write requests
40+
41+
Args:
42+
endpoint: url where data will be sent
43+
basic_auth: username and password for authentication (Optional)
44+
bearer_token: token used for authentication (Optional)
45+
bearer_token_file: filepath to file containing authentication token (Optional)
46+
headers: additional headers for remote write request (Optional)
47+
"""
48+
49+
def __init__(
50+
self,
51+
endpoint: str,
52+
basic_auth: Dict = None,
53+
bearer_token: str = None,
54+
bearer_token_file: str = None,
55+
headers: Dict = None,
56+
):
57+
pass
58+
59+
def validate(self):
60+
pass
61+
62+
63+
class PrometheusRemoteWriteMetricsExporter(MetricsExporter):
64+
"""
65+
Prometheus remote write metric exporter for OpenTelemetry.
66+
67+
Args:
68+
config: configuration containing all necessary information to make remote write requests
69+
"""
70+
71+
def __init__(self, config: Config):
72+
pass
73+
74+
def export(
75+
self, metric_records: Sequence[MetricRecord]
76+
) -> MetricsExportResult:
77+
pass
78+
79+
def shutdown(self) -> None:
80+
pass
81+
82+
def convert_to_timeseries(
83+
self, metric_records: Sequence[MetricRecord]
84+
) -> Sequence[TimeSeries]:
85+
pass
86+
87+
def convert_from_sum(self, sum_record: MetricRecord) -> TimeSeries:
88+
pass
89+
90+
def convert_from_min_max_sum_count(
91+
self, min_max_sum_count_record: MetricRecord
92+
) -> TimeSeries:
93+
pass
94+
95+
def convert_from_histogram(
96+
self, histogram_record: MetricRecord
97+
) -> TimeSeries:
98+
pass
99+
100+
def convert_from_last_value(
101+
self, last_value_record: MetricRecord
102+
) -> TimeSeries:
103+
pass
104+
105+
def convert_from_value_observer(
106+
self, value_observer_record: MetricRecord
107+
) -> TimeSeries:
108+
pass
109+
110+
def convert_from_summary(self, summary_record: MetricRecord) -> TimeSeries:
111+
pass
112+
113+
def sanitize_label(self, label: str) -> str:
114+
pass
115+
116+
def build_message(self, data: Sequence[TimeSeries]) -> str:
117+
pass
118+
119+
def get_headers(self) -> Dict:
120+
pass
121+
122+
def send_message(self, message: str, headers: Dict) -> int:
123+
pass
124+
125+
126+
def parse_config() -> Config:
127+
"""
128+
Method that parses yaml file to generate a valid remote write exporter config
129+
130+
Args:
131+
path: filepath to yaml configuration file
132+
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
__version__ = "0.16.dev0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
17+
18+
# Series of test cases to ensure config validation works as intended
19+
class TestConfig(unittest.TestCase):
20+
def test_valid_standard_config(self):
21+
pass
22+
23+
def test_valid_basic_auth_config(self):
24+
pass
25+
26+
def test_valid_bearer_token_config(self):
27+
pass
28+
29+
def test_valid_quantiles_config(self):
30+
pass
31+
32+
def test_valid_histogram_boundaries_config(self):
33+
pass
34+
35+
def test_valid_tls_config(self):
36+
pass
37+
38+
def test_invalid_no_url_config(self):
39+
pass
40+
41+
def test_invalid_no_name_config(self):
42+
pass
43+
44+
def test_invalid_no_remote_timeout_config(self):
45+
pass
46+
47+
def test_invalid_no_username_config(self):
48+
pass
49+
50+
def test_invalid_no_password_config(self):
51+
pass
52+
53+
def test_invalid_conflicting_passwords_config(self):
54+
pass
55+
56+
def test_invalid_conflicting_bearer_tokens_config(self):
57+
pass
58+
59+
def test_invalid_conflicting_auth_config(self):
60+
pass
61+
62+
def test_invalid_quantiles_config(self):
63+
pass
64+
65+
def test_invalid_histogram_boundaries_config(self):
66+
pass
67+
68+
# Verifies that valid yaml file is parsed correctly
69+
def test_valid_yaml_file(self):
70+
pass
71+
72+
# Ensures invalid filepath raises error when parsing
73+
def test_invalid_yaml_file(self):
74+
pass

0 commit comments

Comments
 (0)