Skip to content

Commit

Permalink
chore(dev): add demo client metric
Browse files Browse the repository at this point in the history
Ref: #281
  • Loading branch information
ernado committed Dec 30, 2023
1 parent cadfa57 commit f76ba78
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/oteldemo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ func client(ctx context.Context, lg *zap.Logger, m *app.Metrics) error {
otelhttp.WithTracerProvider(m.TracerProvider()),
otelhttp.WithMeterProvider(m.MeterProvider()),
)
meter := m.MeterProvider().Meter("oteldemo.client")
sentRequestsCount, err := meter.Int64Counter("oteldemo.client.sent_requests")
if err != nil {
return errors.Wrap(err, "create counter")
}
httpClient := &http.Client{
Transport: httpTransport,
Timeout: time.Second * 10,
}
tracer := m.TracerProvider().Tracer("client")
sendRequest := func(ctx context.Context) {
sentRequestsCount.Add(ctx, 1)
ctx, cancel := context.WithTimeout(ctx, time.Second*2)
defer cancel()

Expand Down
4 changes: 4 additions & 0 deletions dev/local/ch/otelcol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ receivers:
scrape_interval: 5s
static_configs:
- targets: [prometheus:9090]
- job_name: grafana
scrape_interval: 5s
static_configs:
- targets: [grafana:3000]
- job_name: clickhouse
scrape_interval: 5s
static_configs:
Expand Down
274 changes: 274 additions & 0 deletions dev/local/grafana/dashboards/demo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "loki",
"uid": "loki-oteldb"
},
"gridPos": {
"h": 11,
"w": 24,
"x": 0,
"y": 0
},
"id": 2,
"options": {
"dedupStrategy": "none",
"enableLogDetails": true,
"prettifyLogMessage": false,
"showCommonLabels": false,
"showLabels": false,
"showTime": false,
"sortOrder": "Descending",
"wrapLogMessage": false
},
"targets": [
{
"datasource": {
"type": "loki",
"uid": "loki-oteldb"
},
"editorMode": "builder",
"expr": "{service_name=\"client\"} |= ``",
"queryType": "range",
"refId": "A"
}
],
"title": "client",
"type": "logs"
},
{
"datasource": {
"type": "loki",
"uid": "loki-oteldb"
},
"gridPos": {
"h": 11,
"w": 24,
"x": 0,
"y": 11
},
"id": 3,
"options": {
"dedupStrategy": "none",
"enableLogDetails": true,
"prettifyLogMessage": false,
"showCommonLabels": false,
"showLabels": false,
"showTime": false,
"sortOrder": "Descending",
"wrapLogMessage": false
},
"targets": [
{
"datasource": {
"type": "loki",
"uid": "loki-oteldb"
},
"editorMode": "builder",
"expr": "{service_name=\"server\"} |= ``",
"queryType": "range",
"refId": "A"
}
],
"title": "server",
"type": "logs"
},
{
"datasource": {
"type": "prometheus",
"uid": "promoteldb"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 18,
"x": 0,
"y": 22
},
"id": 1,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "promoteldb"
},
"editorMode": "code",
"exemplar": true,
"expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[$__rate_interval])) by (le))",
"instant": false,
"range": true,
"refId": "A"
}
],
"title": "Histogram",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "promoteldb"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 6,
"x": 18,
"y": 22
},
"id": 4,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "promoteldb"
},
"editorMode": "code",
"expr": "oteldemo_client_sent_requests",
"instant": false,
"range": true,
"refId": "A"
}
],
"title": "Requests made",
"type": "stat"
}
],
"refresh": "",
"schemaVersion": 38,
"style": "dark",
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-1m",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Demo",
"uid": "demo",
"version": 1,
"weekStart": ""
}
2 changes: 1 addition & 1 deletion dev/local/grafana/datasources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ datasources:
orgId: 1
url: http://oteldb:9090
uid: promoteldb
isDefault: true

- name: Prometheus
type: prometheus
access: proxy
orgId: 1
url: http://prometheus:9090
uid: prometheus
isDefault: true

- name: ClickHouse
type: grafana-clickhouse-datasource
Expand Down

0 comments on commit f76ba78

Please sign in to comment.