diff --git a/app/vmagent/main.go b/app/vmagent/main.go index 302fbc831..22a092ce3 100644 --- a/app/vmagent/main.go +++ b/app/vmagent/main.go @@ -318,6 +318,10 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool { influxQueryRequests.Inc() influxutils.WriteDatabaseNames(w) return true + case "/influx/health": + influxHealthRequests.Inc() + influxutils.WriteHealthCheckResponse(w) + return true case "/opentelemetry/api/v1/push", "/opentelemetry/v1/metrics": opentelemetryPushRequests.Inc() if err := opentelemetry.InsertHandler(nil, r); err != nil { @@ -564,6 +568,10 @@ func processMultitenantRequest(w http.ResponseWriter, r *http.Request, path stri influxQueryRequests.Inc() influxutils.WriteDatabaseNames(w) return true + case "influx/health": + influxHealthRequests.Inc() + influxutils.WriteHealthCheckResponse(w) + return true case "opentelemetry/api/v1/push", "opentelemetry/v1/metrics": opentelemetryPushRequests.Inc() if err := opentelemetry.InsertHandler(at, r); err != nil { @@ -674,7 +682,8 @@ var ( influxWriteRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/influx/write", protocol="influx"}`) influxWriteErrors = metrics.NewCounter(`vmagent_http_request_errors_total{path="/influx/write", protocol="influx"}`) - influxQueryRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/influx/query", protocol="influx"}`) + influxQueryRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/influx/query", protocol="influx"}`) + influxHealthRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/influx/health", protocol="influx"}`) datadogv1WriteRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/datadog/api/v1/series", protocol="datadog"}`) datadogv1WriteErrors = metrics.NewCounter(`vmagent_http_request_errors_total{path="/datadog/api/v1/series", protocol="datadog"}`) diff --git a/app/vminsert/main.go b/app/vminsert/main.go index f3bed07be..9b02dc18d 100644 --- a/app/vminsert/main.go +++ b/app/vminsert/main.go @@ -218,6 +218,10 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool { addInfluxResponseHeaders(w) influxutils.WriteDatabaseNames(w) return true + case "/influx/health": + influxHealthRequests.Inc() + influxutils.WriteHealthCheckResponse(w) + return true case "/opentelemetry/api/v1/push", "/opentelemetry/v1/metrics": opentelemetryPushRequests.Inc() if err := opentelemetry.InsertHandler(r); err != nil { @@ -397,7 +401,8 @@ var ( influxWriteRequests = metrics.NewCounter(`vm_http_requests_total{path="/influx/write", protocol="influx"}`) influxWriteErrors = metrics.NewCounter(`vm_http_request_errors_total{path="/influx/write", protocol="influx"}`) - influxQueryRequests = metrics.NewCounter(`vm_http_requests_total{path="/influx/query", protocol="influx"}`) + influxQueryRequests = metrics.NewCounter(`vm_http_requests_total{path="/influx/query", protocol="influx"}`) + influxHealthRequests = metrics.NewCounter(`vm_http_requests_total{path="/influx/health", protocol="influx"}`) datadogv1WriteRequests = metrics.NewCounter(`vm_http_requests_total{path="/datadog/api/v1/series", protocol="datadog"}`) datadogv1WriteErrors = metrics.NewCounter(`vm_http_request_errors_total{path="/datadog/api/v1/series", protocol="datadog"}`) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 7afa1c3ee..f6cb6ab75 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -30,6 +30,7 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/). ## tip +* FEATURE: add `/influx/health` health-check handler for Influx endpoints. This is needed as some clients use the health endpoint to determine if the server is healthy and ready for data ingestion. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6653) for the details. * FEATURE: [vmctl](https://docs.victoriametrics.com/vmctl/): add `--vm-backoff-retries`, `--vm-backoff-factor`, `--vm-backoff-min-duration` and `--vm-native-backoff-retries`, `--vm-native-backoff-factor`, `--vm-native-backoff-min-duration` command-line flags. These flags allow to change backoff policy config for import requests to VictoriaMetrics. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6622). ## [v1.102.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.102.1) diff --git a/lib/influxutils/influxutils.go b/lib/influxutils/influxutils.go index dc89e6560..d89663871 100644 --- a/lib/influxutils/influxutils.go +++ b/lib/influxutils/influxutils.go @@ -27,3 +27,14 @@ func WriteDatabaseNames(w http.ResponseWriter) { } fmt.Fprintf(w, `{"results":[{"statement_id":0,"series":[{"name":"databases","columns":["name"],"values":[%s]}]}]}`, strings.Join(dbs, ",")) } + +// WriteHealthCheckResponse writes response for influx ping to w. +func WriteHealthCheckResponse(w http.ResponseWriter) { + // Emulate fake response for influx ping. + // This is needed for some clients to detect whether InfluxDB is available. + // See: + // - https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6653 + // - https://docs.influxdata.com/influxdb/v2/api/#operation/GetHealth + + fmt.Fprintf(w, `{"name":"influxdb", "message":"ready for queries and writes", "status":"pass", "checks":[]}`) +}