VictoriaMetrics/app/vmagent
Max Kotliar 01fff44a8d
vmagent/client: Use VictoriaMetrics remote write protocol by default, downgrade to Prometheus if needed ()
This commit improves how vmagent selects the remote write protocol.
Previously, vmagent [performed a handshake
probe](0ff1a3b154/lib/protoparser/protoparserutil/vmproto_handshake.go (L11))
at
[startup](0ff1a3b154/app/vmagent/remotewrite/client.go (L173)):

- If the probe succeeded, it used the VictoriaMetrics (VM) protocol.

- If the probe failed, it downgraded to the Prometheus protocol.

- No protocol changes occurred after the initial probe at runtime.

However, this approach had limitations:

- If vmstorage was unavailable during vmagent startup, vmagent would
immediately downgrade to the Prometheus protocol, leading to higher
network usage unitl vmagent restarted. This case has been reported in
https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7615.

- If the remote write server was updated or downgraded (e.g., during a
fallback or migration), vmagent would not detect the protocol change. It
would continue retrying failed requests and eventually drop them.
Require a restart of vmagent to pick up the new protocol.

This commit introduces a more adaptive mechanism.
vmagent always starts with the VM protocol and downgrades to the
Prometheus protocol only if an unsupported media type or bad request
response is received.
When this happens, the protocol is downgraded for all future requests.
In-flight requests are re-packed from Zstd to Snappy and retried
immediately.
Snappy-encoded requests are dropped if an unsupported media type or bad
request is received (no retrying).

Additionally, the in-memory and persisted queues could mix snappy and
zstd encoded blocks. The proper encoding is decided before sending by
encoding.IsZstd function.

TODO:
* [x] Add tests
* [x] Update documentation
* [x] Changelog
* [x] Research on
[content-type](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8462#issuecomment-2786918054),
[accept-encoding](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8462#issuecomment-2786923382)

Fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7615#top
issue.

The following checks are **mandatory**:

- [x] My change adheres [VictoriaMetrics contributing
guidelines](https://docs.victoriametrics.com/contributing/).
2025-04-14 11:13:22 +02:00
..
common app/vmagent/common: use plain sync.Pool instead of a mix of sync.Pool with channel-based pool for PushCtx 2024-04-20 21:31:14 +02:00
csvimport lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:40:06 +01:00
datadogsketches lib/protoparser: rename lib/protoparser/datadogutils to lib/protoparser/datadogutil for the sake of consistency for *util package naming 2025-03-26 17:13:36 +01:00
datadogv1 lib/protoparser: rename lib/protoparser/datadogutils to lib/protoparser/datadogutil for the sake of consistency for *util package naming 2025-03-26 17:13:36 +01:00
datadogv2 lib/protoparser: rename lib/protoparser/datadogutils to lib/protoparser/datadogutil for the sake of consistency for *util package naming 2025-03-26 17:13:36 +01:00
deployment all: suppress InvalidDefaultArgInFrom warning emitted by docker build when building Docker packages via make package-* command 2024-09-03 14:05:43 +02:00
graphite app/vlinsert: follow-up for 37ed1842ab 2025-03-15 00:11:58 +01:00
influx lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:40:06 +01:00
multiarch app/*/multiarch: return back empty value for TARGETARCH 2024-09-06 18:15:22 +02:00
native lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:40:06 +01:00
newrelic lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:40:06 +01:00
opentelemetry lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:40:06 +01:00
opentsdb app/vmagent: follow-up for 090cb2c9de 2023-11-25 12:13:39 +02:00
opentsdbhttp lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:40:06 +01:00
prometheusimport lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:40:06 +01:00
promremotewrite lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:40:06 +01:00
remotewrite vmagent/client: Use VictoriaMetrics remote write protocol by default, downgrade to Prometheus if needed () 2025-04-14 11:13:22 +02:00
static/css all: follow-up after 8edb390e21 2022-06-07 01:05:53 +03:00
vmimport lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:40:06 +01:00
main.go app/vmagent: increase the default GOGC from 30 to 50 2025-04-01 21:08:55 +02:00
Makefile Add build support for loong64 () 2024-05-10 14:32:05 +02:00
README.md all: replace the outdated url https://docs.victoriametrics.com/vmagent.html with the new one - https://docs.victoriametrics.com/vmagent/ 2024-04-18 01:32:57 +02:00
vmagent.png app/vmagent: update docs 2020-02-25 00:09:53 +02:00

See vmagent docs here.

vmagent docs can be edited at docs/vmagent.md.