mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-22 08:26:19 +01:00
0b1def6e24
### Describe Your Changes
This is useful for clients which validate InfluxDB is available before
data ingestion can be started.
See: https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6653
### Checklist
The following checks are **mandatory**:
- [x] My change adheres [VictoriaMetrics contributing
guidelines](https://docs.victoriametrics.com/contributing/).
---------
Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>
Signed-off-by: hagen1778 <roman@victoriametrics.com>
Co-authored-by: hagen1778 <roman@victoriametrics.com>
(cherry picked from commit 9877a5e7d5
)
Signed-off-by: hagen1778 <roman@victoriametrics.com>
41 lines
1.6 KiB
Go
41 lines
1.6 KiB
Go
package influxutils
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
|
|
)
|
|
|
|
var influxDatabaseNames = flagutil.NewArrayString("influx.databaseNames", "Comma-separated list of database names to return from /query and /influx/query API. "+
|
|
"This can be needed for accepting data from Telegraf plugins such as https://github.com/fangli/fluent-plugin-influxdb")
|
|
|
|
// WriteDatabaseNames writes influxDatabaseNames to w.
|
|
func WriteDatabaseNames(w http.ResponseWriter) {
|
|
// Emulate fake response for influx query.
|
|
// This is required for TSBS benchmark and some Telegraf plugins.
|
|
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1124
|
|
w.Header().Set("Content-Type", "application/json")
|
|
dbNames := *influxDatabaseNames
|
|
if len(dbNames) == 0 {
|
|
dbNames = []string{"_internal"}
|
|
}
|
|
dbs := make([]string, len(dbNames))
|
|
for i := range dbNames {
|
|
dbs[i] = fmt.Sprintf(`[%q]`, dbNames[i])
|
|
}
|
|
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":[]}`)
|
|
}
|