Skip to content

Commit f76ba78

Browse files
committed
chore(dev): add demo client metric
Ref: #281
1 parent cadfa57 commit f76ba78

File tree

4 files changed

+285
-1
lines changed

4 files changed

+285
-1
lines changed

Diff for: cmd/oteldemo/client.go

+6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ func client(ctx context.Context, lg *zap.Logger, m *app.Metrics) error {
2424
otelhttp.WithTracerProvider(m.TracerProvider()),
2525
otelhttp.WithMeterProvider(m.MeterProvider()),
2626
)
27+
meter := m.MeterProvider().Meter("oteldemo.client")
28+
sentRequestsCount, err := meter.Int64Counter("oteldemo.client.sent_requests")
29+
if err != nil {
30+
return errors.Wrap(err, "create counter")
31+
}
2732
httpClient := &http.Client{
2833
Transport: httpTransport,
2934
Timeout: time.Second * 10,
3035
}
3136
tracer := m.TracerProvider().Tracer("client")
3237
sendRequest := func(ctx context.Context) {
38+
sentRequestsCount.Add(ctx, 1)
3339
ctx, cancel := context.WithTimeout(ctx, time.Second*2)
3440
defer cancel()
3541

Diff for: dev/local/ch/otelcol.yml

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ receivers:
2323
scrape_interval: 5s
2424
static_configs:
2525
- targets: [prometheus:9090]
26+
- job_name: grafana
27+
scrape_interval: 5s
28+
static_configs:
29+
- targets: [grafana:3000]
2630
- job_name: clickhouse
2731
scrape_interval: 5s
2832
static_configs:

Diff for: dev/local/grafana/dashboards/demo.json

+274
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
{
2+
"annotations": {
3+
"list": [
4+
{
5+
"builtIn": 1,
6+
"datasource": {
7+
"type": "grafana",
8+
"uid": "-- Grafana --"
9+
},
10+
"enable": true,
11+
"hide": true,
12+
"iconColor": "rgba(0, 211, 255, 1)",
13+
"name": "Annotations & Alerts",
14+
"type": "dashboard"
15+
}
16+
]
17+
},
18+
"editable": true,
19+
"fiscalYearStartMonth": 0,
20+
"graphTooltip": 0,
21+
"links": [],
22+
"liveNow": false,
23+
"panels": [
24+
{
25+
"datasource": {
26+
"type": "loki",
27+
"uid": "loki-oteldb"
28+
},
29+
"gridPos": {
30+
"h": 11,
31+
"w": 24,
32+
"x": 0,
33+
"y": 0
34+
},
35+
"id": 2,
36+
"options": {
37+
"dedupStrategy": "none",
38+
"enableLogDetails": true,
39+
"prettifyLogMessage": false,
40+
"showCommonLabels": false,
41+
"showLabels": false,
42+
"showTime": false,
43+
"sortOrder": "Descending",
44+
"wrapLogMessage": false
45+
},
46+
"targets": [
47+
{
48+
"datasource": {
49+
"type": "loki",
50+
"uid": "loki-oteldb"
51+
},
52+
"editorMode": "builder",
53+
"expr": "{service_name=\"client\"} |= ``",
54+
"queryType": "range",
55+
"refId": "A"
56+
}
57+
],
58+
"title": "client",
59+
"type": "logs"
60+
},
61+
{
62+
"datasource": {
63+
"type": "loki",
64+
"uid": "loki-oteldb"
65+
},
66+
"gridPos": {
67+
"h": 11,
68+
"w": 24,
69+
"x": 0,
70+
"y": 11
71+
},
72+
"id": 3,
73+
"options": {
74+
"dedupStrategy": "none",
75+
"enableLogDetails": true,
76+
"prettifyLogMessage": false,
77+
"showCommonLabels": false,
78+
"showLabels": false,
79+
"showTime": false,
80+
"sortOrder": "Descending",
81+
"wrapLogMessage": false
82+
},
83+
"targets": [
84+
{
85+
"datasource": {
86+
"type": "loki",
87+
"uid": "loki-oteldb"
88+
},
89+
"editorMode": "builder",
90+
"expr": "{service_name=\"server\"} |= ``",
91+
"queryType": "range",
92+
"refId": "A"
93+
}
94+
],
95+
"title": "server",
96+
"type": "logs"
97+
},
98+
{
99+
"datasource": {
100+
"type": "prometheus",
101+
"uid": "promoteldb"
102+
},
103+
"fieldConfig": {
104+
"defaults": {
105+
"color": {
106+
"mode": "palette-classic"
107+
},
108+
"custom": {
109+
"axisCenteredZero": false,
110+
"axisColorMode": "text",
111+
"axisLabel": "",
112+
"axisPlacement": "auto",
113+
"barAlignment": 0,
114+
"drawStyle": "line",
115+
"fillOpacity": 0,
116+
"gradientMode": "none",
117+
"hideFrom": {
118+
"legend": false,
119+
"tooltip": false,
120+
"viz": false
121+
},
122+
"lineInterpolation": "linear",
123+
"lineWidth": 1,
124+
"pointSize": 5,
125+
"scaleDistribution": {
126+
"type": "linear"
127+
},
128+
"showPoints": "auto",
129+
"spanNulls": false,
130+
"stacking": {
131+
"group": "A",
132+
"mode": "none"
133+
},
134+
"thresholdsStyle": {
135+
"mode": "off"
136+
}
137+
},
138+
"mappings": [],
139+
"thresholds": {
140+
"mode": "absolute",
141+
"steps": [
142+
{
143+
"color": "green",
144+
"value": null
145+
},
146+
{
147+
"color": "red",
148+
"value": 80
149+
}
150+
]
151+
}
152+
},
153+
"overrides": []
154+
},
155+
"gridPos": {
156+
"h": 10,
157+
"w": 18,
158+
"x": 0,
159+
"y": 22
160+
},
161+
"id": 1,
162+
"options": {
163+
"legend": {
164+
"calcs": [],
165+
"displayMode": "list",
166+
"placement": "bottom",
167+
"showLegend": true
168+
},
169+
"tooltip": {
170+
"mode": "single",
171+
"sort": "none"
172+
}
173+
},
174+
"targets": [
175+
{
176+
"datasource": {
177+
"type": "prometheus",
178+
"uid": "promoteldb"
179+
},
180+
"editorMode": "code",
181+
"exemplar": true,
182+
"expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[$__rate_interval])) by (le))",
183+
"instant": false,
184+
"range": true,
185+
"refId": "A"
186+
}
187+
],
188+
"title": "Histogram",
189+
"type": "timeseries"
190+
},
191+
{
192+
"datasource": {
193+
"type": "prometheus",
194+
"uid": "promoteldb"
195+
},
196+
"fieldConfig": {
197+
"defaults": {
198+
"color": {
199+
"mode": "thresholds"
200+
},
201+
"mappings": [],
202+
"thresholds": {
203+
"mode": "absolute",
204+
"steps": [
205+
{
206+
"color": "green",
207+
"value": null
208+
},
209+
{
210+
"color": "red",
211+
"value": 80
212+
}
213+
]
214+
}
215+
},
216+
"overrides": []
217+
},
218+
"gridPos": {
219+
"h": 10,
220+
"w": 6,
221+
"x": 18,
222+
"y": 22
223+
},
224+
"id": 4,
225+
"options": {
226+
"colorMode": "value",
227+
"graphMode": "none",
228+
"justifyMode": "auto",
229+
"orientation": "auto",
230+
"reduceOptions": {
231+
"calcs": [
232+
"lastNotNull"
233+
],
234+
"fields": "",
235+
"values": false
236+
},
237+
"textMode": "auto"
238+
},
239+
"pluginVersion": "10.0.0",
240+
"targets": [
241+
{
242+
"datasource": {
243+
"type": "prometheus",
244+
"uid": "promoteldb"
245+
},
246+
"editorMode": "code",
247+
"expr": "oteldemo_client_sent_requests",
248+
"instant": false,
249+
"range": true,
250+
"refId": "A"
251+
}
252+
],
253+
"title": "Requests made",
254+
"type": "stat"
255+
}
256+
],
257+
"refresh": "",
258+
"schemaVersion": 38,
259+
"style": "dark",
260+
"tags": [],
261+
"templating": {
262+
"list": []
263+
},
264+
"time": {
265+
"from": "now-1m",
266+
"to": "now"
267+
},
268+
"timepicker": {},
269+
"timezone": "",
270+
"title": "Demo",
271+
"uid": "demo",
272+
"version": 1,
273+
"weekStart": ""
274+
}

Diff for: dev/local/grafana/datasources.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ datasources:
2929
orgId: 1
3030
url: http://oteldb:9090
3131
uid: promoteldb
32+
isDefault: true
3233

3334
- name: Prometheus
3435
type: prometheus
3536
access: proxy
3637
orgId: 1
3738
url: http://prometheus:9090
3839
uid: prometheus
39-
isDefault: true
4040

4141
- name: ClickHouse
4242
type: grafana-clickhouse-datasource

0 commit comments

Comments
 (0)