mirror of
https://github.com/hanzoai/metrics.git
synced 2026-10-30 20:03:39 +00:00
### Describe Your Changes This commit improves how vmagent selects the remote write protocol. Previously, vmagent [performed a handshake probe](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/2ee6d8ff92755d9761d502624339655a961dc5fe/lib/protoparser/protoparserutil/vmproto_handshake.go#L11) at [startup](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/2ee6d8ff92755d9761d502624339655a961dc5fe/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. ### Checklist The following checks are **mandatory**: - [x] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/).
21 lines
580 B
Go
21 lines
580 B
Go
package protoparserutil
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
// HandleVMProtoServerHandshake returns true if r contains handshake request for determining the supported protocol version.
|
|
//
|
|
// Deprecated: New vmagent versions skip the handshake and use the VictoriaMetrics
|
|
// remote write protocol by default.
|
|
// See: https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8462
|
|
func HandleVMProtoServerHandshake(w http.ResponseWriter, r *http.Request) bool {
|
|
q := r.URL.Query()
|
|
if q.Get("get_vm_proto_version") != "" {
|
|
_, _ = io.WriteString(w, "1")
|
|
return true
|
|
}
|
|
return false
|
|
}
|