Skip to content

Commit 4e99b72

Browse files
author
Azfaar Qureshi
committed
adding integration tests for prom RW exporter
adding async conversions fixing tox.ini snappy installing snappy c library installing c snappy library before calling tests
1 parent ac5f46f commit 4e99b72

File tree

4 files changed

+190
-3
lines changed

4 files changed

+190
-3
lines changed

tests/opentelemetry-docker-tests/tests/docker-compose.yml

+12
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,15 @@ services:
3939
- "16686:16686"
4040
- "14268:14268"
4141
- "9411:9411"
42+
cortex:
43+
image: quay.io/cortexproject/cortex:v1.5.0
44+
command:
45+
- -config.file=./config/cortex-config.yml
46+
volumes:
47+
- ./prometheus-remote-write-cortex/cortex-config.yml:/config/cortex-config.yml:ro
48+
ports:
49+
- 9009:9009
50+
grafana:
51+
image: grafana/grafana:latest
52+
ports:
53+
- 3000:3000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# This Cortex Config is copied from the Cortex Project documentation
2+
# Source: https://github.com/cortexproject/cortex/blob/master/docs/configuration/single-process-config.yaml
3+
4+
# Configuration for running Cortex in single-process mode.
5+
# This configuration should not be used in production.
6+
# It is only for getting started and development.
7+
8+
# Disable the requirement that every request to Cortex has a
9+
# X-Scope-OrgID header. `fake` will be substituted in instead.
10+
auth_enabled: false
11+
12+
server:
13+
http_listen_port: 9009
14+
15+
# Configure the server to allow messages up to 100MB.
16+
grpc_server_max_recv_msg_size: 104857600
17+
grpc_server_max_send_msg_size: 104857600
18+
grpc_server_max_concurrent_streams: 1000
19+
20+
distributor:
21+
shard_by_all_labels: true
22+
pool:
23+
health_check_ingesters: true
24+
25+
ingester_client:
26+
grpc_client_config:
27+
# Configure the client to allow messages up to 100MB.
28+
max_recv_msg_size: 104857600
29+
max_send_msg_size: 104857600
30+
use_gzip_compression: true
31+
32+
ingester:
33+
# We want our ingesters to flush chunks at the same time to optimise
34+
# deduplication opportunities.
35+
spread_flushes: true
36+
chunk_age_jitter: 0
37+
38+
walconfig:
39+
wal_enabled: true
40+
recover_from_wal: true
41+
wal_dir: /tmp/cortex/wal
42+
43+
lifecycler:
44+
# The address to advertise for this ingester. Will be autodiscovered by
45+
# looking up address on eth0 or en0; can be specified if this fails.
46+
# address: 127.0.0.1
47+
48+
# We want to start immediately and flush on shutdown.
49+
join_after: 0
50+
min_ready_duration: 0s
51+
final_sleep: 0s
52+
num_tokens: 512
53+
tokens_file_path: /tmp/cortex/wal/tokens
54+
55+
# Use an in memory ring store, so we don't need to launch a Consul.
56+
ring:
57+
kvstore:
58+
store: inmemory
59+
replication_factor: 1
60+
61+
# Use local storage - BoltDB for the index, and the filesystem
62+
# for the chunks.
63+
schema:
64+
configs:
65+
- from: 2019-07-29
66+
store: boltdb
67+
object_store: filesystem
68+
schema: v10
69+
index:
70+
prefix: index_
71+
period: 1w
72+
73+
storage:
74+
boltdb:
75+
directory: /tmp/cortex/index
76+
77+
filesystem:
78+
directory: /tmp/cortex/chunks
79+
80+
delete_store:
81+
store: boltdb
82+
83+
purger:
84+
object_store_type: filesystem
85+
86+
frontend_worker:
87+
# Configure the frontend worker in the querier to match worker count
88+
# to max_concurrent on the queriers.
89+
match_max_concurrent: true
90+
91+
# Configure the ruler to scan the /tmp/cortex/rules directory for prometheus
92+
# rules: https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/#recording-rules
93+
ruler:
94+
enable_api: true
95+
enable_sharding: false
96+
storage:
97+
type: local
98+
local:
99+
directory: /tmp/cortex/rules
100+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from opentelemetry import metrics
2+
from opentelemetry.exporter.prometheus_remote_write import (
3+
PrometheusRemoteWriteMetricsExporter,
4+
)
5+
from opentelemetry.test.test_base import TestBase
6+
7+
8+
def observer_callback(observer):
9+
array = [1.0, 15.0, 25.0, 26.0]
10+
for (index, usage) in enumerate(array):
11+
labels = {"test_label": str(index)}
12+
observer.observe(usage, labels)
13+
14+
15+
class TestPrometheusRemoteWriteExporterCortex(TestBase):
16+
def setUp(self):
17+
super().setUp
18+
self.exporter = PrometheusRemoteWriteMetricsExporter(
19+
endpoint="http://localhost:9009/api/prom/push",
20+
headers={"X-Scope-Org-ID": "5"},
21+
)
22+
self.labels = {"environment": "testing"}
23+
self.meter = self.meter_provider.get_meter(__name__)
24+
metrics.get_meter_provider().start_pipeline(
25+
self.meter, self.exporter, 1,
26+
)
27+
28+
def test_export_counter(self):
29+
requests_counter = self.meter.create_counter(
30+
name="counter",
31+
description="test_export_counter",
32+
unit="1",
33+
value_type=int,
34+
)
35+
requests_counter.add(25, self.labels)
36+
37+
def test_export_valuerecorder(self):
38+
requests_size = self.meter.create_valuerecorder(
39+
name="valuerecorder",
40+
description="test_export_valuerecorder",
41+
unit="1",
42+
value_type=int,
43+
)
44+
requests_size.record(25, self.labels)
45+
46+
def test_export_updowncounter(self):
47+
requests_size = self.meter.create_updowncounter(
48+
name="updowncounter",
49+
description="test_export_updowncounter",
50+
unit="1",
51+
value_type=int,
52+
)
53+
requests_size.add(-25, self.labels)
54+
55+
def test_export_sumobserver(self):
56+
self.meter.register_sumobserver(
57+
callback=observer_callback,
58+
name="sumobserver",
59+
description="test_export_sumobserver",
60+
unit="1",
61+
value_type=float,
62+
)
63+
64+
def test_export_updownsumobserver(self):
65+
self.meter.register_updownsumobserver(
66+
callback=observer_callback,
67+
name="updownsumobserver",
68+
description="test_export_updownsumobserver",
69+
unit="1",
70+
value_type=float,
71+
)

