Skip to content

Commit b3e521c

Browse files
Cortex example project (#238)
* Cortex: Add example * Add license and source to cortexConfig * Run make precommit * Switch to infinite loop
1 parent 9cc7199 commit b3e521c

File tree

7 files changed

+659
-0
lines changed

7 files changed

+659
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Cortex Exporter Example
2+
3+
This example exports several metrics to a [Cortex](https://cortexmetrics.io/) instance and displays
4+
them in [Grafana](https://grafana.com/).
5+
6+
## Requirements
7+
8+
- [Docker Compose](https://docs.docker.com/compose/) installed
9+
10+
## Instructions
11+
12+
1. Run the docker container with the following command
13+
14+
```bash
15+
docker-compose up -d
16+
```
17+
18+
2. Log in to the Grafana instance running at [http://localhost:3000](http://localhost:3000). The
19+
login credentials are admin/admin.
20+
21+
3. Add Cortex as a data source by creating a new Prometheus data source using
22+
[http://localhost:9009/api/prom/](http://localhost:9009/api/prom/) as the endpoint.
23+
24+
4. View collected metrics in Grafana.
25+
26+
5. Shut down the services when you're finished with the example
27+
28+
```bash
29+
docker-compose down
30+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
url: http://host.docker.internal:9009/api/prom/push
16+
remote_timeout: 30s
17+
push_interval: 2s
18+
name: Test
19+
headers:
20+
X-Scope-OrgID: 5
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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: "3"
16+
17+
services:
18+
app:
19+
image: golang:1.14-alpine
20+
volumes:
21+
- .:/app
22+
working_dir: /app
23+
command: go run main.go
24+
cortex:
25+
image: quay.io/cortexproject/cortex:v1.3.0-rc.1
26+
command:
27+
- -config.file=./config/cortexConfig.yml
28+
volumes:
29+
- ./cortexConfig.yml:/config/cortexConfig.yml:ro
30+
ports:
31+
- 9009:9009
32+
grafana:
33+
image: grafana/grafana:latest
34+
ports:
35+
- 3000:3000
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module go.opentelemetry.io/contrib/exporters/metric/cortex/example
2+
3+
go 1.14
4+
5+
require (
6+
go.opentelemetry.io/contrib/exporters/metric/cortex v0.10.1
7+
go.opentelemetry.io/contrib/exporters/metric/cortex/utils v0.10.1
8+
go.opentelemetry.io/otel v0.10.0
9+
go.opentelemetry.io/otel/sdk v0.10.0
10+
gopkg.in/yaml.v2 v2.2.5 // indirect
11+
)

0 commit comments

Comments
 (0)