Skip to content

Commit 83e15ea

Browse files
committed
Setup Prometheus Remote Write Exporter
1 parent 18c18f3 commit 83e15ea

File tree

17 files changed

+2354
-2
lines changed

17 files changed

+2354
-2
lines changed

.flake8

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ exclude =
1919
__pycache__
2020
exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/gen/
2121
exporter/opentelemetry-exporter-jaeger/build/*
22+
exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/gen
2223
docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/grpc/gen/
2324
docs/examples/opentelemetry-example-app/build/*
2425
opentelemetry-python-core/

.pylintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ contextmanager-decorators=contextlib.contextmanager
165165
# List of members which are set dynamically and missed by pylint inference
166166
# system, and so shouldn't trigger E1101 when accessed. Python regular
167167
# expressions are accepted.
168-
generated-members=
168+
generated-members=*_pb2.py
169169

170170
# Tells whether missing members accessed in mixin class should be ignored. A
171171
# mixin class is detected if its name ends with "mixin" (case insensitive).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## Unreleased
4+
- Prometheus Remote Write Exporter Setup
5+
((#180)[https://github.com/open-telemetry/opentelemetry-python-contrib/pull/180])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
OpenTelemetry Prometheus Remote Write Exporter
2+
==============================================
3+
4+
This library allows exporting metric data to `Prometheus Remote Write Integrated Backends
5+
<https://prometheus.io/docs/operating/integrations/>`_. Latest `types.proto
6+
<https://github.com/prometheus/prometheus/blob/master/prompb/types.proto>` and `remote.proto
7+
<https://github.com/prometheus/prometheus/blob/master/prompb/remote.proto>` Protocol Buffers
8+
used to create WriteRequest objects were taken from Prometheus repository. Development is
9+
currently in progress.
10+
11+
Installation
12+
------------
13+
14+
::
15+
16+
pip install opentelemetry-exporter-prometheus-remote-write
17+
18+
19+
.. _Prometheus: https://prometheus.io/
20+
.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/
21+
22+
23+
References
24+
----------
25+
26+
* `Prometheus <https://prometheus.io/>`_
27+
* `OpenTelemetry Project <https://opentelemetry.io/>`_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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-contrib/tree/master/exporter/opentelemetry-exporter-prometheus-remote-write
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+
opentelemetry-api == 0.16.dev0
43+
opentelemetry-sdk == 0.16.dev0
44+
45+
[options.packages.find]
46+
where = src
47+
48+
[options.extras_require]
49+
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,113 @@
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+
from typing import Dict, Sequence
16+
17+
from opentelemetry.exporter.prometheus_remote_write.gen.types_pb2 import (
18+
Label,
19+
Sample,
20+
TimeSeries,
21+
)
22+
from opentelemetry.sdk.metrics.export import (
23+
ExportRecord,
24+
MetricsExporter,
25+
MetricsExportResult,
26+
)
27+
28+
29+
class PrometheusRemoteWriteMetricsExporter(MetricsExporter):
30+
"""
31+
Prometheus remote write metric exporter for OpenTelemetry.
32+
33+
Args:
34+
endpoint: url where data will be sent (Required)
35+
basic_auth: username and password for authentication (Optional)
36+
bearer_token: token used for authentication (Optional)
37+
bearer_token_file: filepath to file containing authentication token (Optional)
38+
headers: additional headers for remote write request (Optional
39+
"""
40+
41+
def __init__(
42+
self,
43+
endpoint: str,
44+
basic_auth: Dict = None,
45+
bearer_token: str = None,
46+
bearer_token_file: str = None,
47+
headers: Dict = None,
48+
):
49+
raise NotImplementedError()
50+
51+
def export(
52+
self, export_records: Sequence[ExportRecord]
53+
) -> MetricsExportResult:
54+
raise NotImplementedError()
55+
56+
def shutdown(self) -> None:
57+
raise NotImplementedError()
58+
59+
def convert_to_timeseries(
60+
self, export_records: Sequence[ExportRecord]
61+
) -> Sequence[TimeSeries]:
62+
raise NotImplementedError()
63+
64+
def convert_from_sum(self, sum_record: ExportRecord) -> TimeSeries:
65+
raise NotImplementedError()
66+
67+
def convert_from_min_max_sum_count(
68+
self, min_max_sum_count_record: ExportRecord
69+
) -> TimeSeries:
70+
raise NotImplementedError()
71+
72+
def convert_from_histogram(
73+
self, histogram_record: ExportRecord
74+
) -> TimeSeries:
75+
raise NotImplementedError()
76+
77+
def convert_from_last_value(
78+
self, last_value_record: ExportRecord
79+
) -> TimeSeries:
80+
raise NotImplementedError()
81+
82+
def convert_from_value_observer(
83+
self, value_observer_record: ExportRecord
84+
) -> TimeSeries:
85+
raise NotImplementedError()
86+
87+
def convert_from_quantile(
88+
self, summary_record: ExportRecord
89+
) -> TimeSeries:
90+
raise NotImplementedError()
91+
92+
# pylint: disable=no-member
93+
def create_timeseries(
94+
self, export_record: ExportRecord, name, value: float
95+
) -> TimeSeries:
96+
raise NotImplementedError()
97+
98+
def create_sample(self, timestamp: int, value: float) -> Sample:
99+
raise NotImplementedError()
100+
101+
def create_label(self, name: str, value: str) -> Label:
102+
raise NotImplementedError()
103+
104+
def build_message(self, timeseries: Sequence[TimeSeries]) -> bytes:
105+
raise NotImplementedError()
106+
107+
def get_headers(self) -> Dict:
108+
raise NotImplementedError()
109+
110+
def send_message(
111+
self, message: bytes, headers: Dict
112+
) -> MetricsExportResult:
113+
raise NotImplementedError()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Protocol Buffers for Go with Gadgets
2+
//
3+
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
4+
// http://github.com/gogo/protobuf
5+
//
6+
// Redistribution and use in source and binary forms, with or without
7+
// modification, are permitted provided that the following conditions are
8+
// met:
9+
//
10+
// * Redistributions of source code must retain the above copyright
11+
// notice, this list of conditions and the following disclaimer.
12+
// * Redistributions in binary form must reproduce the above
13+
// copyright notice, this list of conditions and the following disclaimer
14+
// in the documentation and/or other materials provided with the
15+
// distribution.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
syntax = "proto2";
30+
package gogoproto;
31+
32+
import "google/protobuf/descriptor.proto";
33+
34+
option java_package = "com.google.protobuf";
35+
option java_outer_classname = "GoGoProtos";
36+
option go_package = "github.com/gogo/protobuf/gogoproto";
37+
38+
extend google.protobuf.EnumOptions {
39+
optional bool goproto_enum_prefix = 62001;
40+
optional bool goproto_enum_stringer = 62021;
41+
optional bool enum_stringer = 62022;
42+
optional string enum_customname = 62023;
43+
optional bool enumdecl = 62024;
44+
}
45+
46+
extend google.protobuf.EnumValueOptions {
47+
optional string enumvalue_customname = 66001;
48+
}
49+
50+
extend google.protobuf.FileOptions {
51+
optional bool goproto_getters_all = 63001;
52+
optional bool goproto_enum_prefix_all = 63002;
53+
optional bool goproto_stringer_all = 63003;
54+
optional bool verbose_equal_all = 63004;
55+
optional bool face_all = 63005;
56+
optional bool gostring_all = 63006;
57+
optional bool populate_all = 63007;
58+
optional bool stringer_all = 63008;
59+
optional bool onlyone_all = 63009;
60+
61+
optional bool equal_all = 63013;
62+
optional bool description_all = 63014;
63+
optional bool testgen_all = 63015;
64+
optional bool benchgen_all = 63016;
65+
optional bool marshaler_all = 63017;
66+
optional bool unmarshaler_all = 63018;
67+
optional bool stable_marshaler_all = 63019;
68+
69+
optional bool sizer_all = 63020;
70+
71+
optional bool goproto_enum_stringer_all = 63021;
72+
optional bool enum_stringer_all = 63022;
73+
74+
optional bool unsafe_marshaler_all = 63023;
75+
optional bool unsafe_unmarshaler_all = 63024;
76+
77+
optional bool goproto_extensions_map_all = 63025;
78+
optional bool goproto_unrecognized_all = 63026;
79+
optional bool gogoproto_import = 63027;
80+
optional bool protosizer_all = 63028;
81+
optional bool compare_all = 63029;
82+
optional bool typedecl_all = 63030;
83+
optional bool enumdecl_all = 63031;
84+
85+
optional bool goproto_registration = 63032;
86+
optional bool messagename_all = 63033;
87+
88+
optional bool goproto_sizecache_all = 63034;
89+
optional bool goproto_unkeyed_all = 63035;
90+
}
91+
92+
extend google.protobuf.MessageOptions {
93+
optional bool goproto_getters = 64001;
94+
optional bool goproto_stringer = 64003;
95+
optional bool verbose_equal = 64004;
96+
optional bool face = 64005;
97+
optional bool gostring = 64006;
98+
optional bool populate = 64007;
99+
optional bool stringer = 67008;
100+
optional bool onlyone = 64009;
101+
102+
optional bool equal = 64013;
103+
optional bool description = 64014;
104+
optional bool testgen = 64015;
105+
optional bool benchgen = 64016;
106+
optional bool marshaler = 64017;
107+
optional bool unmarshaler = 64018;
108+
optional bool stable_marshaler = 64019;
109+
110+
optional bool sizer = 64020;
111+
112+
optional bool unsafe_marshaler = 64023;
113+
optional bool unsafe_unmarshaler = 64024;
114+
115+
optional bool goproto_extensions_map = 64025;
116+
optional bool goproto_unrecognized = 64026;
117+
118+
optional bool protosizer = 64028;
119+
optional bool compare = 64029;
120+
121+
optional bool typedecl = 64030;
122+
123+
optional bool messagename = 64033;
124+
125+
optional bool goproto_sizecache = 64034;
126+
optional bool goproto_unkeyed = 64035;
127+
}
128+
129+
extend google.protobuf.FieldOptions {
130+
optional bool nullable = 65001;
131+
optional bool embed = 65002;
132+
optional string customtype = 65003;
133+
optional string customname = 65004;
134+
optional string jsontag = 65005;
135+
optional string moretags = 65006;
136+
optional string casttype = 65007;
137+
optional string castkey = 65008;
138+
optional string castvalue = 65009;
139+
140+
optional bool stdtime = 65010;
141+
optional bool stdduration = 65011;
142+
optional bool wktpointer = 65012;
143+
144+
}
145+

0 commit comments

Comments
 (0)