tox.ini

+7-3
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ commands_pre =
198198
test: pip install {toxinidir}/opentelemetry-python-core/opentelemetry-api {toxinidir}/opentelemetry-python-core/opentelemetry-sdk {toxinidir}/opentelemetry-python-core/tests/util
199199

200200
test: pip install {toxinidir}/opentelemetry-python-core/opentelemetry-instrumentation
201-
201+
202202
celery: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-celery[test]
203203

204204
grpc: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-grpc[test]
@@ -308,7 +308,8 @@ deps =
308308
sqlalchemy ~= 1.3.16
309309
redis ~= 3.3.11
310310
celery ~= 4.0, != 4.4.4
311-
311+
protobuf>=3.13.0
312+
requests==2.25.0
312313
changedir =
313314
tests/opentelemetry-docker-tests/tests
314315

@@ -328,7 +329,10 @@ commands_pre =
328329
-e {toxinidir}/instrumentation/opentelemetry-instrumentation-aiopg \
329330
-e {toxinidir}/instrumentation/opentelemetry-instrumentation-redis \
330331
-e {toxinidir}/instrumentation/opentelemetry-instrumentation-system-metrics \
331-
-e {toxinidir}/opentelemetry-python-core/exporter/opentelemetry-exporter-opencensus
332+
-e {toxinidir}/opentelemetry-python-core/exporter/opentelemetry-exporter-opencensus \
333+
-e {toxinidir}/exporter/opentelemetry-exporter-prometheus-remote-write
334+
sudo apt-get install libsnappy-dev
335+
pip install python-snappy
332336
docker-compose up -d
333337
python check_availability.py
334338
commands =

0 commit comments

Comments
 (0)