From 476286385f7222f14ba240fbaa3e3bc91eb688d0 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Sat, 12 Aug 2023 14:05:16 +0200 Subject: [PATCH] opentelemetry: return human readable error for json encoding. (#4822) Opentelemetry parser supports only protobuf atm. Co-authored-by: Aliaksandr Valialkin --- app/vmagent/opentelemetry/request_handler.go | 4 ++++ app/vminsert/opentelemetry/request_handler.go | 4 ++++ docs/CHANGELOG.md | 1 + 3 files changed, 9 insertions(+) diff --git a/app/vmagent/opentelemetry/request_handler.go b/app/vmagent/opentelemetry/request_handler.go index 047978149..0ad6a75fd 100644 --- a/app/vmagent/opentelemetry/request_handler.go +++ b/app/vmagent/opentelemetry/request_handler.go @@ -1,6 +1,7 @@ package opentelemetry import ( + "fmt" "net/http" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmagent/common" @@ -26,6 +27,9 @@ func InsertHandler(at *auth.Token, req *http.Request) error { return err } isGzipped := req.Header.Get("Content-Encoding") == "gzip" + if req.Header.Get("Content-Type") == "application/json" { + return fmt.Errorf("json encoding isn't supported for opentelemetry format. Use protobuf encoding") + } return stream.ParseStream(req.Body, isGzipped, func(tss []prompbmarshal.TimeSeries) error { return insertRows(at, tss, extraLabels) }) diff --git a/app/vminsert/opentelemetry/request_handler.go b/app/vminsert/opentelemetry/request_handler.go index c3ae5d4bc..08fbc295f 100644 --- a/app/vminsert/opentelemetry/request_handler.go +++ b/app/vminsert/opentelemetry/request_handler.go @@ -1,6 +1,7 @@ package opentelemetry import ( + "fmt" "net/http" "github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/netstorage" @@ -27,6 +28,9 @@ func InsertHandler(at *auth.Token, req *http.Request) error { return err } isGzipped := req.Header.Get("Content-Encoding") == "gzip" + if req.Header.Get("Content-Type") == "application/json" { + return fmt.Errorf("json encoding isn't supported for opentelemetry format. Use protobuf encoding") + } return stream.ParseStream(req.Body, isGzipped, func(tss []prompbmarshal.TimeSeries) error { return insertRows(at, tss, extraLabels) }) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e1376a53a..4f2024c48 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -42,6 +42,7 @@ The following `tip` changes can be tested by building VictoriaMetrics components * FEATURE: [Official Grafana dashboards for VictoriaMetrics](https://grafana.com/orgs/victoriametrics): correctly calculate `Bytes per point` value for single-server and cluster VM dashboards. Before, the calculation mistakenly accounted for the number of entries in indexdb in denominator, which could have shown lower values than expected. * FEATURE: [Alerting rules for VictoriaMetrics](https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/deployment/docker#alerts): `ConcurrentFlushesHitTheLimit` alerting rule was moved from [single-server](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/alerts.yml) and [cluster](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/alerts-cluster.yml) alerts to the [list of "health" alerts](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/alerts-health.yml) as it could be related to many VictoriaMetrics components. +* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): return human readable error if opentelemetry has json encoding. Follow-up after [PR](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/2570). * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly validate scheme for `proxy_url` field at the scrape config. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4811) for details. * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly apply `if` filters during [relabeling](https://docs.victoriametrics.com/vmagent.html#relabeling-enhancements). Previously the `if` filter could improperly work. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4806) and [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4816). * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): use local scrape timestamps for the scraped metrics unless `honor_timestamps: true` option is explicitly set at [scrape_config](https://docs.victoriametrics.com/sd_configs.html#scrape_configs). This fixes gaps for metrics collected from [cadvisor](https://github.com/google/cadvisor) or similar exporters, which export metrics with invalid timestamps. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4697) and [this comment](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4697#issuecomment-1654614799) for details. The issue has been introduced in [v1.68.0](#v1680).