From f76ba78a7d281ad42ef4dc2f42d19c086ca3f80d Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sat, 30 Dec 2023 17:04:27 +0300 Subject: [PATCH] chore(dev): add demo client metric Ref: #281 --- cmd/oteldemo/client.go | 6 + dev/local/ch/otelcol.yml | 4 + dev/local/grafana/dashboards/demo.json | 274 +++++++++++++++++++++++++ dev/local/grafana/datasources.yml | 2 +- 4 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 dev/local/grafana/dashboards/demo.json diff --git a/cmd/oteldemo/client.go b/cmd/oteldemo/client.go index e5c9d327..3fb95537 100644 --- a/cmd/oteldemo/client.go +++ b/cmd/oteldemo/client.go @@ -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() diff --git a/dev/local/ch/otelcol.yml b/dev/local/ch/otelcol.yml index 8cc02cb5..2b0de274 100644 --- a/dev/local/ch/otelcol.yml +++ b/dev/local/ch/otelcol.yml @@ -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: diff --git a/dev/local/grafana/dashboards/demo.json b/dev/local/grafana/dashboards/demo.json new file mode 100644 index 00000000..38739b3b --- /dev/null +++ b/dev/local/grafana/dashboards/demo.json @@ -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": "" +} diff --git a/dev/local/grafana/datasources.yml b/dev/local/grafana/datasources.yml index 204a4766..fcc67f89 100644 --- a/dev/local/grafana/datasources.yml +++ b/dev/local/grafana/datasources.yml @@ -29,6 +29,7 @@ datasources: orgId: 1 url: http://oteldb:9090 uid: promoteldb + isDefault: true - name: Prometheus type: prometheus @@ -36,7 +37,6 @@ datasources: orgId: 1 url: http://prometheus:9090 uid: prometheus - isDefault: true - name: ClickHouse type: grafana-clickhouse-datasource