From b1aa8c3d8f68e9cc8f6bbcfa56bf3f6462c328db Mon Sep 17 00:00:00 2001 From: Nikolay Date: Mon, 15 Mar 2021 22:10:47 +0300 Subject: [PATCH] adds fake response for telegraph queries (#1130) https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1124 --- app/vmagent/README.md | 1 + app/vmagent/main.go | 13 +++++++++++-- app/vminsert/main.go | 13 +++++++++++-- docs/vmagent.md | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/vmagent/README.md b/app/vmagent/README.md index 2606690c5..cf6a739b8 100644 --- a/app/vmagent/README.md +++ b/app/vmagent/README.md @@ -515,6 +515,7 @@ See the docs at https://victoriametrics.github.io/vmagent.html . -import.maxLineLen max_rows_per_line The maximum length in bytes of a single line accepted by /api/v1/import; the line length can be limited with max_rows_per_line query arg passed to /api/v1/export Supports the following optional suffixes for values: KB, MB, GB, KiB, MiB, GiB (default 104857600) + -influx.databasesNames comma separated names of influx database, that will be returned for /query and /influx/query request. -influx.maxLineSize value The maximum size in bytes for a single Influx line during parsing Supports the following optional suffixes for values: KB, MB, GB, KiB, MiB, GiB (default 262144) diff --git a/app/vmagent/main.go b/app/vmagent/main.go index 865f03459..02b65641c 100644 --- a/app/vmagent/main.go +++ b/app/vmagent/main.go @@ -49,6 +49,7 @@ var ( dryRun = flag.Bool("dryRun", false, "Whether to check only config files without running vmagent. The following files are checked: "+ "-promscrape.config, -remoteWrite.relabelConfig, -remoteWrite.urlRelabelConfig . "+ "Unknown config entries are allowed in -promscrape.config by default. This can be changed with -promscrape.config.strictParse") + influxDatabasesNames = flag.String("influx.databasesNames", "_internal", "Comma separated names of databases, that will be returned for /query and /influx/query api.") ) var ( @@ -205,9 +206,17 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool { return true case "/query": // Emulate fake response for influx query. - // This is required for TSBS benchmark. + // This is required for TSBS benchmark and some telegraph plugins. influxQueryRequests.Inc() - fmt.Fprintf(w, `{"results":[{"series":[{"values":[]}]}]}`) + var dbs string + influxDbs := strings.Split(*influxDatabasesNames, ",") + for i := range influxDbs { + dbs += fmt.Sprintf(`"[%s]"`, influxDbs[i]) + if i != len(influxDbs)-1 { + dbs += "," + } + } + fmt.Fprintf(w, `{"results":[{"name":"databases","columns":["name"],"series":[{"values":[%s]}]}]}`, dbs) return true case "/targets": promscrapeTargetsRequests.Inc() diff --git a/app/vminsert/main.go b/app/vminsert/main.go index 5e69efeb9..55696ec68 100644 --- a/app/vminsert/main.go +++ b/app/vminsert/main.go @@ -40,6 +40,7 @@ var ( "Usually :4242 must be set. Doesn't work if empty") opentsdbHTTPListenAddr = flag.String("opentsdbHTTPListenAddr", "", "TCP address to listen for OpentTSDB HTTP put requests. Usually :4242 must be set. Doesn't work if empty") maxLabelsPerTimeseries = flag.Int("maxLabelsPerTimeseries", 30, "The maximum number of labels accepted per time series. Superfluous labels are dropped") + influxDatabasesNames = flag.String("influx.databasesNames", "_internal", "Comma separated names of databases, that will be returned for /query and /influx/query api.") ) var ( @@ -148,9 +149,17 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool { return true case "/influx/query", "/query": // Emulate fake response for influx query. - // This is required for TSBS benchmark. + // This is required for TSBS benchmark and some telegraph plugins. influxQueryRequests.Inc() - fmt.Fprintf(w, `{"results":[{"series":[{"values":[]}]}]}`) + var dbs string + influxDbs := strings.Split(*influxDatabasesNames, ",") + for i := range influxDbs { + dbs += fmt.Sprintf(`"[%s]"`, influxDbs[i]) + if i != len(influxDbs)-1 { + dbs += "," + } + } + fmt.Fprintf(w, `{"results":[{"name":"databases","columns":["name"],"series":[{"values":[%s]}]}]}`, dbs) return true case "/prometheus/targets", "/targets": promscrapeTargetsRequests.Inc() diff --git a/docs/vmagent.md b/docs/vmagent.md index 2606690c5..cf6a739b8 100644 --- a/docs/vmagent.md +++ b/docs/vmagent.md @@ -515,6 +515,7 @@ See the docs at https://victoriametrics.github.io/vmagent.html . -import.maxLineLen max_rows_per_line The maximum length in bytes of a single line accepted by /api/v1/import; the line length can be limited with max_rows_per_line query arg passed to /api/v1/export Supports the following optional suffixes for values: KB, MB, GB, KiB, MiB, GiB (default 104857600) + -influx.databasesNames comma separated names of influx database, that will be returned for /query and /influx/query request. -influx.maxLineSize value The maximum size in bytes for a single Influx line during parsing Supports the following optional suffixes for values: KB, MB, GB, KiB, MiB, GiB (default 262144)