2016-04-13 14:08:22 +00:00
|
|
|
// Copyright 2016 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2015-06-04 16:07:57 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2017-10-25 04:21:42 +00:00
|
|
|
"context"
|
2023-11-08 03:49:39 +00:00
|
|
|
"errors"
|
2015-06-04 16:07:57 +00:00
|
|
|
"fmt"
|
2016-12-24 23:37:46 +00:00
|
|
|
"math"
|
2017-12-03 05:07:05 +00:00
|
|
|
"math/rand"
|
2020-02-17 17:19:15 +00:00
|
|
|
"net"
|
2015-06-04 16:07:57 +00:00
|
|
|
"net/http"
|
2017-04-25 05:42:33 +00:00
|
|
|
"net/url"
|
2017-12-03 05:07:05 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2024-01-15 16:24:46 +00:00
|
|
|
"slices"
|
2022-12-23 10:55:08 +00:00
|
|
|
"sort"
|
2015-06-04 16:07:57 +00:00
|
|
|
"strconv"
|
2019-11-11 21:42:24 +00:00
|
|
|
"strings"
|
2015-06-04 16:07:57 +00:00
|
|
|
"time"
|
|
|
|
|
2021-06-11 16:17:59 +00:00
|
|
|
"github.com/go-kit/log"
|
|
|
|
"github.com/go-kit/log/level"
|
2022-02-12 23:58:27 +00:00
|
|
|
"github.com/grafana/regexp"
|
2018-02-07 12:27:57 +00:00
|
|
|
jsoniter "github.com/json-iterator/go"
|
2023-02-27 02:27:09 +00:00
|
|
|
"github.com/munnerz/goautoneg"
|
2018-10-10 23:09:08 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2015-08-20 15:18:46 +00:00
|
|
|
"github.com/prometheus/common/model"
|
2015-09-24 15:07:11 +00:00
|
|
|
"github.com/prometheus/common/route"
|
2020-10-22 09:00:08 +00:00
|
|
|
|
2017-05-11 15:09:24 +00:00
|
|
|
"github.com/prometheus/prometheus/config"
|
2021-11-08 14:23:17 +00:00
|
|
|
"github.com/prometheus/prometheus/model/labels"
|
2023-11-22 14:39:21 +00:00
|
|
|
"github.com/prometheus/prometheus/model/metadata"
|
2021-11-08 14:23:17 +00:00
|
|
|
"github.com/prometheus/prometheus/model/timestamp"
|
2015-06-04 16:07:57 +00:00
|
|
|
"github.com/prometheus/prometheus/promql"
|
2020-02-03 18:06:39 +00:00
|
|
|
"github.com/prometheus/prometheus/promql/parser"
|
2018-03-25 16:50:34 +00:00
|
|
|
"github.com/prometheus/prometheus/rules"
|
2018-02-01 09:55:07 +00:00
|
|
|
"github.com/prometheus/prometheus/scrape"
|
2016-12-29 08:27:30 +00:00
|
|
|
"github.com/prometheus/prometheus/storage"
|
2017-10-23 20:28:17 +00:00
|
|
|
"github.com/prometheus/prometheus/storage/remote"
|
2019-11-18 19:53:33 +00:00
|
|
|
"github.com/prometheus/prometheus/tsdb"
|
|
|
|
"github.com/prometheus/prometheus/tsdb/index"
|
2023-09-14 16:57:31 +00:00
|
|
|
"github.com/prometheus/prometheus/util/annotations"
|
2015-09-17 12:49:50 +00:00
|
|
|
"github.com/prometheus/prometheus/util/httputil"
|
2017-02-08 11:58:40 +00:00
|
|
|
"github.com/prometheus/prometheus/util/stats"
|
2015-06-04 16:07:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type status string
|
|
|
|
|
|
|
|
const (
|
|
|
|
statusSuccess status = "success"
|
2017-12-02 13:52:43 +00:00
|
|
|
statusError status = "error"
|
2023-01-25 19:22:25 +00:00
|
|
|
|
|
|
|
// Non-standard status code (originally introduced by nginx) for the case when a client closes
|
|
|
|
// the connection while the server is still processing the request.
|
|
|
|
statusClientClosedConnection = 499
|
2015-06-04 16:07:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type errorType string
|
|
|
|
|
|
|
|
const (
|
2023-02-27 02:27:09 +00:00
|
|
|
errorNone errorType = ""
|
|
|
|
errorTimeout errorType = "timeout"
|
|
|
|
errorCanceled errorType = "canceled"
|
|
|
|
errorExec errorType = "execution"
|
|
|
|
errorBadData errorType = "bad_data"
|
|
|
|
errorInternal errorType = "internal"
|
|
|
|
errorUnavailable errorType = "unavailable"
|
|
|
|
errorNotFound errorType = "not_found"
|
|
|
|
errorNotAcceptable errorType = "not_acceptable"
|
2015-06-04 16:07:57 +00:00
|
|
|
)
|
|
|
|
|
2021-10-22 08:06:44 +00:00
|
|
|
var LocalhostRepresentations = []string{"127.0.0.1", "localhost", "::1"}
|
2018-10-10 23:09:08 +00:00
|
|
|
|
2015-06-04 16:07:57 +00:00
|
|
|
type apiError struct {
|
|
|
|
typ errorType
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *apiError) Error() string {
|
|
|
|
return fmt.Sprintf("%s: %s", e.typ, e.err)
|
|
|
|
}
|
|
|
|
|
2022-12-23 10:55:08 +00:00
|
|
|
// ScrapePoolsRetriever provide the list of all scrape pools.
|
|
|
|
type ScrapePoolsRetriever interface {
|
|
|
|
ScrapePools() []string
|
|
|
|
}
|
|
|
|
|
2020-04-16 08:30:47 +00:00
|
|
|
// TargetRetriever provides the list of active/dropped targets to scrape or not.
|
|
|
|
type TargetRetriever interface {
|
2018-09-26 09:20:56 +00:00
|
|
|
TargetsActive() map[string][]*scrape.Target
|
|
|
|
TargetsDropped() map[string][]*scrape.Target
|
2023-08-14 14:39:25 +00:00
|
|
|
TargetsDroppedCounts() map[string]int
|
2016-12-02 12:31:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 18:02:32 +00:00
|
|
|
// AlertmanagerRetriever provides a list of all/dropped AlertManager URLs.
|
|
|
|
type AlertmanagerRetriever interface {
|
2017-04-25 05:42:33 +00:00
|
|
|
Alertmanagers() []*url.URL
|
2018-02-21 09:00:07 +00:00
|
|
|
DroppedAlertmanagers() []*url.URL
|
2016-12-02 12:31:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 18:02:32 +00:00
|
|
|
// RulesRetriever provides a list of active rules and alerts.
|
|
|
|
type RulesRetriever interface {
|
2018-03-25 16:50:34 +00:00
|
|
|
RuleGroups() []*rules.Group
|
2018-06-27 07:15:17 +00:00
|
|
|
AlertingRules() []*rules.AlertingRule
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-18 14:12:33 +00:00
|
|
|
// StatsRenderer converts engine statistics into a format suitable for the API.
|
2022-02-10 14:17:05 +00:00
|
|
|
type StatsRenderer func(context.Context, *stats.Statistics, string) stats.QueryStats
|
|
|
|
|
2024-05-18 14:12:33 +00:00
|
|
|
// DefaultStatsRenderer is the default stats renderer for the API.
|
|
|
|
func DefaultStatsRenderer(_ context.Context, s *stats.Statistics, param string) stats.QueryStats {
|
2022-02-10 14:17:05 +00:00
|
|
|
if param != "" {
|
|
|
|
return stats.NewQueryStats(s)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-11-02 15:53:32 +00:00
|
|
|
// PrometheusVersion contains build information about Prometheus.
|
|
|
|
type PrometheusVersion struct {
|
|
|
|
Version string `json:"version"`
|
|
|
|
Revision string `json:"revision"`
|
|
|
|
Branch string `json:"branch"`
|
|
|
|
BuildUser string `json:"buildUser"`
|
|
|
|
BuildDate string `json:"buildDate"`
|
|
|
|
GoVersion string `json:"goVersion"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// RuntimeInfo contains runtime information about Prometheus.
|
|
|
|
type RuntimeInfo struct {
|
|
|
|
StartTime time.Time `json:"startTime"`
|
|
|
|
CWD string `json:"CWD"`
|
|
|
|
ReloadConfigSuccess bool `json:"reloadConfigSuccess"`
|
|
|
|
LastConfigTime time.Time `json:"lastConfigTime"`
|
|
|
|
CorruptionCount int64 `json:"corruptionCount"`
|
|
|
|
GoroutineCount int `json:"goroutineCount"`
|
|
|
|
GOMAXPROCS int `json:"GOMAXPROCS"`
|
2023-03-28 18:47:18 +00:00
|
|
|
GOMEMLIMIT int64 `json:"GOMEMLIMIT"`
|
2019-11-02 15:53:32 +00:00
|
|
|
GOGC string `json:"GOGC"`
|
|
|
|
GODEBUG string `json:"GODEBUG"`
|
|
|
|
StorageRetention string `json:"storageRetention"`
|
|
|
|
}
|
|
|
|
|
2023-01-25 03:30:47 +00:00
|
|
|
// Response contains a response to a HTTP API request.
|
|
|
|
type Response struct {
|
2015-06-04 16:07:57 +00:00
|
|
|
Status status `json:"status"`
|
|
|
|
Data interface{} `json:"data,omitempty"`
|
|
|
|
ErrorType errorType `json:"errorType,omitempty"`
|
|
|
|
Error string `json:"error,omitempty"`
|
2018-11-30 14:27:12 +00:00
|
|
|
Warnings []string `json:"warnings,omitempty"`
|
2024-07-06 09:05:00 +00:00
|
|
|
Infos []string `json:"infos,omitempty"`
|
2018-11-30 14:27:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type apiFuncResult struct {
|
|
|
|
data interface{}
|
|
|
|
err *apiError
|
2023-09-14 16:57:31 +00:00
|
|
|
warnings annotations.Annotations
|
2018-11-30 14:27:12 +00:00
|
|
|
finalizer func()
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
type apiFunc func(r *http.Request) apiFuncResult
|
2015-11-11 19:46:57 +00:00
|
|
|
|
2020-04-29 16:16:14 +00:00
|
|
|
// TSDBAdminStats defines the tsdb interfaces used by the v1 API for admin operations as well as statistics.
|
|
|
|
type TSDBAdminStats interface {
|
2018-11-15 13:22:16 +00:00
|
|
|
CleanTombstones() error
|
2023-09-13 13:43:06 +00:00
|
|
|
Delete(ctx context.Context, mint, maxt int64, ms ...*labels.Matcher) error
|
2018-11-15 13:22:16 +00:00
|
|
|
Snapshot(dir string, withHead bool) error
|
2023-05-22 12:37:07 +00:00
|
|
|
Stats(statsByLabelName string, limit int) (*tsdb.Stats, error)
|
2021-06-05 14:29:32 +00:00
|
|
|
WALReplayStatus() (tsdb.WALReplayStatus, error)
|
2018-11-15 13:22:16 +00:00
|
|
|
}
|
|
|
|
|
2023-07-03 12:56:06 +00:00
|
|
|
type QueryOpts interface {
|
|
|
|
EnablePerStepStats() bool
|
|
|
|
LookbackDelta() time.Duration
|
2021-12-21 10:22:40 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 16:07:57 +00:00
|
|
|
// API can register a set of endpoints in a router and handle
|
|
|
|
// them using the provided storage and query engine.
|
|
|
|
type API struct {
|
2021-03-16 09:47:45 +00:00
|
|
|
Queryable storage.SampleAndChunkQueryable
|
2024-03-06 03:54:33 +00:00
|
|
|
QueryEngine promql.QueryEngine
|
2021-03-16 09:47:45 +00:00
|
|
|
ExemplarQueryable storage.ExemplarQueryable
|
2015-06-08 19:19:52 +00:00
|
|
|
|
2022-12-23 10:55:08 +00:00
|
|
|
scrapePoolsRetriever func(context.Context) ScrapePoolsRetriever
|
2020-04-16 08:30:47 +00:00
|
|
|
targetRetriever func(context.Context) TargetRetriever
|
2020-05-18 18:02:32 +00:00
|
|
|
alertmanagerRetriever func(context.Context) AlertmanagerRetriever
|
|
|
|
rulesRetriever func(context.Context) RulesRetriever
|
2018-03-25 16:50:34 +00:00
|
|
|
now func() time.Time
|
|
|
|
config func() config.Config
|
|
|
|
flagsMap map[string]string
|
|
|
|
ready func(http.HandlerFunc) http.HandlerFunc
|
2020-02-17 17:19:15 +00:00
|
|
|
globalURLOptions GlobalURLOptions
|
2017-12-03 05:07:05 +00:00
|
|
|
|
2022-02-10 14:17:05 +00:00
|
|
|
db TSDBAdminStats
|
|
|
|
dbDir string
|
|
|
|
enableAdmin bool
|
|
|
|
logger log.Logger
|
|
|
|
CORSOrigin *regexp.Regexp
|
|
|
|
buildInfo *PrometheusVersion
|
|
|
|
runtimeInfo func() (RuntimeInfo, error)
|
|
|
|
gatherer prometheus.Gatherer
|
|
|
|
isAgent bool
|
|
|
|
statsRenderer StatsRenderer
|
2021-02-26 16:43:19 +00:00
|
|
|
|
|
|
|
remoteWriteHandler http.Handler
|
|
|
|
remoteReadHandler http.Handler
|
2023-07-28 10:35:28 +00:00
|
|
|
otlpWriteHandler http.Handler
|
2015-06-04 16:07:57 +00:00
|
|
|
|
2023-02-27 02:27:09 +00:00
|
|
|
codecs []Codec
|
2018-10-10 23:09:08 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 19:46:57 +00:00
|
|
|
// NewAPI returns an initialized API type.
|
2017-10-06 15:20:20 +00:00
|
|
|
func NewAPI(
|
2024-03-06 03:54:33 +00:00
|
|
|
qe promql.QueryEngine,
|
2021-02-15 11:30:00 +00:00
|
|
|
q storage.SampleAndChunkQueryable,
|
|
|
|
ap storage.Appendable,
|
2021-03-16 09:47:45 +00:00
|
|
|
eq storage.ExemplarQueryable,
|
2022-12-23 10:55:08 +00:00
|
|
|
spsr func(context.Context) ScrapePoolsRetriever,
|
2020-04-16 08:30:47 +00:00
|
|
|
tr func(context.Context) TargetRetriever,
|
2020-05-18 18:02:32 +00:00
|
|
|
ar func(context.Context) AlertmanagerRetriever,
|
2017-10-06 15:20:20 +00:00
|
|
|
configFunc func() config.Config,
|
api: Added v1/status/flags endpoint. (#3864)
Endpoint URL: /api/v1/status/flags
Example Output:
```json
{
"status": "success",
"data": {
"alertmanager.notification-queue-capacity": "10000",
"alertmanager.timeout": "10s",
"completion-bash": "false",
"completion-script-bash": "false",
"completion-script-zsh": "false",
"config.file": "my_cool_prometheus.yaml",
"help": "false",
"help-long": "false",
"help-man": "false",
"log.level": "info",
"query.lookback-delta": "5m",
"query.max-concurrency": "20",
"query.timeout": "2m",
"storage.tsdb.max-block-duration": "36h",
"storage.tsdb.min-block-duration": "2h",
"storage.tsdb.no-lockfile": "false",
"storage.tsdb.path": "data/",
"storage.tsdb.retention": "15d",
"version": "false",
"web.console.libraries": "console_libraries",
"web.console.templates": "consoles",
"web.enable-admin-api": "false",
"web.enable-lifecycle": "false",
"web.external-url": "",
"web.listen-address": "0.0.0.0:9090",
"web.max-connections": "512",
"web.read-timeout": "5m",
"web.route-prefix": "/",
"web.user-assets": ""
}
}
```
Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
2018-02-21 08:49:02 +00:00
|
|
|
flagsMap map[string]string,
|
2020-02-17 17:19:15 +00:00
|
|
|
globalURLOptions GlobalURLOptions,
|
2017-10-06 15:20:20 +00:00
|
|
|
readyFunc func(http.HandlerFunc) http.HandlerFunc,
|
2020-04-29 16:16:14 +00:00
|
|
|
db TSDBAdminStats,
|
|
|
|
dbDir string,
|
2017-12-03 05:07:05 +00:00
|
|
|
enableAdmin bool,
|
2018-07-06 17:44:45 +00:00
|
|
|
logger log.Logger,
|
2020-05-18 18:02:32 +00:00
|
|
|
rr func(context.Context) RulesRetriever,
|
2018-09-25 19:07:34 +00:00
|
|
|
remoteReadSampleLimit int,
|
|
|
|
remoteReadConcurrencyLimit int,
|
2019-08-19 20:16:10 +00:00
|
|
|
remoteReadMaxBytesInFrame int,
|
2021-10-29 15:25:05 +00:00
|
|
|
isAgent bool,
|
2023-04-09 07:08:40 +00:00
|
|
|
corsOrigin *regexp.Regexp,
|
2019-11-02 15:53:32 +00:00
|
|
|
runtimeInfo func() (RuntimeInfo, error),
|
|
|
|
buildInfo *PrometheusVersion,
|
2020-09-29 20:05:33 +00:00
|
|
|
gatherer prometheus.Gatherer,
|
2021-02-26 16:43:19 +00:00
|
|
|
registerer prometheus.Registerer,
|
2022-02-10 14:17:05 +00:00
|
|
|
statsRenderer StatsRenderer,
|
2023-07-28 10:35:28 +00:00
|
|
|
rwEnabled bool,
|
[PRW 2.0] Merging `remote-write-2.0` feature branch to main (PRW 2.0 support + metadata in WAL) (#14395)
* Remote Write 1.1: e2e benchmarks (#13102)
* Remote Write e2e benchmarks
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Prometheus ports automatically assigned
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* make dashboard editable + more modular to different job label values
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* Dashboard improvements
* memory stats
* diffs look at counter increases
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* run script: absolute path for config templates
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* grafana dashboard improvements
* show actual values of metrics
* add memory stats and diff
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* dashboard changes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
---------
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Co-authored-by: Callum Styan <callumstyan@gmail.com>
* replace snappy encoding library
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add new proto types
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add decode function for new write request proto
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add lookup table struct that is used to build the symbol table in new
write request format
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Implement code paths for new proto format
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* update example server to include handler for new format
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Add new test client
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* tests and new -> original proto mapping util
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add new proto support on receiver end
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Fix test
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* no-brainer copypaste but more performance write support
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove some comented code
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix mocks and fixture
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add basic reduce remote write handler benchmark
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* refactor out common code between write methods
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix: queue manager to include float histograms in new requests
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add sender-side tests and fix failing ones
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* refactor queue manager code to remove some duplication
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix build
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Improve sender benchmarks and some allocations
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Use github.com/golang/snappy
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* cleanup: remove hardcoded fake url for testing
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Add 1.1 version handling code
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Remove config, update proto
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* gofmt
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix NewWriteClient and change new flags wording
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fields rewording in handler
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remote write handler to checks version header
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix typo in log
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* lint
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Add minmized remote write proto format
Co-authored-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add functions for translating between new proto formats symbol table and
actual prometheus labels
Co-authored-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add functionality for new minimized remote write request format
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix minor things
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Make LabelSymbols a fixed32
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove unused proto type
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* update tests
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix build for stringlabels tag
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Use two uint32 to encode (offset,leng)
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* manually optimize varint marshaling
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Use unsafe []byte->string cast to reuse buffer
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix writeRequestMinimizedFixture
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove all code from previous interning approach
the 'minimized' version is now the only v1.1 version
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* minimally-tested exemplar support for rw 1.1
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* refactor new version flag to make it easier to pick a specific format
instead of having multiple flags, plus add new formats for testing
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* use exp slices for backwards compat. to go 1.20 plus add copyright
header to test file
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix label ranging
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Add bytes slice (instead of slice of 32bit vars) format for testing
Co-authored-by: Nicolás Pazos <npazosmendez@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* test additional len and lenbytes formats
Co-authored-by: Nicolás Pazos <npazosmendez@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove mistaken package lock changes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove formats we've decided not to use
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove more format types we probably won't use
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* More cleanup
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* use require instead of assert in custom marshal test
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* cleanup; remove some unused functions
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* more cleanup, mostly linting fixes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove package-lock.json change again
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* more cleanup, address review comments
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix test panic
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix minor lint issue + use labels Range function since it looks like
the tests fail to do `range labels.Labels` on CI
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* new interning format based on []string indeces
Co-authored-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove all new rw formats but the []string one
also adapt tests to the new format
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* cleanup rwSymbolTable
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add some TODOs for later
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* don't reserve field 3 for new proto and add TODO
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix custom marshaling
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* lint
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* additional merge fixes
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* lint fixes
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix server example
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* revert package-lock.json changes
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* update example prometheus version
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* define separate proto types for remote write 2.0
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* lint
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* rename new proto types and move to separate pkg
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* update prometheus version for example
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* make proto
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* make Metadata not nullable
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove old MinSample proto message
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* change enum names to fit buf build recommend enum naming and lint rules
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* remote: Added test for classic histogram grouping when sending rw; Fixed queue manager test delay. (#13421)
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Remote write v2: metadata support in every write request (#13394)
* Approach bundling metadata along with samples and exemplars
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
* Add first test; rebase with main
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
* Alternative approach: bundle metadata in TimeSeries protobuf
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
* update go mod to match main branch
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* fix after rebase
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* we're not going to modify the 1.X format anymore
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* Modify AppendMetadata based on the fact that we be putting metadata into
timeseries
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* Rename enums for remote write versions to something that makes more
sense + remove the added `sendMetadata` flag.
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* rename flag that enables writing of metadata records to the WAL
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* additional clean up
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* lint
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* fix usage of require.Len
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* some clean up from review comments
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* more review fixes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
---------
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Co-authored-by: Paschalis Tsilias <paschalist0@gmail.com>
* remote write 2.0: sync with `main` branch (#13510)
* consoles: exclude iowait and steal from CPU Utilisation
'iowait' and 'steal' indicate specific idle/wait states, which shouldn't
be counted into CPU Utilisation. Also see
https://github.com/prometheus-operator/kube-prometheus/pull/796 and
https://github.com/kubernetes-monitoring/kubernetes-mixin/pull/667.
Per the iostat man page:
%idle
Show the percentage of time that the CPU or CPUs were idle and the
system did not have an outstanding disk I/O request.
%iowait
Show the percentage of time that the CPU or CPUs were idle during
which the system had an outstanding disk I/O request.
%steal
Show the percentage of time spent in involuntary wait by the
virtual CPU or CPUs while the hypervisor was servicing another
virtual processor.
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
* tsdb: shrink txRing with smaller integers
4 billion active transactions ought to be enough for anyone.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* tsdb: create isolation transaction slice on demand
When Prometheus restarts it creates every series read in from the WAL,
but many of those series will be finished, and never receive any more
samples. By defering allocation of the txRing slice to when it is first
needed, we save 32 bytes per stale series.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* add cluster variable to Overview dashboard
Signed-off-by: Erik Sommer <ersotech@posteo.de>
* promql: simplify Native Histogram arithmetics
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
* Cut 2.49.0-rc.0 (#13270)
* Cut 2.49.0-rc.0
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Removed the duplicate.
Signed-off-by: bwplotka <bwplotka@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Add unit protobuf parser
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* Go on adding protobuf parsing for unit
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* ui: create a reproduction for https://github.com/prometheus/prometheus/issues/13292
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
* Get conditional right
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* Get VM Scale Set NIC (#13283)
Calling `*armnetwork.InterfacesClient.Get()` doesn't work for Scale Set
VM NIC, because these use a different Resource ID format.
Use `*armnetwork.InterfacesClient.GetVirtualMachineScaleSetNetworkInterface()`
instead. This needs both the scale set name and the instance ID, so
add an `InstanceID` field to the `virtualMachine` struct. `InstanceID`
is empty for a VM that isn't a ScaleSetVM.
Signed-off-by: Daniel Nicholls <daniel.nicholls@resdiary.com>
* Cut v2.49.0-rc.1
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Delete debugging lines, amend error message for unit
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* Correct order in error message
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* Consider storage.ErrTooOldSample as non-retryable
Signed-off-by: Daniel Kerbel <nmdanny@gmail.com>
* scrape_test.go: Increase scrape interval in TestScrapeLoopCache to reduce potential flakiness
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
* Avoid creating string for suffix, consider counters without _total suffix
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* build(deps): bump github.com/prometheus/client_golang
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.17.0 to 1.18.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.17.0...v1.18.0)
---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* build(deps): bump actions/setup-node from 3.8.1 to 4.0.1
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3.8.1 to 4.0.1.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d...b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8)
---
updated-dependencies:
- dependency-name: actions/setup-node
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* scripts: sort file list in embed directive
Otherwise the resulting string depends on find, which afaict depends on
the underlying filesystem. A stable file list make it easier to detect
UI changes in downstreams that need to track UI assets.
Signed-off-by: Jan Fajerski <jfajersk@redhat.com>
* Fix DataTableProps['data'] for resultType string
Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
* Fix handling of scalar and string in isHeatmapData
Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
* build(deps): bump github.com/influxdata/influxdb
Bumps [github.com/influxdata/influxdb](https://github.com/influxdata/influxdb) from 1.11.2 to 1.11.4.
- [Release notes](https://github.com/influxdata/influxdb/releases)
- [Commits](https://github.com/influxdata/influxdb/compare/v1.11.2...v1.11.4)
---
updated-dependencies:
- dependency-name: github.com/influxdata/influxdb
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* build(deps): bump github.com/prometheus/prometheus
Bumps [github.com/prometheus/prometheus](https://github.com/prometheus/prometheus) from 0.48.0 to 0.48.1.
- [Release notes](https://github.com/prometheus/prometheus/releases)
- [Changelog](https://github.com/prometheus/prometheus/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/prometheus/compare/v0.48.0...v0.48.1)
---
updated-dependencies:
- dependency-name: github.com/prometheus/prometheus
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* Bump client_golang to v1.18.0 (#13373)
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Drop old inmemory samples (#13002)
* Drop old inmemory samples
Co-authored-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Avoid copying timeseries when the feature is disabled
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Run gofmt
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Clarify docs
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Add more logging info
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Remove loggers
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* optimize function and add tests
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Simplify filter
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* rename var
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Update help info from metrics
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* use metrics to keep track of drop elements during buildWriteRequest
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* rename var in tests
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* pass time.Now as parameter
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Change buildwriterequest during retries
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Revert "Remove loggers"
This reverts commit 54f91dfcae20488944162335ab4ad8be459df1ab.
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* use log level debug for loggers
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Fix linter
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Remove noisy debug-level logs; add 'reason' label to drop metrics
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Remove accidentally committed files
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Propagate logger to buildWriteRequest to log dropped data
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Fix docs comment
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Make drop reason more specific
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Remove unnecessary pass of logger
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Use snake_case for reason label
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Fix dropped samples metric
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
---------
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
Signed-off-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
Co-authored-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
* fix(discovery): allow requireUpdate util to timeout in discovery/file/file_test.go.
The loop ran indefinitely if the condition isn't met.
Before, each iteration created a new timer channel which was always outpaced by
the other timer channel with smaller duration.
minor detail: There was a memory leak: resources of the ~10 previous timers were
constantly kept. With the fix, we may keep the resources of one timer around for defaultWait
but this isn't worth the changes to make it right.
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
* Merge pull request #13371 from kevinmingtarja/fix-isHeatmapData
ui: fix handling of scalar and string in isHeatmapData
* tsdb/{index,compact}: allow using custom postings encoding format (#13242)
* tsdb/{index,compact}: allow using custom postings encoding format
We would like to experiment with a different postings encoding format in
Thanos so in this change I am proposing adding another argument to
`NewWriter` which would allow users to change the format if needed.
Also, wire the leveled compactor so that it would be possible to change
the format there too.
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* tsdb/compact: use a struct for leveled compactor options
As discussed on Slack, let's use a struct for the options in leveled
compactor.
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* tsdb: make changes after Bryan's review
- Make changes less intrusive
- Turn the postings encoder type into a function
- Add NewWriterWithEncoder()
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
---------
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* Cut 2.49.0-rc.2
Signed-off-by: bwplotka <bwplotka@gmail.com>
* build(deps): bump actions/setup-go from 3.5.0 to 5.0.0 in /scripts (#13362)
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 3.5.0 to 5.0.0.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/6edd4406fa81c3da01a34fa6f6343087c207a568...0c52d547c9bc32b1aa3301fd7a9cb496313a4491)
---
updated-dependencies:
- dependency-name: actions/setup-go
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* build(deps): bump github/codeql-action from 2.22.8 to 3.22.12 (#13358)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.22.8 to 3.22.12.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/407ffafae6a767df3e0230c3df91b6443ae8df75...012739e5082ff0c22ca6d6ab32e07c36df03c4a4)
---
updated-dependencies:
- dependency-name: github/codeql-action
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* put @nexucis has a release shepherd (#13383)
Signed-off-by: Augustin Husson <augustin.husson@amadeus.com>
* Add analyze histograms command to promtool (#12331)
Add `query analyze` command to promtool
This command analyzes the buckets of classic and native histograms,
based on data queried from the Prometheus query API, i.e. it
doesn't require direct access to the TSDB files.
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
---------
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
* included instance in all necessary descriptions
Signed-off-by: Erik Sommer <ersotech@posteo.de>
* tsdb/compact: fix passing merge func
Fixing a very small logical problem I've introduced :(.
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* tsdb: add enable overlapping compaction
This functionality is needed in downstream projects because they have a
separate component that does compaction.
Upstreaming
https://github.com/grafana/mimir-prometheus/blob/7c8e9a2a76fc729e9078889782928b2fdfe240e9/tsdb/compact.go#L323-L325.
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* Cut 2.49.0
Signed-off-by: bwplotka <bwplotka@gmail.com>
* promtool: allow setting multiple matchers to "promtool tsdb dump" command. (#13296)
Conditions are ANDed inside the same matcher but matchers are ORed
Including unit tests for "promtool tsdb dump".
Refactor some matchers scraping utils.
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
* Fixed changelog
Signed-off-by: bwplotka <bwplotka@gmail.com>
* tsdb/main: wire "EnableOverlappingCompaction" to tsdb.Options (#13398)
This added the https://github.com/prometheus/prometheus/pull/13393
"EnableOverlappingCompaction" parameter to the compactor code but not to
the tsdb.Options. I forgot about that. Add it to `tsdb.Options` too and
set it to `true` in Prometheus.
Copy/paste the description from
https://github.com/prometheus/prometheus/pull/13393#issuecomment-1891787986
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* Issue #13268: fix quality value in accept header
Signed-off-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com>
* Cut 2.49.1 with scrape q= bugfix.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Cut 2.49.1 web package.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Restore more efficient version of NewPossibleNonCounterInfo annotation (#13022)
Restore more efficient version of NewPossibleNonCounterInfo annotation
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
---------
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
* Fix regressions introduced by #13242
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* fix slice copy in 1.20 (#13389)
The slices package is added to the standard library in Go 1.21;
we need to import from the exp area to maintain compatibility with Go 1.20.
Signed-off-by: tyltr <tylitianrui@126.com>
* Docs: Query Basics: link to rate (#10538)
Co-authored-by: Julien Pivotto <roidelapluie@o11y.eu>
* chore(kubernetes): check preconditions earlier and avoid unnecessary checks or iterations
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
* Examples: link to `rate` for new users (#10535)
* Examples: link to `rate` for new users
Signed-off-by: Ted Robertson 10043369+tredondo@users.noreply.github.com
Co-authored-by: Bryan Boreham <bjboreham@gmail.com>
* promql: use natural sort in sort_by_label and sort_by_label_desc (#13411)
These functions are intended for humans, as robots can already sort the results
however they please. Humans like things sorted "naturally":
* https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/
A similar thing has been done to Grafana, which is also used by humans:
* https://github.com/grafana/grafana/pull/78024
* https://github.com/grafana/grafana/pull/78494
Signed-off-by: Ivan Babrou <github@ivan.computer>
* TestLabelValuesWithMatchers: Add test case
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* remove obsolete build tag
Signed-off-by: tyltr <tylitianrui@126.com>
* Upgrade some golang dependencies for resty 2.11
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
* Native Histograms: support `native_histogram_min_bucket_factor` in scrape_config (#13222)
Native Histograms: support native_histogram_min_bucket_factor in scrape_config
---------
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
* Add warnings for histogramRate applied with isCounter not matching counter/gauge histogram (#13392)
Add warnings for histogramRate applied with isCounter not matching counter/gauge histogram
---------
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
* Minor fixes to otlp vendor update script
Signed-off-by: Goutham <gouthamve@gmail.com>
* build(deps): bump github.com/hetznercloud/hcloud-go/v2
Bumps [github.com/hetznercloud/hcloud-go/v2](https://github.com/hetznercloud/hcloud-go) from 2.4.0 to 2.6.0.
- [Release notes](https://github.com/hetznercloud/hcloud-go/releases)
- [Changelog](https://github.com/hetznercloud/hcloud-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hetznercloud/hcloud-go/compare/v2.4.0...v2.6.0)
---
updated-dependencies:
- dependency-name: github.com/hetznercloud/hcloud-go/v2
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Enhanced visibility for `promtool test rules` with JSON colored formatting (#13342)
* Added diff flag for unit test to improvise readability & debugging
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Removed blank spaces
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Fixed linting error
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Added cli flags to documentation
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Revert unrrelated linting fixes
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Fixed review suggestions
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Cleanup
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Updated flag description
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Updated flag description
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
---------
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* storage: skip merging when no remote storage configured
Prometheus is hard-coded to use a fanout storage between TSDB and
a remote storage which by default is empty.
This change detects the empty storage and skips merging between
result sets, which would make `Select()` sort results.
Bottom line: we skip a sort unless there really is some remote storage
configured.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* Remove csmarchbanks from remote write owners (#13432)
I have not had the time to keep up with remote write and have no plans
to work on it in the near future so I am withdrawing my maintainership
of that part of the codebase. I continue to focus on client_python.
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
* add more context cancellation check at evaluation time
Signed-off-by: Ben Ye <benye@amazon.com>
* Optimize label values with matchers by taking shortcuts (#13426)
Don't calculate postings beforehand: we may not need them. If all
matchers are for the requested label, we can just filter its values.
Also, if there are no values at all, no need to run any kind of
logic.
Also add more labelValuesWithMatchers benchmarks
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
* Add automatic memory limit handling
Enable automatic detection of memory limits and configure GOMEMLIMIT to
match.
* Also includes a flag to allow controlling the reserved ratio.
Signed-off-by: SuperQ <superq@gmail.com>
* Update OSSF badge link (#13433)
Provide a more user friendly interface
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
* SD Managers taking over responsibility for registration of debug metrics (#13375)
SD Managers take over responsibility for SD metrics registration
---------
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
* Optimize histogram iterators (#13340)
Optimize histogram iterators
Histogram iterators allocate new objects in the AtHistogram and
AtFloatHistogram methods, which makes calculating rates over long
ranges expensive.
In #13215 we allowed an existing object to be reused
when converting an integer histogram to a float histogram. This commit follows
the same idea and allows injecting an existing object in the AtHistogram and
AtFloatHistogram methods. When the injected value is nil, iterators allocate
new histograms, otherwise they populate and return the injected object.
The commit also adds a CopyTo method to Histogram and FloatHistogram which
is used in the BufferedIterator to overwrite items in the ring instead of making
new copies.
Note that a specialized HPoint pool is needed for all of this to work
(`matrixSelectorHPool`).
---------
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
* doc: Mark `mad_over_time` as experimental (#13440)
We forgot to do that in
https://github.com/prometheus/prometheus/pull/13059
Signed-off-by: beorn7 <beorn@grafana.com>
* Change metric label for Puppetdb from 'http' to 'puppetdb'
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
* mirror metrics.proto change & generate code
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
* TestHeadLabelValuesWithMatchers: Add test case (#13414)
Add test case to TestHeadLabelValuesWithMatchers, while fixing a couple
of typos in other test cases. Also enclosing some implicit sub-tests in a
`t.Run` call to make them explicitly sub-tests.
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* update all go dependencies (#13438)
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
* build(deps): bump the k8s-io group with 2 updates (#13454)
Bumps the k8s-io group with 2 updates: [k8s.io/api](https://github.com/kubernetes/api) and [k8s.io/client-go](https://github.com/kubernetes/client-go).
Updates `k8s.io/api` from 0.28.4 to 0.29.1
- [Commits](https://github.com/kubernetes/api/compare/v0.28.4...v0.29.1)
Updates `k8s.io/client-go` from 0.28.4 to 0.29.1
- [Changelog](https://github.com/kubernetes/client-go/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kubernetes/client-go/compare/v0.28.4...v0.29.1)
---
updated-dependencies:
- dependency-name: k8s.io/api
dependency-type: direct:production
update-type: version-update:semver-minor
dependency-group: k8s-io
- dependency-name: k8s.io/client-go
dependency-type: direct:production
update-type: version-update:semver-minor
dependency-group: k8s-io
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* build(deps): bump the go-opentelemetry-io group with 1 update (#13453)
Bumps the go-opentelemetry-io group with 1 update: [go.opentelemetry.io/collector/semconv](https://github.com/open-telemetry/opentelemetry-collector).
Updates `go.opentelemetry.io/collector/semconv` from 0.92.0 to 0.93.0
- [Release notes](https://github.com/open-telemetry/opentelemetry-collector/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-collector/blob/main/CHANGELOG-API.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-collector/compare/v0.92.0...v0.93.0)
---
updated-dependencies:
- dependency-name: go.opentelemetry.io/collector/semconv
dependency-type: direct:production
update-type: version-update:semver-minor
dependency-group: go-opentelemetry-io
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* build(deps): bump actions/upload-artifact from 3.1.3 to 4.0.0 (#13355)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3.1.3 to 4.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/a8a3f3ad30e3422c9c7b888a15615d19a852ae32...c7d193f32edcb7bfad88892161225aeda64e9392)
---
updated-dependencies:
- dependency-name: actions/upload-artifact
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* build(deps): bump bufbuild/buf-push-action (#13357)
Bumps [bufbuild/buf-push-action](https://github.com/bufbuild/buf-push-action) from 342fc4cdcf29115a01cf12a2c6dd6aac68dc51e1 to a654ff18effe4641ebea4a4ce242c49800728459.
- [Release notes](https://github.com/bufbuild/buf-push-action/releases)
- [Commits](https://github.com/bufbuild/buf-push-action/compare/342fc4cdcf29115a01cf12a2c6dd6aac68dc51e1...a654ff18effe4641ebea4a4ce242c49800728459)
---
updated-dependencies:
- dependency-name: bufbuild/buf-push-action
dependency-type: direct:production
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Labels: Add DropMetricName function, used in PromQL (#13446)
This function is called very frequently when executing PromQL functions,
and we can do it much more efficiently inside Labels.
In the common case that `__name__` comes first in the labels, we simply
re-point to start at the next label, which is nearly free.
`DropMetricName` is now so cheap I removed the cache - benchmarks show
everything still goes faster.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* tsdb: simplify internal series delete function (#13261)
Lifting an optimisation from Agent code, `seriesHashmap.del` can use
the unique series reference, doesn't need to check Labels.
Also streamline the logic for deleting from `unique` and `conflicts` maps,
and add some comments to help the next person.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* otlptranslator/update-copy.sh: Fix sed command lines
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Rollback k8s.io requirements (#13462)
Rollback k8s.io Go modules to v0.28.6 to avoid forcing upgrade of Go to
1.21. This allows us to keep compatibility with the currently supported
upstream Go releases.
Signed-off-by: SuperQ <superq@gmail.com>
* Make update-copy.sh work for both OSX and GNU sed
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Name @beorn7 and @krajorama as maintainers for native histograms
I have been the de-facto maintainer for native histograms from the
beginning. So let's put this into MAINTAINERS.md.
In addition, I hereby proposose George Krajcsovits AKA Krajo as a
co-maintainer. He has contributed a lot of native histogram code, but
more importantly, he has contributed substantially to reviewing other
contributors' native histogram code, up to a point where I was merely
rubberstamping the PRs he had already reviewed. I'm confident that he
is ready to to be granted commit rights as outlined in the
"Maintainers" section of the governance:
https://prometheus.io/governance/#maintainers
According to the same section of the governance, I will announce the
proposed change on the developers mailing list and will give some time
for lazy consensus before merging this PR.
Signed-off-by: beorn7 <beorn@grafana.com>
* ui/fix: correct url handling for stacked graphs (#13460)
Signed-off-by: Yury Moladau <yurymolodov@gmail.com>
* tsdb: use cheaper Mutex on series
Mutex is 8 bytes; RWMutex is 24 bytes and much more complicated. Since
`RLock` is only used in two places, `UpdateMetadata` and `Delete`,
neither of which are hotspots, we should use the cheaper one.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* Fix last_over_time for native histograms
The last_over_time retains a histogram sample without making a copy.
This sample is now coming from the buffered iterator used for windowing functions,
and can be reused for reading subsequent samples as the iterator progresses.
I would propose copying the sample in the last_over_time function, similar to
how it is done for rate, sum_over_time and others.
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
* Implementation
NOTE:
Rebased from main after refactor in #13014
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Add feature flag
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Refactor concurrency control
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Optimising dependencies/dependents funcs to not produce new slices each request
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Refactoring
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Rename flag
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Refactoring for performance, and to allow controller to be overridden
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Block until all rules, both sync & async, have completed evaluating
Updated & added tests
Review feedback nits
Return empty map if not indeterminate
Use highWatermark to track inflight requests counter
Appease the linter
Clarify feature flag
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Fix typo in CLI flag description
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Fixed auto-generated doc
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Improve doc
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Simplify the design to update concurrency controller once the rule evaluation has done
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Add more test cases to TestDependenciesEdgeCases
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Added more test cases to TestDependenciesEdgeCases
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Improved RuleConcurrencyController interface doc
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Introduced sequentialRuleEvalController
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Remove superfluous nil check in Group.metrics
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* api: Serialize discovered and target labels into JSON directly (#13469)
Converted maps into labels.Labels to avoid a lot of copying of data which leads to very high memory consumption while opening the /service-discovery endpoint in the Prometheus UI
Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
* api: Serialize discovered labels into JSON directly in dropped targets (#13484)
Converted maps into labels.Labels to avoid a lot of copying of data which leads to very high memory consumption while opening the /service-discovery endpoint in the Prometheus UI
Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
* Add ShardedPostings() support to TSDB (#10421)
This PR is a reference implementation of the proposal described in #10420.
In addition to what described in #10420, in this PR I've introduced labels.StableHash(). The idea is to offer an hashing function which doesn't change over time, and that's used by query sharding in order to get a stable behaviour over time. The implementation of labels.StableHash() is the hashing function used by Prometheus before stringlabels, and what's used by Grafana Mimir for query sharding (because built before stringlabels was a thing).
Follow up work
As mentioned in #10420, if this PR is accepted I'm also open to upload another foundamental piece used by Grafana Mimir query sharding to accelerate the query execution: an optional, configurable and fast in-memory cache for the series hashes.
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* storage/remote: document why two benchmarks are skipped
One was silently doing nothing; one was doing something but the work
didn't go up linearly with iteration count.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* Pod status changes not discovered by Kube Endpoints SD (#13337)
* fix(discovery/kubernetes/endpoints): react to changes on Pods because some modifications can occur on them without triggering an update on the related Endpoints (The Pod phase changing from Pending to Running e.g.).
---------
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
Co-authored-by: Guillermo Sanchez Gavier <gsanchez@newrelic.com>
* Small improvements, add const, remove copypasta (#8106)
Signed-off-by: Mikhail Fesenko <proggga@gmail.com>
Signed-off-by: Jesus Vazquez <jesusvzpg@gmail.com>
* Proposal to improve FPointSlice and HPointSlice allocation. (#13448)
* Reusing points slice from previous series when the slice is under utilized
* Adding comments on the bench test
Signed-off-by: Alan Protasio <alanprot@gmail.com>
* lint
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* go mod tidy
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
---------
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Erik Sommer <ersotech@posteo.de>
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
Signed-off-by: Daniel Nicholls <daniel.nicholls@resdiary.com>
Signed-off-by: Daniel Kerbel <nmdanny@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Jan Fajerski <jfajersk@redhat.com>
Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
Signed-off-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Signed-off-by: Augustin Husson <augustin.husson@amadeus.com>
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: tyltr <tylitianrui@126.com>
Signed-off-by: Ted Robertson 10043369+tredondo@users.noreply.github.com
Signed-off-by: Ivan Babrou <github@ivan.computer>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Signed-off-by: Goutham <gouthamve@gmail.com>
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
Signed-off-by: Ben Ye <benye@amazon.com>
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Signed-off-by: SuperQ <superq@gmail.com>
Signed-off-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Signed-off-by: beorn7 <beorn@grafana.com>
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
Signed-off-by: Yury Moladau <yurymolodov@gmail.com>
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
Signed-off-by: Mikhail Fesenko <proggga@gmail.com>
Signed-off-by: Jesus Vazquez <jesusvzpg@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
Co-authored-by: Julian Wiedmann <jwi@linux.ibm.com>
Co-authored-by: Bryan Boreham <bjboreham@gmail.com>
Co-authored-by: Erik Sommer <ersotech@posteo.de>
Co-authored-by: Linas Medziunas <linas.medziunas@gmail.com>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Co-authored-by: Arianna Vespri <arianna.vespri@yahoo.it>
Co-authored-by: machine424 <ayoubmrini424@gmail.com>
Co-authored-by: daniel-resdiary <109083091+daniel-resdiary@users.noreply.github.com>
Co-authored-by: Daniel Kerbel <nmdanny@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jan Fajerski <jfajersk@redhat.com>
Co-authored-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
Co-authored-by: Marc Tudurí <marctc@protonmail.com>
Co-authored-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Co-authored-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Co-authored-by: Augustin Husson <husson.augustin@gmail.com>
Co-authored-by: Björn Rabenstein <beorn@grafana.com>
Co-authored-by: zenador <zenador@users.noreply.github.com>
Co-authored-by: gotjosh <josue.abreu@gmail.com>
Co-authored-by: Ben Kochie <superq@gmail.com>
Co-authored-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>
Co-authored-by: tyltr <tylitianrui@126.com>
Co-authored-by: Ted Robertson <10043369+tredondo@users.noreply.github.com>
Co-authored-by: Julien Pivotto <roidelapluie@o11y.eu>
Co-authored-by: Matthias Loibl <mail@matthiasloibl.com>
Co-authored-by: Ivan Babrou <github@ivan.computer>
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
Co-authored-by: Israel Blancas <iblancasa@gmail.com>
Co-authored-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: Goutham <gouthamve@gmail.com>
Co-authored-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
Co-authored-by: Chris Marchbanks <csmarchbanks@gmail.com>
Co-authored-by: Ben Ye <benye@amazon.com>
Co-authored-by: Oleg Zaytsev <mail@olegzaytsev.com>
Co-authored-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Paulin Todev <paulin.todev@gmail.com>
Co-authored-by: Filip Petkovski <filip.petkovsky@gmail.com>
Co-authored-by: Yury Molodov <yurymolodov@gmail.com>
Co-authored-by: Danny Kopping <danny.kopping@grafana.com>
Co-authored-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
Co-authored-by: Guillermo Sanchez Gavier <gsanchez@newrelic.com>
Co-authored-by: Mikhail Fesenko <proggga@gmail.com>
Co-authored-by: Alan Protasio <alanprot@gmail.com>
* remote write 2.0 - follow up improvements (#13478)
* move remote write proto version config from a remote storage config to a
per remote write configuration option
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* rename scrape config for metadata, fix 2.0 header var name/value (was
1.1), and more clean up
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* address review comments, mostly lint fixes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* another lint fix
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* lint imports
Signed-off-by: Callum Styan <callumstyan@gmail.com>
---------
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* go mod tidy
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Added commmentary to RW 2.0 protocol for easier adoption and explicit semantics. (#13502)
* Added commmentary to RW 2.0 protocol for easier adoption and explicit semantics.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Apply suggestions from code review
Co-authored-by: Nico Pazos <32206519+npazosmendez@users.noreply.github.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Co-authored-by: Callum Styan <callumstyan@gmail.com>
Co-authored-by: Nico Pazos <32206519+npazosmendez@users.noreply.github.com>
* prw2.0: Added support for "custom" layouts for native histogram proto (#13558)
* prw2.0: Added support for "custom" layouts for native histogram.
Result of the discussions:
* https://github.com/prometheus/prometheus/issues/13475#issuecomment-1931496924
* https://cloud-native.slack.com/archives/C02KR205UMU/p1707301006347199
Signed-off-by: bwplotka <bwplotka@gmail.com>
* prw2.0: Added support for "custom" layouts for native histogram.
Result of the discussions:
* https://github.com/prometheus/prometheus/issues/13475#issuecomment-1931496924
* https://cloud-native.slack.com/archives/C02KR205UMU/p1707301006347199
Signed-off-by: bwplotka <bwplotka@gmail.com>
# Conflicts:
# prompb/write/v2/types.pb.go
* Update prompb/write/v2/types.proto
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
* Addressed comments, fixed test.
Signed-off-by: bwplotka <bwplotka@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
* first draft of content negotiation
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Lint
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Fix race in test
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Fix another test race
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Almost done with lint
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Fix todos around 405 HEAD handling
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Changes based on review comments
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Update storage/remote/client.go
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Latest updates to review comments
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* latest tweaks
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* remote write 2.0 - content negotiation remediation (#13921)
* Consolidate renegotiation error into one, fix tests
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* fix metric name and actuall increment counter
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
---------
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Fixes after main sync.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* [PRW 2.0] Moved rw2 proto to the full path (both package name and placement) (#13973)
undefined
* [PRW2.0] Remove benchmark scripts (#13949)
See rationales on https://docs.google.com/document/d/1Bpf7mYjrHUhPHkie0qlnZFxzgqf_L32kM8ZOknSdJrU/edit
Signed-off-by: bwplotka <bwplotka@gmail.com>
* rw20: Update prw commentary after Callum spec review (#14136)
* rw20: Update prw commentary after Callum spec review
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
* Update types.proto
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
---------
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
* [PRW 2.0] Updated spec proto (2.0-rc.1); deterministic v1 interop; to be sympathetic with implementation. (#14330)
* [PRW 2.0] Updated spec proto (2.0-rc.1); deterministic v1 interop; to be sympathetic with implementation.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* update custom marshalling
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Removed confusing comments.
Signed-off-by: bwplotka <bwplotka@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
* [PRW-2.0] (chain1) New Remote Write 2.0 Config options for 2.0-rc.1 spec. (#14335)
NOTE: For simple review this change does not touch remote/ packages, only main and configs.
Spec: https://prometheus.io/docs/specs/remote_write_spec_2_0
Supersedes https://github.com/prometheus/prometheus/pull/13968
Signed-off-by: bwplotka <bwplotka@gmail.com>
* [PRW-2.0] (part 2) Removed automatic negotiation, updates for the latest spec semantics in remote pkg (#14329)
* [PRW-2.0] (part2) Moved to latest basic negotiation & spec semantics.
Spec: https://github.com/prometheus/docs/pull/2462
Supersedes https://github.com/prometheus/prometheus/pull/13968
Signed-off-by: bwplotka <bwplotka@gmail.com>
# Conflicts:
# config/config.go
# docs/configuration/configuration.md
# storage/remote/queue_manager_test.go
# storage/remote/write.go
# web/api/v1/api.go
* Addressed comments.
Signed-off-by: bwplotka <bwplotka@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
* lint
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* storage/remote tests: refactor: extract function newTestQueueManager
To reduce repetition.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* use newTestQueueManager for test
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* go mod tidy
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* [PRW 2.0] (part3) moved type specific conversions to prompb and writev2 codecs.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Added test for rwProtoMsgFlagParser; fixed TODO comment.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Renamed DecodeV2WriteRequestStr to DecodeWriteV2Request (with tests).
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Addressed comments on remote_storage example, updated it for 2.0
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Fixed `--enable-feature=metadata-wal-records` docs and error when using PRW 2.0 without it.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Addressed Callum comments on custom*.go
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Added TODO to genproto.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Addressed Callum comments in remote pkg.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Added metadata validation to write handler test; fixed ToMetadata.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Addressed rest of Callum comments.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Fixed writev2.FromMetadataType (was wrongly using prompb).
Signed-off-by: bwplotka <bwplotka@gmail.com>
* fix a few import whitespaces
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* add a default case with an error to the example RW receiver
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* more minor import whitespace chagnes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* Apply suggestions from code review
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
* Update storage/remote/queue_manager_test.go
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
---------
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Erik Sommer <ersotech@posteo.de>
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
Signed-off-by: Daniel Nicholls <daniel.nicholls@resdiary.com>
Signed-off-by: Daniel Kerbel <nmdanny@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Jan Fajerski <jfajersk@redhat.com>
Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
Signed-off-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Signed-off-by: Augustin Husson <augustin.husson@amadeus.com>
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: tyltr <tylitianrui@126.com>
Signed-off-by: Ted Robertson 10043369+tredondo@users.noreply.github.com
Signed-off-by: Ivan Babrou <github@ivan.computer>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Signed-off-by: Goutham <gouthamve@gmail.com>
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
Signed-off-by: Ben Ye <benye@amazon.com>
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Signed-off-by: SuperQ <superq@gmail.com>
Signed-off-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Signed-off-by: beorn7 <beorn@grafana.com>
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
Signed-off-by: Yury Moladau <yurymolodov@gmail.com>
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
Signed-off-by: Mikhail Fesenko <proggga@gmail.com>
Signed-off-by: Jesus Vazquez <jesusvzpg@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
Co-authored-by: Nicolás Pazos <32206519+npazosmendez@users.noreply.github.com>
Co-authored-by: Callum Styan <callumstyan@gmail.com>
Co-authored-by: Nicolás Pazos <npazosmendez@gmail.com>
Co-authored-by: alexgreenbank <alex.greenbank@grafana.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>
Co-authored-by: Paschalis Tsilias <paschalist0@gmail.com>
Co-authored-by: Julian Wiedmann <jwi@linux.ibm.com>
Co-authored-by: Bryan Boreham <bjboreham@gmail.com>
Co-authored-by: Erik Sommer <ersotech@posteo.de>
Co-authored-by: Linas Medziunas <linas.medziunas@gmail.com>
Co-authored-by: Arianna Vespri <arianna.vespri@yahoo.it>
Co-authored-by: machine424 <ayoubmrini424@gmail.com>
Co-authored-by: daniel-resdiary <109083091+daniel-resdiary@users.noreply.github.com>
Co-authored-by: Daniel Kerbel <nmdanny@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jan Fajerski <jfajersk@redhat.com>
Co-authored-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
Co-authored-by: Marc Tudurí <marctc@protonmail.com>
Co-authored-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Co-authored-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Co-authored-by: Augustin Husson <husson.augustin@gmail.com>
Co-authored-by: Björn Rabenstein <beorn@grafana.com>
Co-authored-by: zenador <zenador@users.noreply.github.com>
Co-authored-by: gotjosh <josue.abreu@gmail.com>
Co-authored-by: Ben Kochie <superq@gmail.com>
Co-authored-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com>
Co-authored-by: tyltr <tylitianrui@126.com>
Co-authored-by: Ted Robertson <10043369+tredondo@users.noreply.github.com>
Co-authored-by: Julien Pivotto <roidelapluie@o11y.eu>
Co-authored-by: Matthias Loibl <mail@matthiasloibl.com>
Co-authored-by: Ivan Babrou <github@ivan.computer>
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
Co-authored-by: Israel Blancas <iblancasa@gmail.com>
Co-authored-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: Goutham <gouthamve@gmail.com>
Co-authored-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
Co-authored-by: Chris Marchbanks <csmarchbanks@gmail.com>
Co-authored-by: Ben Ye <benye@amazon.com>
Co-authored-by: Oleg Zaytsev <mail@olegzaytsev.com>
Co-authored-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Paulin Todev <paulin.todev@gmail.com>
Co-authored-by: Filip Petkovski <filip.petkovsky@gmail.com>
Co-authored-by: Yury Molodov <yurymolodov@gmail.com>
Co-authored-by: Danny Kopping <danny.kopping@grafana.com>
Co-authored-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
Co-authored-by: Guillermo Sanchez Gavier <gsanchez@newrelic.com>
Co-authored-by: Mikhail Fesenko <proggga@gmail.com>
Co-authored-by: Alan Protasio <alanprot@gmail.com>
2024-07-04 21:29:20 +00:00
|
|
|
acceptRemoteWriteProtoMsgs []config.RemoteWriteProtoMsg,
|
2023-07-28 10:35:28 +00:00
|
|
|
otlpEnabled bool,
|
2017-10-06 15:20:20 +00:00
|
|
|
) *API {
|
2021-01-30 11:04:48 +00:00
|
|
|
a := &API{
|
2021-03-16 09:47:45 +00:00
|
|
|
QueryEngine: qe,
|
|
|
|
Queryable: q,
|
|
|
|
ExemplarQueryable: eq,
|
2021-01-30 11:04:48 +00:00
|
|
|
|
2022-12-23 10:55:08 +00:00
|
|
|
scrapePoolsRetriever: spsr,
|
2017-01-13 09:20:11 +00:00
|
|
|
targetRetriever: tr,
|
|
|
|
alertmanagerRetriever: ar,
|
2018-09-05 13:50:50 +00:00
|
|
|
|
2021-02-26 16:43:19 +00:00
|
|
|
now: time.Now,
|
|
|
|
config: configFunc,
|
|
|
|
flagsMap: flagsMap,
|
|
|
|
ready: readyFunc,
|
|
|
|
globalURLOptions: globalURLOptions,
|
|
|
|
db: db,
|
|
|
|
dbDir: dbDir,
|
|
|
|
enableAdmin: enableAdmin,
|
|
|
|
rulesRetriever: rr,
|
|
|
|
logger: logger,
|
2023-04-09 07:08:40 +00:00
|
|
|
CORSOrigin: corsOrigin,
|
2021-02-26 16:43:19 +00:00
|
|
|
runtimeInfo: runtimeInfo,
|
|
|
|
buildInfo: buildInfo,
|
|
|
|
gatherer: gatherer,
|
2021-10-29 15:25:05 +00:00
|
|
|
isAgent: isAgent,
|
2024-05-18 14:12:33 +00:00
|
|
|
statsRenderer: DefaultStatsRenderer,
|
2021-02-26 16:43:19 +00:00
|
|
|
|
|
|
|
remoteReadHandler: remote.NewReadHandler(logger, registerer, q, configFunc, remoteReadSampleLimit, remoteReadConcurrencyLimit, remoteReadMaxBytesInFrame),
|
2015-11-11 19:46:57 +00:00
|
|
|
}
|
2021-01-30 11:04:48 +00:00
|
|
|
|
2023-02-27 02:27:09 +00:00
|
|
|
a.InstallCodec(JSONCodec{})
|
2023-01-25 03:30:47 +00:00
|
|
|
|
2022-02-10 14:17:05 +00:00
|
|
|
if statsRenderer != nil {
|
|
|
|
a.statsRenderer = statsRenderer
|
|
|
|
}
|
|
|
|
|
2023-07-28 10:35:28 +00:00
|
|
|
if ap == nil && (rwEnabled || otlpEnabled) {
|
|
|
|
panic("remote write or otlp write enabled, but no appender passed in.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if rwEnabled {
|
[PRW 2.0] Merging `remote-write-2.0` feature branch to main (PRW 2.0 support + metadata in WAL) (#14395)
* Remote Write 1.1: e2e benchmarks (#13102)
* Remote Write e2e benchmarks
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Prometheus ports automatically assigned
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* make dashboard editable + more modular to different job label values
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* Dashboard improvements
* memory stats
* diffs look at counter increases
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* run script: absolute path for config templates
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* grafana dashboard improvements
* show actual values of metrics
* add memory stats and diff
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* dashboard changes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
---------
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Co-authored-by: Callum Styan <callumstyan@gmail.com>
* replace snappy encoding library
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add new proto types
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add decode function for new write request proto
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add lookup table struct that is used to build the symbol table in new
write request format
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Implement code paths for new proto format
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* update example server to include handler for new format
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Add new test client
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* tests and new -> original proto mapping util
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add new proto support on receiver end
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Fix test
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* no-brainer copypaste but more performance write support
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove some comented code
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix mocks and fixture
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add basic reduce remote write handler benchmark
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* refactor out common code between write methods
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix: queue manager to include float histograms in new requests
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add sender-side tests and fix failing ones
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* refactor queue manager code to remove some duplication
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix build
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Improve sender benchmarks and some allocations
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Use github.com/golang/snappy
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* cleanup: remove hardcoded fake url for testing
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Add 1.1 version handling code
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Remove config, update proto
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* gofmt
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix NewWriteClient and change new flags wording
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fields rewording in handler
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remote write handler to checks version header
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix typo in log
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* lint
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Add minmized remote write proto format
Co-authored-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add functions for translating between new proto formats symbol table and
actual prometheus labels
Co-authored-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add functionality for new minimized remote write request format
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix minor things
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Make LabelSymbols a fixed32
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove unused proto type
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* update tests
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix build for stringlabels tag
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Use two uint32 to encode (offset,leng)
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* manually optimize varint marshaling
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Use unsafe []byte->string cast to reuse buffer
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix writeRequestMinimizedFixture
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove all code from previous interning approach
the 'minimized' version is now the only v1.1 version
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* minimally-tested exemplar support for rw 1.1
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* refactor new version flag to make it easier to pick a specific format
instead of having multiple flags, plus add new formats for testing
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* use exp slices for backwards compat. to go 1.20 plus add copyright
header to test file
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix label ranging
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Add bytes slice (instead of slice of 32bit vars) format for testing
Co-authored-by: Nicolás Pazos <npazosmendez@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* test additional len and lenbytes formats
Co-authored-by: Nicolás Pazos <npazosmendez@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove mistaken package lock changes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove formats we've decided not to use
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove more format types we probably won't use
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* More cleanup
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* use require instead of assert in custom marshal test
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* cleanup; remove some unused functions
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* more cleanup, mostly linting fixes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove package-lock.json change again
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* more cleanup, address review comments
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix test panic
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix minor lint issue + use labels Range function since it looks like
the tests fail to do `range labels.Labels` on CI
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* new interning format based on []string indeces
Co-authored-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove all new rw formats but the []string one
also adapt tests to the new format
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* cleanup rwSymbolTable
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* add some TODOs for later
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* don't reserve field 3 for new proto and add TODO
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix custom marshaling
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* lint
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* additional merge fixes
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* lint fixes
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* fix server example
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* revert package-lock.json changes
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* update example prometheus version
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* define separate proto types for remote write 2.0
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* lint
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* rename new proto types and move to separate pkg
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* update prometheus version for example
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* make proto
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* make Metadata not nullable
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* remove old MinSample proto message
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* change enum names to fit buf build recommend enum naming and lint rules
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* remote: Added test for classic histogram grouping when sending rw; Fixed queue manager test delay. (#13421)
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Remote write v2: metadata support in every write request (#13394)
* Approach bundling metadata along with samples and exemplars
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
* Add first test; rebase with main
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
* Alternative approach: bundle metadata in TimeSeries protobuf
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
* update go mod to match main branch
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* fix after rebase
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* we're not going to modify the 1.X format anymore
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* Modify AppendMetadata based on the fact that we be putting metadata into
timeseries
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* Rename enums for remote write versions to something that makes more
sense + remove the added `sendMetadata` flag.
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* rename flag that enables writing of metadata records to the WAL
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* additional clean up
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* lint
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* fix usage of require.Len
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* some clean up from review comments
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* more review fixes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
---------
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Co-authored-by: Paschalis Tsilias <paschalist0@gmail.com>
* remote write 2.0: sync with `main` branch (#13510)
* consoles: exclude iowait and steal from CPU Utilisation
'iowait' and 'steal' indicate specific idle/wait states, which shouldn't
be counted into CPU Utilisation. Also see
https://github.com/prometheus-operator/kube-prometheus/pull/796 and
https://github.com/kubernetes-monitoring/kubernetes-mixin/pull/667.
Per the iostat man page:
%idle
Show the percentage of time that the CPU or CPUs were idle and the
system did not have an outstanding disk I/O request.
%iowait
Show the percentage of time that the CPU or CPUs were idle during
which the system had an outstanding disk I/O request.
%steal
Show the percentage of time spent in involuntary wait by the
virtual CPU or CPUs while the hypervisor was servicing another
virtual processor.
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
* tsdb: shrink txRing with smaller integers
4 billion active transactions ought to be enough for anyone.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* tsdb: create isolation transaction slice on demand
When Prometheus restarts it creates every series read in from the WAL,
but many of those series will be finished, and never receive any more
samples. By defering allocation of the txRing slice to when it is first
needed, we save 32 bytes per stale series.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* add cluster variable to Overview dashboard
Signed-off-by: Erik Sommer <ersotech@posteo.de>
* promql: simplify Native Histogram arithmetics
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
* Cut 2.49.0-rc.0 (#13270)
* Cut 2.49.0-rc.0
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Removed the duplicate.
Signed-off-by: bwplotka <bwplotka@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Add unit protobuf parser
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* Go on adding protobuf parsing for unit
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* ui: create a reproduction for https://github.com/prometheus/prometheus/issues/13292
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
* Get conditional right
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* Get VM Scale Set NIC (#13283)
Calling `*armnetwork.InterfacesClient.Get()` doesn't work for Scale Set
VM NIC, because these use a different Resource ID format.
Use `*armnetwork.InterfacesClient.GetVirtualMachineScaleSetNetworkInterface()`
instead. This needs both the scale set name and the instance ID, so
add an `InstanceID` field to the `virtualMachine` struct. `InstanceID`
is empty for a VM that isn't a ScaleSetVM.
Signed-off-by: Daniel Nicholls <daniel.nicholls@resdiary.com>
* Cut v2.49.0-rc.1
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Delete debugging lines, amend error message for unit
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* Correct order in error message
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* Consider storage.ErrTooOldSample as non-retryable
Signed-off-by: Daniel Kerbel <nmdanny@gmail.com>
* scrape_test.go: Increase scrape interval in TestScrapeLoopCache to reduce potential flakiness
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
* Avoid creating string for suffix, consider counters without _total suffix
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
* build(deps): bump github.com/prometheus/client_golang
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.17.0 to 1.18.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.17.0...v1.18.0)
---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* build(deps): bump actions/setup-node from 3.8.1 to 4.0.1
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3.8.1 to 4.0.1.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d...b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8)
---
updated-dependencies:
- dependency-name: actions/setup-node
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* scripts: sort file list in embed directive
Otherwise the resulting string depends on find, which afaict depends on
the underlying filesystem. A stable file list make it easier to detect
UI changes in downstreams that need to track UI assets.
Signed-off-by: Jan Fajerski <jfajersk@redhat.com>
* Fix DataTableProps['data'] for resultType string
Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
* Fix handling of scalar and string in isHeatmapData
Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
* build(deps): bump github.com/influxdata/influxdb
Bumps [github.com/influxdata/influxdb](https://github.com/influxdata/influxdb) from 1.11.2 to 1.11.4.
- [Release notes](https://github.com/influxdata/influxdb/releases)
- [Commits](https://github.com/influxdata/influxdb/compare/v1.11.2...v1.11.4)
---
updated-dependencies:
- dependency-name: github.com/influxdata/influxdb
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* build(deps): bump github.com/prometheus/prometheus
Bumps [github.com/prometheus/prometheus](https://github.com/prometheus/prometheus) from 0.48.0 to 0.48.1.
- [Release notes](https://github.com/prometheus/prometheus/releases)
- [Changelog](https://github.com/prometheus/prometheus/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/prometheus/compare/v0.48.0...v0.48.1)
---
updated-dependencies:
- dependency-name: github.com/prometheus/prometheus
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* Bump client_golang to v1.18.0 (#13373)
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Drop old inmemory samples (#13002)
* Drop old inmemory samples
Co-authored-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Avoid copying timeseries when the feature is disabled
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Run gofmt
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Clarify docs
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Add more logging info
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Remove loggers
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* optimize function and add tests
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Simplify filter
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* rename var
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Update help info from metrics
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* use metrics to keep track of drop elements during buildWriteRequest
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* rename var in tests
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* pass time.Now as parameter
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Change buildwriterequest during retries
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Revert "Remove loggers"
This reverts commit 54f91dfcae20488944162335ab4ad8be459df1ab.
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* use log level debug for loggers
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
* Fix linter
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Remove noisy debug-level logs; add 'reason' label to drop metrics
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Remove accidentally committed files
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Propagate logger to buildWriteRequest to log dropped data
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Fix docs comment
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Make drop reason more specific
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Remove unnecessary pass of logger
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Use snake_case for reason label
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
* Fix dropped samples metric
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
---------
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
Signed-off-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
Co-authored-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
* fix(discovery): allow requireUpdate util to timeout in discovery/file/file_test.go.
The loop ran indefinitely if the condition isn't met.
Before, each iteration created a new timer channel which was always outpaced by
the other timer channel with smaller duration.
minor detail: There was a memory leak: resources of the ~10 previous timers were
constantly kept. With the fix, we may keep the resources of one timer around for defaultWait
but this isn't worth the changes to make it right.
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
* Merge pull request #13371 from kevinmingtarja/fix-isHeatmapData
ui: fix handling of scalar and string in isHeatmapData
* tsdb/{index,compact}: allow using custom postings encoding format (#13242)
* tsdb/{index,compact}: allow using custom postings encoding format
We would like to experiment with a different postings encoding format in
Thanos so in this change I am proposing adding another argument to
`NewWriter` which would allow users to change the format if needed.
Also, wire the leveled compactor so that it would be possible to change
the format there too.
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* tsdb/compact: use a struct for leveled compactor options
As discussed on Slack, let's use a struct for the options in leveled
compactor.
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* tsdb: make changes after Bryan's review
- Make changes less intrusive
- Turn the postings encoder type into a function
- Add NewWriterWithEncoder()
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
---------
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* Cut 2.49.0-rc.2
Signed-off-by: bwplotka <bwplotka@gmail.com>
* build(deps): bump actions/setup-go from 3.5.0 to 5.0.0 in /scripts (#13362)
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 3.5.0 to 5.0.0.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/6edd4406fa81c3da01a34fa6f6343087c207a568...0c52d547c9bc32b1aa3301fd7a9cb496313a4491)
---
updated-dependencies:
- dependency-name: actions/setup-go
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* build(deps): bump github/codeql-action from 2.22.8 to 3.22.12 (#13358)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.22.8 to 3.22.12.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/407ffafae6a767df3e0230c3df91b6443ae8df75...012739e5082ff0c22ca6d6ab32e07c36df03c4a4)
---
updated-dependencies:
- dependency-name: github/codeql-action
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* put @nexucis has a release shepherd (#13383)
Signed-off-by: Augustin Husson <augustin.husson@amadeus.com>
* Add analyze histograms command to promtool (#12331)
Add `query analyze` command to promtool
This command analyzes the buckets of classic and native histograms,
based on data queried from the Prometheus query API, i.e. it
doesn't require direct access to the TSDB files.
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
---------
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
* included instance in all necessary descriptions
Signed-off-by: Erik Sommer <ersotech@posteo.de>
* tsdb/compact: fix passing merge func
Fixing a very small logical problem I've introduced :(.
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* tsdb: add enable overlapping compaction
This functionality is needed in downstream projects because they have a
separate component that does compaction.
Upstreaming
https://github.com/grafana/mimir-prometheus/blob/7c8e9a2a76fc729e9078889782928b2fdfe240e9/tsdb/compact.go#L323-L325.
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* Cut 2.49.0
Signed-off-by: bwplotka <bwplotka@gmail.com>
* promtool: allow setting multiple matchers to "promtool tsdb dump" command. (#13296)
Conditions are ANDed inside the same matcher but matchers are ORed
Including unit tests for "promtool tsdb dump".
Refactor some matchers scraping utils.
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
* Fixed changelog
Signed-off-by: bwplotka <bwplotka@gmail.com>
* tsdb/main: wire "EnableOverlappingCompaction" to tsdb.Options (#13398)
This added the https://github.com/prometheus/prometheus/pull/13393
"EnableOverlappingCompaction" parameter to the compactor code but not to
the tsdb.Options. I forgot about that. Add it to `tsdb.Options` too and
set it to `true` in Prometheus.
Copy/paste the description from
https://github.com/prometheus/prometheus/pull/13393#issuecomment-1891787986
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* Issue #13268: fix quality value in accept header
Signed-off-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com>
* Cut 2.49.1 with scrape q= bugfix.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Cut 2.49.1 web package.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Restore more efficient version of NewPossibleNonCounterInfo annotation (#13022)
Restore more efficient version of NewPossibleNonCounterInfo annotation
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
---------
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
* Fix regressions introduced by #13242
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* fix slice copy in 1.20 (#13389)
The slices package is added to the standard library in Go 1.21;
we need to import from the exp area to maintain compatibility with Go 1.20.
Signed-off-by: tyltr <tylitianrui@126.com>
* Docs: Query Basics: link to rate (#10538)
Co-authored-by: Julien Pivotto <roidelapluie@o11y.eu>
* chore(kubernetes): check preconditions earlier and avoid unnecessary checks or iterations
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
* Examples: link to `rate` for new users (#10535)
* Examples: link to `rate` for new users
Signed-off-by: Ted Robertson 10043369+tredondo@users.noreply.github.com
Co-authored-by: Bryan Boreham <bjboreham@gmail.com>
* promql: use natural sort in sort_by_label and sort_by_label_desc (#13411)
These functions are intended for humans, as robots can already sort the results
however they please. Humans like things sorted "naturally":
* https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/
A similar thing has been done to Grafana, which is also used by humans:
* https://github.com/grafana/grafana/pull/78024
* https://github.com/grafana/grafana/pull/78494
Signed-off-by: Ivan Babrou <github@ivan.computer>
* TestLabelValuesWithMatchers: Add test case
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* remove obsolete build tag
Signed-off-by: tyltr <tylitianrui@126.com>
* Upgrade some golang dependencies for resty 2.11
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
* Native Histograms: support `native_histogram_min_bucket_factor` in scrape_config (#13222)
Native Histograms: support native_histogram_min_bucket_factor in scrape_config
---------
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
* Add warnings for histogramRate applied with isCounter not matching counter/gauge histogram (#13392)
Add warnings for histogramRate applied with isCounter not matching counter/gauge histogram
---------
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
* Minor fixes to otlp vendor update script
Signed-off-by: Goutham <gouthamve@gmail.com>
* build(deps): bump github.com/hetznercloud/hcloud-go/v2
Bumps [github.com/hetznercloud/hcloud-go/v2](https://github.com/hetznercloud/hcloud-go) from 2.4.0 to 2.6.0.
- [Release notes](https://github.com/hetznercloud/hcloud-go/releases)
- [Changelog](https://github.com/hetznercloud/hcloud-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hetznercloud/hcloud-go/compare/v2.4.0...v2.6.0)
---
updated-dependencies:
- dependency-name: github.com/hetznercloud/hcloud-go/v2
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Enhanced visibility for `promtool test rules` with JSON colored formatting (#13342)
* Added diff flag for unit test to improvise readability & debugging
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Removed blank spaces
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Fixed linting error
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Added cli flags to documentation
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Revert unrrelated linting fixes
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Fixed review suggestions
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Cleanup
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Updated flag description
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* Updated flag description
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
---------
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
* storage: skip merging when no remote storage configured
Prometheus is hard-coded to use a fanout storage between TSDB and
a remote storage which by default is empty.
This change detects the empty storage and skips merging between
result sets, which would make `Select()` sort results.
Bottom line: we skip a sort unless there really is some remote storage
configured.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* Remove csmarchbanks from remote write owners (#13432)
I have not had the time to keep up with remote write and have no plans
to work on it in the near future so I am withdrawing my maintainership
of that part of the codebase. I continue to focus on client_python.
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
* add more context cancellation check at evaluation time
Signed-off-by: Ben Ye <benye@amazon.com>
* Optimize label values with matchers by taking shortcuts (#13426)
Don't calculate postings beforehand: we may not need them. If all
matchers are for the requested label, we can just filter its values.
Also, if there are no values at all, no need to run any kind of
logic.
Also add more labelValuesWithMatchers benchmarks
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
* Add automatic memory limit handling
Enable automatic detection of memory limits and configure GOMEMLIMIT to
match.
* Also includes a flag to allow controlling the reserved ratio.
Signed-off-by: SuperQ <superq@gmail.com>
* Update OSSF badge link (#13433)
Provide a more user friendly interface
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
* SD Managers taking over responsibility for registration of debug metrics (#13375)
SD Managers take over responsibility for SD metrics registration
---------
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
* Optimize histogram iterators (#13340)
Optimize histogram iterators
Histogram iterators allocate new objects in the AtHistogram and
AtFloatHistogram methods, which makes calculating rates over long
ranges expensive.
In #13215 we allowed an existing object to be reused
when converting an integer histogram to a float histogram. This commit follows
the same idea and allows injecting an existing object in the AtHistogram and
AtFloatHistogram methods. When the injected value is nil, iterators allocate
new histograms, otherwise they populate and return the injected object.
The commit also adds a CopyTo method to Histogram and FloatHistogram which
is used in the BufferedIterator to overwrite items in the ring instead of making
new copies.
Note that a specialized HPoint pool is needed for all of this to work
(`matrixSelectorHPool`).
---------
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
* doc: Mark `mad_over_time` as experimental (#13440)
We forgot to do that in
https://github.com/prometheus/prometheus/pull/13059
Signed-off-by: beorn7 <beorn@grafana.com>
* Change metric label for Puppetdb from 'http' to 'puppetdb'
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
* mirror metrics.proto change & generate code
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
* TestHeadLabelValuesWithMatchers: Add test case (#13414)
Add test case to TestHeadLabelValuesWithMatchers, while fixing a couple
of typos in other test cases. Also enclosing some implicit sub-tests in a
`t.Run` call to make them explicitly sub-tests.
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* update all go dependencies (#13438)
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
* build(deps): bump the k8s-io group with 2 updates (#13454)
Bumps the k8s-io group with 2 updates: [k8s.io/api](https://github.com/kubernetes/api) and [k8s.io/client-go](https://github.com/kubernetes/client-go).
Updates `k8s.io/api` from 0.28.4 to 0.29.1
- [Commits](https://github.com/kubernetes/api/compare/v0.28.4...v0.29.1)
Updates `k8s.io/client-go` from 0.28.4 to 0.29.1
- [Changelog](https://github.com/kubernetes/client-go/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kubernetes/client-go/compare/v0.28.4...v0.29.1)
---
updated-dependencies:
- dependency-name: k8s.io/api
dependency-type: direct:production
update-type: version-update:semver-minor
dependency-group: k8s-io
- dependency-name: k8s.io/client-go
dependency-type: direct:production
update-type: version-update:semver-minor
dependency-group: k8s-io
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* build(deps): bump the go-opentelemetry-io group with 1 update (#13453)
Bumps the go-opentelemetry-io group with 1 update: [go.opentelemetry.io/collector/semconv](https://github.com/open-telemetry/opentelemetry-collector).
Updates `go.opentelemetry.io/collector/semconv` from 0.92.0 to 0.93.0
- [Release notes](https://github.com/open-telemetry/opentelemetry-collector/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-collector/blob/main/CHANGELOG-API.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-collector/compare/v0.92.0...v0.93.0)
---
updated-dependencies:
- dependency-name: go.opentelemetry.io/collector/semconv
dependency-type: direct:production
update-type: version-update:semver-minor
dependency-group: go-opentelemetry-io
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* build(deps): bump actions/upload-artifact from 3.1.3 to 4.0.0 (#13355)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3.1.3 to 4.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/a8a3f3ad30e3422c9c7b888a15615d19a852ae32...c7d193f32edcb7bfad88892161225aeda64e9392)
---
updated-dependencies:
- dependency-name: actions/upload-artifact
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* build(deps): bump bufbuild/buf-push-action (#13357)
Bumps [bufbuild/buf-push-action](https://github.com/bufbuild/buf-push-action) from 342fc4cdcf29115a01cf12a2c6dd6aac68dc51e1 to a654ff18effe4641ebea4a4ce242c49800728459.
- [Release notes](https://github.com/bufbuild/buf-push-action/releases)
- [Commits](https://github.com/bufbuild/buf-push-action/compare/342fc4cdcf29115a01cf12a2c6dd6aac68dc51e1...a654ff18effe4641ebea4a4ce242c49800728459)
---
updated-dependencies:
- dependency-name: bufbuild/buf-push-action
dependency-type: direct:production
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Labels: Add DropMetricName function, used in PromQL (#13446)
This function is called very frequently when executing PromQL functions,
and we can do it much more efficiently inside Labels.
In the common case that `__name__` comes first in the labels, we simply
re-point to start at the next label, which is nearly free.
`DropMetricName` is now so cheap I removed the cache - benchmarks show
everything still goes faster.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* tsdb: simplify internal series delete function (#13261)
Lifting an optimisation from Agent code, `seriesHashmap.del` can use
the unique series reference, doesn't need to check Labels.
Also streamline the logic for deleting from `unique` and `conflicts` maps,
and add some comments to help the next person.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* otlptranslator/update-copy.sh: Fix sed command lines
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Rollback k8s.io requirements (#13462)
Rollback k8s.io Go modules to v0.28.6 to avoid forcing upgrade of Go to
1.21. This allows us to keep compatibility with the currently supported
upstream Go releases.
Signed-off-by: SuperQ <superq@gmail.com>
* Make update-copy.sh work for both OSX and GNU sed
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Name @beorn7 and @krajorama as maintainers for native histograms
I have been the de-facto maintainer for native histograms from the
beginning. So let's put this into MAINTAINERS.md.
In addition, I hereby proposose George Krajcsovits AKA Krajo as a
co-maintainer. He has contributed a lot of native histogram code, but
more importantly, he has contributed substantially to reviewing other
contributors' native histogram code, up to a point where I was merely
rubberstamping the PRs he had already reviewed. I'm confident that he
is ready to to be granted commit rights as outlined in the
"Maintainers" section of the governance:
https://prometheus.io/governance/#maintainers
According to the same section of the governance, I will announce the
proposed change on the developers mailing list and will give some time
for lazy consensus before merging this PR.
Signed-off-by: beorn7 <beorn@grafana.com>
* ui/fix: correct url handling for stacked graphs (#13460)
Signed-off-by: Yury Moladau <yurymolodov@gmail.com>
* tsdb: use cheaper Mutex on series
Mutex is 8 bytes; RWMutex is 24 bytes and much more complicated. Since
`RLock` is only used in two places, `UpdateMetadata` and `Delete`,
neither of which are hotspots, we should use the cheaper one.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* Fix last_over_time for native histograms
The last_over_time retains a histogram sample without making a copy.
This sample is now coming from the buffered iterator used for windowing functions,
and can be reused for reading subsequent samples as the iterator progresses.
I would propose copying the sample in the last_over_time function, similar to
how it is done for rate, sum_over_time and others.
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
* Implementation
NOTE:
Rebased from main after refactor in #13014
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Add feature flag
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Refactor concurrency control
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Optimising dependencies/dependents funcs to not produce new slices each request
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Refactoring
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Rename flag
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Refactoring for performance, and to allow controller to be overridden
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Block until all rules, both sync & async, have completed evaluating
Updated & added tests
Review feedback nits
Return empty map if not indeterminate
Use highWatermark to track inflight requests counter
Appease the linter
Clarify feature flag
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
* Fix typo in CLI flag description
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Fixed auto-generated doc
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Improve doc
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Simplify the design to update concurrency controller once the rule evaluation has done
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Add more test cases to TestDependenciesEdgeCases
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Added more test cases to TestDependenciesEdgeCases
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Improved RuleConcurrencyController interface doc
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Introduced sequentialRuleEvalController
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* Remove superfluous nil check in Group.metrics
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* api: Serialize discovered and target labels into JSON directly (#13469)
Converted maps into labels.Labels to avoid a lot of copying of data which leads to very high memory consumption while opening the /service-discovery endpoint in the Prometheus UI
Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
* api: Serialize discovered labels into JSON directly in dropped targets (#13484)
Converted maps into labels.Labels to avoid a lot of copying of data which leads to very high memory consumption while opening the /service-discovery endpoint in the Prometheus UI
Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
* Add ShardedPostings() support to TSDB (#10421)
This PR is a reference implementation of the proposal described in #10420.
In addition to what described in #10420, in this PR I've introduced labels.StableHash(). The idea is to offer an hashing function which doesn't change over time, and that's used by query sharding in order to get a stable behaviour over time. The implementation of labels.StableHash() is the hashing function used by Prometheus before stringlabels, and what's used by Grafana Mimir for query sharding (because built before stringlabels was a thing).
Follow up work
As mentioned in #10420, if this PR is accepted I'm also open to upload another foundamental piece used by Grafana Mimir query sharding to accelerate the query execution: an optional, configurable and fast in-memory cache for the series hashes.
Signed-off-by: Marco Pracucci <marco@pracucci.com>
* storage/remote: document why two benchmarks are skipped
One was silently doing nothing; one was doing something but the work
didn't go up linearly with iteration count.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* Pod status changes not discovered by Kube Endpoints SD (#13337)
* fix(discovery/kubernetes/endpoints): react to changes on Pods because some modifications can occur on them without triggering an update on the related Endpoints (The Pod phase changing from Pending to Running e.g.).
---------
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
Co-authored-by: Guillermo Sanchez Gavier <gsanchez@newrelic.com>
* Small improvements, add const, remove copypasta (#8106)
Signed-off-by: Mikhail Fesenko <proggga@gmail.com>
Signed-off-by: Jesus Vazquez <jesusvzpg@gmail.com>
* Proposal to improve FPointSlice and HPointSlice allocation. (#13448)
* Reusing points slice from previous series when the slice is under utilized
* Adding comments on the bench test
Signed-off-by: Alan Protasio <alanprot@gmail.com>
* lint
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* go mod tidy
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
---------
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Erik Sommer <ersotech@posteo.de>
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
Signed-off-by: Daniel Nicholls <daniel.nicholls@resdiary.com>
Signed-off-by: Daniel Kerbel <nmdanny@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Jan Fajerski <jfajersk@redhat.com>
Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
Signed-off-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Signed-off-by: Augustin Husson <augustin.husson@amadeus.com>
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: tyltr <tylitianrui@126.com>
Signed-off-by: Ted Robertson 10043369+tredondo@users.noreply.github.com
Signed-off-by: Ivan Babrou <github@ivan.computer>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Signed-off-by: Goutham <gouthamve@gmail.com>
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
Signed-off-by: Ben Ye <benye@amazon.com>
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Signed-off-by: SuperQ <superq@gmail.com>
Signed-off-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Signed-off-by: beorn7 <beorn@grafana.com>
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
Signed-off-by: Yury Moladau <yurymolodov@gmail.com>
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
Signed-off-by: Mikhail Fesenko <proggga@gmail.com>
Signed-off-by: Jesus Vazquez <jesusvzpg@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
Co-authored-by: Julian Wiedmann <jwi@linux.ibm.com>
Co-authored-by: Bryan Boreham <bjboreham@gmail.com>
Co-authored-by: Erik Sommer <ersotech@posteo.de>
Co-authored-by: Linas Medziunas <linas.medziunas@gmail.com>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Co-authored-by: Arianna Vespri <arianna.vespri@yahoo.it>
Co-authored-by: machine424 <ayoubmrini424@gmail.com>
Co-authored-by: daniel-resdiary <109083091+daniel-resdiary@users.noreply.github.com>
Co-authored-by: Daniel Kerbel <nmdanny@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jan Fajerski <jfajersk@redhat.com>
Co-authored-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
Co-authored-by: Marc Tudurí <marctc@protonmail.com>
Co-authored-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Co-authored-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Co-authored-by: Augustin Husson <husson.augustin@gmail.com>
Co-authored-by: Björn Rabenstein <beorn@grafana.com>
Co-authored-by: zenador <zenador@users.noreply.github.com>
Co-authored-by: gotjosh <josue.abreu@gmail.com>
Co-authored-by: Ben Kochie <superq@gmail.com>
Co-authored-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>
Co-authored-by: tyltr <tylitianrui@126.com>
Co-authored-by: Ted Robertson <10043369+tredondo@users.noreply.github.com>
Co-authored-by: Julien Pivotto <roidelapluie@o11y.eu>
Co-authored-by: Matthias Loibl <mail@matthiasloibl.com>
Co-authored-by: Ivan Babrou <github@ivan.computer>
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
Co-authored-by: Israel Blancas <iblancasa@gmail.com>
Co-authored-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: Goutham <gouthamve@gmail.com>
Co-authored-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
Co-authored-by: Chris Marchbanks <csmarchbanks@gmail.com>
Co-authored-by: Ben Ye <benye@amazon.com>
Co-authored-by: Oleg Zaytsev <mail@olegzaytsev.com>
Co-authored-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Paulin Todev <paulin.todev@gmail.com>
Co-authored-by: Filip Petkovski <filip.petkovsky@gmail.com>
Co-authored-by: Yury Molodov <yurymolodov@gmail.com>
Co-authored-by: Danny Kopping <danny.kopping@grafana.com>
Co-authored-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
Co-authored-by: Guillermo Sanchez Gavier <gsanchez@newrelic.com>
Co-authored-by: Mikhail Fesenko <proggga@gmail.com>
Co-authored-by: Alan Protasio <alanprot@gmail.com>
* remote write 2.0 - follow up improvements (#13478)
* move remote write proto version config from a remote storage config to a
per remote write configuration option
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* rename scrape config for metadata, fix 2.0 header var name/value (was
1.1), and more clean up
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* address review comments, mostly lint fixes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* another lint fix
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* lint imports
Signed-off-by: Callum Styan <callumstyan@gmail.com>
---------
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* go mod tidy
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* Added commmentary to RW 2.0 protocol for easier adoption and explicit semantics. (#13502)
* Added commmentary to RW 2.0 protocol for easier adoption and explicit semantics.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Apply suggestions from code review
Co-authored-by: Nico Pazos <32206519+npazosmendez@users.noreply.github.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Co-authored-by: Callum Styan <callumstyan@gmail.com>
Co-authored-by: Nico Pazos <32206519+npazosmendez@users.noreply.github.com>
* prw2.0: Added support for "custom" layouts for native histogram proto (#13558)
* prw2.0: Added support for "custom" layouts for native histogram.
Result of the discussions:
* https://github.com/prometheus/prometheus/issues/13475#issuecomment-1931496924
* https://cloud-native.slack.com/archives/C02KR205UMU/p1707301006347199
Signed-off-by: bwplotka <bwplotka@gmail.com>
* prw2.0: Added support for "custom" layouts for native histogram.
Result of the discussions:
* https://github.com/prometheus/prometheus/issues/13475#issuecomment-1931496924
* https://cloud-native.slack.com/archives/C02KR205UMU/p1707301006347199
Signed-off-by: bwplotka <bwplotka@gmail.com>
# Conflicts:
# prompb/write/v2/types.pb.go
* Update prompb/write/v2/types.proto
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
* Addressed comments, fixed test.
Signed-off-by: bwplotka <bwplotka@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
* first draft of content negotiation
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Lint
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Fix race in test
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Fix another test race
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Almost done with lint
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Fix todos around 405 HEAD handling
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Changes based on review comments
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Update storage/remote/client.go
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Latest updates to review comments
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* latest tweaks
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* remote write 2.0 - content negotiation remediation (#13921)
* Consolidate renegotiation error into one, fix tests
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* fix metric name and actuall increment counter
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
---------
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
* Fixes after main sync.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* [PRW 2.0] Moved rw2 proto to the full path (both package name and placement) (#13973)
undefined
* [PRW2.0] Remove benchmark scripts (#13949)
See rationales on https://docs.google.com/document/d/1Bpf7mYjrHUhPHkie0qlnZFxzgqf_L32kM8ZOknSdJrU/edit
Signed-off-by: bwplotka <bwplotka@gmail.com>
* rw20: Update prw commentary after Callum spec review (#14136)
* rw20: Update prw commentary after Callum spec review
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
* Update types.proto
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
---------
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
* [PRW 2.0] Updated spec proto (2.0-rc.1); deterministic v1 interop; to be sympathetic with implementation. (#14330)
* [PRW 2.0] Updated spec proto (2.0-rc.1); deterministic v1 interop; to be sympathetic with implementation.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* update custom marshalling
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Removed confusing comments.
Signed-off-by: bwplotka <bwplotka@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
* [PRW-2.0] (chain1) New Remote Write 2.0 Config options for 2.0-rc.1 spec. (#14335)
NOTE: For simple review this change does not touch remote/ packages, only main and configs.
Spec: https://prometheus.io/docs/specs/remote_write_spec_2_0
Supersedes https://github.com/prometheus/prometheus/pull/13968
Signed-off-by: bwplotka <bwplotka@gmail.com>
* [PRW-2.0] (part 2) Removed automatic negotiation, updates for the latest spec semantics in remote pkg (#14329)
* [PRW-2.0] (part2) Moved to latest basic negotiation & spec semantics.
Spec: https://github.com/prometheus/docs/pull/2462
Supersedes https://github.com/prometheus/prometheus/pull/13968
Signed-off-by: bwplotka <bwplotka@gmail.com>
# Conflicts:
# config/config.go
# docs/configuration/configuration.md
# storage/remote/queue_manager_test.go
# storage/remote/write.go
# web/api/v1/api.go
* Addressed comments.
Signed-off-by: bwplotka <bwplotka@gmail.com>
---------
Signed-off-by: bwplotka <bwplotka@gmail.com>
* lint
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* storage/remote tests: refactor: extract function newTestQueueManager
To reduce repetition.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* use newTestQueueManager for test
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* go mod tidy
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
* [PRW 2.0] (part3) moved type specific conversions to prompb and writev2 codecs.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Added test for rwProtoMsgFlagParser; fixed TODO comment.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Renamed DecodeV2WriteRequestStr to DecodeWriteV2Request (with tests).
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Addressed comments on remote_storage example, updated it for 2.0
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Fixed `--enable-feature=metadata-wal-records` docs and error when using PRW 2.0 without it.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Addressed Callum comments on custom*.go
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Added TODO to genproto.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Addressed Callum comments in remote pkg.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Added metadata validation to write handler test; fixed ToMetadata.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Addressed rest of Callum comments.
Signed-off-by: bwplotka <bwplotka@gmail.com>
* Fixed writev2.FromMetadataType (was wrongly using prompb).
Signed-off-by: bwplotka <bwplotka@gmail.com>
* fix a few import whitespaces
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* add a default case with an error to the example RW receiver
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* more minor import whitespace chagnes
Signed-off-by: Callum Styan <callumstyan@gmail.com>
* Apply suggestions from code review
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
* Update storage/remote/queue_manager_test.go
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
---------
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Erik Sommer <ersotech@posteo.de>
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
Signed-off-by: Daniel Nicholls <daniel.nicholls@resdiary.com>
Signed-off-by: Daniel Kerbel <nmdanny@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Jan Fajerski <jfajersk@redhat.com>
Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Signed-off-by: Marc Tuduri <marctc@protonmail.com>
Signed-off-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Signed-off-by: Augustin Husson <augustin.husson@amadeus.com>
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: tyltr <tylitianrui@126.com>
Signed-off-by: Ted Robertson 10043369+tredondo@users.noreply.github.com
Signed-off-by: Ivan Babrou <github@ivan.computer>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Signed-off-by: Goutham <gouthamve@gmail.com>
Signed-off-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
Signed-off-by: Ben Ye <benye@amazon.com>
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Signed-off-by: SuperQ <superq@gmail.com>
Signed-off-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Signed-off-by: Paulin Todev <paulin.todev@gmail.com>
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Signed-off-by: beorn7 <beorn@grafana.com>
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
Signed-off-by: Yury Moladau <yurymolodov@gmail.com>
Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
Signed-off-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
Signed-off-by: Mikhail Fesenko <proggga@gmail.com>
Signed-off-by: Jesus Vazquez <jesusvzpg@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alex Greenbank <alex.greenbank@grafana.com>
Co-authored-by: Nicolás Pazos <32206519+npazosmendez@users.noreply.github.com>
Co-authored-by: Callum Styan <callumstyan@gmail.com>
Co-authored-by: Nicolás Pazos <npazosmendez@gmail.com>
Co-authored-by: alexgreenbank <alex.greenbank@grafana.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>
Co-authored-by: Paschalis Tsilias <paschalist0@gmail.com>
Co-authored-by: Julian Wiedmann <jwi@linux.ibm.com>
Co-authored-by: Bryan Boreham <bjboreham@gmail.com>
Co-authored-by: Erik Sommer <ersotech@posteo.de>
Co-authored-by: Linas Medziunas <linas.medziunas@gmail.com>
Co-authored-by: Arianna Vespri <arianna.vespri@yahoo.it>
Co-authored-by: machine424 <ayoubmrini424@gmail.com>
Co-authored-by: daniel-resdiary <109083091+daniel-resdiary@users.noreply.github.com>
Co-authored-by: Daniel Kerbel <nmdanny@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jan Fajerski <jfajersk@redhat.com>
Co-authored-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
Co-authored-by: Marc Tudurí <marctc@protonmail.com>
Co-authored-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Co-authored-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Co-authored-by: Augustin Husson <husson.augustin@gmail.com>
Co-authored-by: Björn Rabenstein <beorn@grafana.com>
Co-authored-by: zenador <zenador@users.noreply.github.com>
Co-authored-by: gotjosh <josue.abreu@gmail.com>
Co-authored-by: Ben Kochie <superq@gmail.com>
Co-authored-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com>
Co-authored-by: tyltr <tylitianrui@126.com>
Co-authored-by: Ted Robertson <10043369+tredondo@users.noreply.github.com>
Co-authored-by: Julien Pivotto <roidelapluie@o11y.eu>
Co-authored-by: Matthias Loibl <mail@matthiasloibl.com>
Co-authored-by: Ivan Babrou <github@ivan.computer>
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
Co-authored-by: Israel Blancas <iblancasa@gmail.com>
Co-authored-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: Goutham <gouthamve@gmail.com>
Co-authored-by: Rewanth Tammana <22347290+rewanthtammana@users.noreply.github.com>
Co-authored-by: Chris Marchbanks <csmarchbanks@gmail.com>
Co-authored-by: Ben Ye <benye@amazon.com>
Co-authored-by: Oleg Zaytsev <mail@olegzaytsev.com>
Co-authored-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Paulin Todev <paulin.todev@gmail.com>
Co-authored-by: Filip Petkovski <filip.petkovsky@gmail.com>
Co-authored-by: Yury Molodov <yurymolodov@gmail.com>
Co-authored-by: Danny Kopping <danny.kopping@grafana.com>
Co-authored-by: Leegin <114397475+Leegin-darknight@users.noreply.github.com>
Co-authored-by: Guillermo Sanchez Gavier <gsanchez@newrelic.com>
Co-authored-by: Mikhail Fesenko <proggga@gmail.com>
Co-authored-by: Alan Protasio <alanprot@gmail.com>
2024-07-04 21:29:20 +00:00
|
|
|
a.remoteWriteHandler = remote.NewWriteHandler(logger, registerer, ap, acceptRemoteWriteProtoMsgs)
|
2021-01-30 11:04:48 +00:00
|
|
|
}
|
2023-07-28 10:35:28 +00:00
|
|
|
if otlpEnabled {
|
|
|
|
a.otlpWriteHandler = remote.NewOTLPWriteHandler(logger, ap)
|
|
|
|
}
|
2021-01-30 11:04:48 +00:00
|
|
|
|
|
|
|
return a
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 03:30:47 +00:00
|
|
|
// InstallCodec adds codec to this API's available codecs.
|
2023-02-27 02:27:09 +00:00
|
|
|
// Codecs installed first take precedence over codecs installed later when evaluating wildcards in Accept headers.
|
|
|
|
// The first installed codec is used as a fallback when the Accept header cannot be satisfied or if there is no Accept header.
|
2023-01-25 03:30:47 +00:00
|
|
|
func (api *API) InstallCodec(codec Codec) {
|
2023-02-27 02:27:09 +00:00
|
|
|
api.codecs = append(api.codecs, codec)
|
|
|
|
}
|
2023-01-25 03:30:47 +00:00
|
|
|
|
2023-02-27 02:27:09 +00:00
|
|
|
// ClearCodecs removes all available codecs from this API, including the default codec installed by NewAPI.
|
|
|
|
func (api *API) ClearCodecs() {
|
|
|
|
api.codecs = nil
|
2023-01-25 03:30:47 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 16:16:14 +00:00
|
|
|
func setUnavailStatusOnTSDBNotReady(r apiFuncResult) apiFuncResult {
|
2023-11-08 03:49:39 +00:00
|
|
|
if r.err != nil && errors.Is(r.err.err, tsdb.ErrNotReady) {
|
2020-04-29 16:16:14 +00:00
|
|
|
r.err.typ = errorUnavailable
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2015-06-04 16:07:57 +00:00
|
|
|
// Register the API's endpoints in the given router.
|
|
|
|
func (api *API) Register(r *route.Router) {
|
2018-03-21 08:16:16 +00:00
|
|
|
wrap := func(f apiFunc) http.HandlerFunc {
|
2015-09-17 12:49:50 +00:00
|
|
|
hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2019-01-17 15:01:06 +00:00
|
|
|
httputil.SetCORS(w, api.CORSOrigin, r)
|
2020-04-29 16:16:14 +00:00
|
|
|
result := setUnavailStatusOnTSDBNotReady(f(r))
|
2020-04-16 18:16:16 +00:00
|
|
|
if result.finalizer != nil {
|
|
|
|
defer result.finalizer()
|
|
|
|
}
|
2018-11-30 14:27:12 +00:00
|
|
|
if result.err != nil {
|
|
|
|
api.respondError(w, result.err, result.data)
|
2020-04-29 16:16:14 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.data != nil {
|
2023-09-14 16:57:31 +00:00
|
|
|
api.respond(w, r, result.data, result.warnings, r.FormValue("query"))
|
2020-04-29 16:16:14 +00:00
|
|
|
return
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
2020-04-29 16:16:14 +00:00
|
|
|
w.WriteHeader(http.StatusNoContent)
|
2015-06-04 16:07:57 +00:00
|
|
|
})
|
2018-03-21 08:16:16 +00:00
|
|
|
return api.ready(httputil.CompressionHandler{
|
2015-09-18 14:51:53 +00:00
|
|
|
Handler: hf,
|
2018-03-21 08:16:16 +00:00
|
|
|
}.ServeHTTP)
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 15:25:05 +00:00
|
|
|
wrapAgent := func(f apiFunc) http.HandlerFunc {
|
|
|
|
return wrap(func(r *http.Request) apiFuncResult {
|
|
|
|
if api.isAgent {
|
|
|
|
return apiFuncResult{nil, &apiError{errorExec, errors.New("unavailable with Prometheus Agent")}, nil, nil}
|
|
|
|
}
|
|
|
|
return f(r)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-21 08:16:16 +00:00
|
|
|
r.Options("/*path", wrap(api.options))
|
2016-01-26 00:32:46 +00:00
|
|
|
|
2021-10-29 15:25:05 +00:00
|
|
|
r.Get("/query", wrapAgent(api.query))
|
|
|
|
r.Post("/query", wrapAgent(api.query))
|
|
|
|
r.Get("/query_range", wrapAgent(api.queryRange))
|
|
|
|
r.Post("/query_range", wrapAgent(api.queryRange))
|
|
|
|
r.Get("/query_exemplars", wrapAgent(api.queryExemplars))
|
|
|
|
r.Post("/query_exemplars", wrapAgent(api.queryExemplars))
|
2015-06-04 16:07:57 +00:00
|
|
|
|
2022-07-20 12:55:09 +00:00
|
|
|
r.Get("/format_query", wrapAgent(api.formatQuery))
|
|
|
|
r.Post("/format_query", wrapAgent(api.formatQuery))
|
|
|
|
|
2021-10-29 15:25:05 +00:00
|
|
|
r.Get("/labels", wrapAgent(api.labelNames))
|
|
|
|
r.Post("/labels", wrapAgent(api.labelNames))
|
|
|
|
r.Get("/label/:name/values", wrapAgent(api.labelValues))
|
2015-06-09 14:09:31 +00:00
|
|
|
|
2021-10-29 15:25:05 +00:00
|
|
|
r.Get("/series", wrapAgent(api.series))
|
|
|
|
r.Post("/series", wrapAgent(api.series))
|
|
|
|
r.Del("/series", wrapAgent(api.dropSeries))
|
2016-12-02 12:31:43 +00:00
|
|
|
|
2022-12-23 10:55:08 +00:00
|
|
|
r.Get("/scrape_pools", wrap(api.scrapePools))
|
2018-03-21 08:16:16 +00:00
|
|
|
r.Get("/targets", wrap(api.targets))
|
2018-05-18 07:32:11 +00:00
|
|
|
r.Get("/targets/metadata", wrap(api.targetMetadata))
|
2021-10-29 15:25:05 +00:00
|
|
|
r.Get("/alertmanagers", wrapAgent(api.alertmanagers))
|
2017-05-11 15:09:24 +00:00
|
|
|
|
2019-12-10 14:56:16 +00:00
|
|
|
r.Get("/metadata", wrap(api.metricMetadata))
|
|
|
|
|
2018-03-21 08:16:16 +00:00
|
|
|
r.Get("/status/config", wrap(api.serveConfig))
|
2019-11-02 15:53:32 +00:00
|
|
|
r.Get("/status/runtimeinfo", wrap(api.serveRuntimeInfo))
|
|
|
|
r.Get("/status/buildinfo", wrap(api.serveBuildInfo))
|
2018-03-21 08:16:16 +00:00
|
|
|
r.Get("/status/flags", wrap(api.serveFlags))
|
2021-10-29 15:25:05 +00:00
|
|
|
r.Get("/status/tsdb", wrapAgent(api.serveTSDBStatus))
|
2021-06-05 14:29:32 +00:00
|
|
|
r.Get("/status/walreplay", api.serveWALReplayStatus)
|
2021-10-15 22:41:53 +00:00
|
|
|
r.Post("/read", api.ready(api.remoteRead))
|
|
|
|
r.Post("/write", api.ready(api.remoteWrite))
|
2023-07-28 10:35:28 +00:00
|
|
|
r.Post("/otlp/v1/metrics", api.ready(api.otlpWrite))
|
2017-12-03 05:07:05 +00:00
|
|
|
|
2021-10-29 15:25:05 +00:00
|
|
|
r.Get("/alerts", wrapAgent(api.alerts))
|
|
|
|
r.Get("/rules", wrapAgent(api.rules))
|
2018-03-25 16:50:34 +00:00
|
|
|
|
2017-12-03 05:07:05 +00:00
|
|
|
// Admin APIs
|
2021-10-29 15:25:05 +00:00
|
|
|
r.Post("/admin/tsdb/delete_series", wrapAgent(api.deleteSeries))
|
|
|
|
r.Post("/admin/tsdb/clean_tombstones", wrapAgent(api.cleanTombstones))
|
|
|
|
r.Post("/admin/tsdb/snapshot", wrapAgent(api.snapshot))
|
2019-03-20 17:33:45 +00:00
|
|
|
|
2021-10-29 15:25:05 +00:00
|
|
|
r.Put("/admin/tsdb/delete_series", wrapAgent(api.deleteSeries))
|
|
|
|
r.Put("/admin/tsdb/clean_tombstones", wrapAgent(api.cleanTombstones))
|
|
|
|
r.Put("/admin/tsdb/snapshot", wrapAgent(api.snapshot))
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2023-02-02 04:29:13 +00:00
|
|
|
type QueryData struct {
|
2022-02-10 14:17:05 +00:00
|
|
|
ResultType parser.ValueType `json:"resultType"`
|
|
|
|
Result parser.Value `json:"result"`
|
|
|
|
Stats stats.QueryStats `json:"stats,omitempty"`
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 00:27:13 +00:00
|
|
|
func invalidParamError(err error, parameter string) apiFuncResult {
|
|
|
|
return apiFuncResult{nil, &apiError{
|
2023-11-08 03:49:39 +00:00
|
|
|
errorBadData, fmt.Errorf("invalid parameter %q: %w", parameter, err),
|
2020-12-24 00:27:13 +00:00
|
|
|
}, nil, nil}
|
|
|
|
}
|
|
|
|
|
2023-04-12 11:05:41 +00:00
|
|
|
func (api *API) options(*http.Request) apiFuncResult {
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{nil, nil, nil, nil}
|
2016-01-26 00:32:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 18:03:26 +00:00
|
|
|
func (api *API) query(r *http.Request) (result apiFuncResult) {
|
2021-08-31 11:31:19 +00:00
|
|
|
ts, err := parseTimeParam(r, "time", api.now())
|
|
|
|
if err != nil {
|
|
|
|
return invalidParamError(err, "time")
|
|
|
|
}
|
|
|
|
ctx := r.Context()
|
|
|
|
if to := r.FormValue("timeout"); to != "" {
|
|
|
|
var cancel context.CancelFunc
|
|
|
|
timeout, err := parseDuration(to)
|
|
|
|
if err != nil {
|
|
|
|
return invalidParamError(err, "timeout")
|
|
|
|
}
|
|
|
|
|
2023-10-04 08:36:55 +00:00
|
|
|
ctx, cancel = context.WithDeadline(ctx, api.now().Add(timeout))
|
2021-08-31 11:31:19 +00:00
|
|
|
defer cancel()
|
|
|
|
}
|
|
|
|
|
2023-03-07 23:28:31 +00:00
|
|
|
opts, err := extractQueryOpts(r)
|
|
|
|
if err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
|
|
|
}
|
2023-04-18 04:32:38 +00:00
|
|
|
qry, err := api.QueryEngine.NewInstantQuery(ctx, api.Queryable, opts, r.FormValue("query"), ts)
|
2021-08-31 11:31:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return invalidParamError(err, "query")
|
|
|
|
}
|
|
|
|
|
|
|
|
// From now on, we must only return with a finalizer in the result (to
|
|
|
|
// be called by the caller) or call qry.Close ourselves (which is
|
|
|
|
// required in the case of a panic).
|
|
|
|
defer func() {
|
|
|
|
if result.finalizer == nil {
|
|
|
|
qry.Close()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
ctx = httputil.ContextFromRequest(ctx, r)
|
|
|
|
|
|
|
|
res := qry.Exec(ctx)
|
|
|
|
if res.Err != nil {
|
|
|
|
return apiFuncResult{nil, returnAPIError(res.Err), res.Warnings, qry.Close}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Optional stats field in response if parameter "stats" is not empty.
|
2022-02-10 14:17:05 +00:00
|
|
|
sr := api.statsRenderer
|
|
|
|
if sr == nil {
|
2024-05-18 14:12:33 +00:00
|
|
|
sr = DefaultStatsRenderer
|
2021-08-31 11:31:19 +00:00
|
|
|
}
|
2022-02-10 14:17:05 +00:00
|
|
|
qs := sr(ctx, qry.Stats(), r.FormValue("stats"))
|
2017-11-16 15:30:48 +00:00
|
|
|
|
2023-02-02 04:29:13 +00:00
|
|
|
return apiFuncResult{&QueryData{
|
2021-08-31 11:31:19 +00:00
|
|
|
ResultType: res.Value.Type(),
|
|
|
|
Result: res.Value,
|
|
|
|
Stats: qs,
|
|
|
|
}, nil, res.Warnings, qry.Close}
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2022-07-20 12:55:09 +00:00
|
|
|
func (api *API) formatQuery(r *http.Request) (result apiFuncResult) {
|
|
|
|
expr, err := parser.ParseExpr(r.FormValue("query"))
|
|
|
|
if err != nil {
|
|
|
|
return invalidParamError(err, "query")
|
|
|
|
}
|
|
|
|
|
|
|
|
return apiFuncResult{expr.Pretty(0), nil, nil, nil}
|
|
|
|
}
|
|
|
|
|
2023-07-03 12:56:06 +00:00
|
|
|
func extractQueryOpts(r *http.Request) (promql.QueryOpts, error) {
|
|
|
|
var duration time.Duration
|
|
|
|
|
2023-03-07 23:28:31 +00:00
|
|
|
if strDuration := r.FormValue("lookback_delta"); strDuration != "" {
|
2023-07-03 12:56:06 +00:00
|
|
|
parsedDuration, err := parseDuration(strDuration)
|
2023-03-07 23:28:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error parsing lookback delta duration: %w", err)
|
|
|
|
}
|
2023-07-03 12:56:06 +00:00
|
|
|
duration = parsedDuration
|
2023-03-07 23:28:31 +00:00
|
|
|
}
|
2023-07-03 12:56:06 +00:00
|
|
|
|
|
|
|
return promql.NewPrometheusQueryOpts(r.FormValue("stats") == "all", duration), nil
|
2022-02-02 02:07:23 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 18:03:26 +00:00
|
|
|
func (api *API) queryRange(r *http.Request) (result apiFuncResult) {
|
2015-06-04 16:07:57 +00:00
|
|
|
start, err := parseTime(r.FormValue("start"))
|
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "start")
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
end, err := parseTime(r.FormValue("end"))
|
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "end")
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
2016-11-01 13:25:34 +00:00
|
|
|
if end.Before(start) {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(errors.New("end timestamp must not be before start time"), "end")
|
2016-11-01 13:25:34 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 16:07:57 +00:00
|
|
|
step, err := parseDuration(r.FormValue("step"))
|
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "step")
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 13:10:02 +00:00
|
|
|
if step <= 0 {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(errors.New("zero or negative query resolution step widths are not accepted. Try a positive integer"), "step")
|
2016-08-16 13:10:02 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 16:07:57 +00:00
|
|
|
// For safety, limit the number of returned points per timeseries.
|
|
|
|
// This is sufficient for 60s resolution for a week or 1h resolution for a year.
|
|
|
|
if end.Sub(start)/step > 11000 {
|
|
|
|
err := errors.New("exceeded maximum resolution of 11,000 points per timeseries. Try decreasing the query resolution (?step=XX)")
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-02 23:49:29 +00:00
|
|
|
ctx := r.Context()
|
2017-03-06 17:32:21 +00:00
|
|
|
if to := r.FormValue("timeout"); to != "" {
|
|
|
|
var cancel context.CancelFunc
|
|
|
|
timeout, err := parseDuration(to)
|
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "timeout")
|
2017-03-06 17:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel = context.WithTimeout(ctx, timeout)
|
|
|
|
defer cancel()
|
|
|
|
}
|
|
|
|
|
2023-03-07 23:28:31 +00:00
|
|
|
opts, err := extractQueryOpts(r)
|
|
|
|
if err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
|
|
|
}
|
2023-04-18 04:32:38 +00:00
|
|
|
qry, err := api.QueryEngine.NewRangeQuery(ctx, api.Queryable, opts, r.FormValue("query"), start, end, step)
|
2015-06-04 16:07:57 +00:00
|
|
|
if err != nil {
|
2023-04-11 20:45:34 +00:00
|
|
|
return invalidParamError(err, "query")
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
2021-08-31 11:31:19 +00:00
|
|
|
// From now on, we must only return with a finalizer in the result (to
|
|
|
|
// be called by the caller) or call qry.Close ourselves (which is
|
|
|
|
// required in the case of a panic).
|
|
|
|
defer func() {
|
|
|
|
if result.finalizer == nil {
|
|
|
|
qry.Close()
|
2021-07-05 10:47:34 +00:00
|
|
|
}
|
2021-08-31 11:31:19 +00:00
|
|
|
}()
|
2021-07-03 13:53:56 +00:00
|
|
|
|
2021-08-31 11:31:19 +00:00
|
|
|
ctx = httputil.ContextFromRequest(ctx, r)
|
2021-07-03 13:53:56 +00:00
|
|
|
|
2021-08-31 11:31:19 +00:00
|
|
|
res := qry.Exec(ctx)
|
|
|
|
if res.Err != nil {
|
|
|
|
return apiFuncResult{nil, returnAPIError(res.Err), res.Warnings, qry.Close}
|
2017-02-08 11:58:40 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 11:31:19 +00:00
|
|
|
// Optional stats field in response if parameter "stats" is not empty.
|
2022-02-10 14:17:05 +00:00
|
|
|
sr := api.statsRenderer
|
|
|
|
if sr == nil {
|
2024-05-18 14:12:33 +00:00
|
|
|
sr = DefaultStatsRenderer
|
2021-07-05 10:47:34 +00:00
|
|
|
}
|
2022-02-10 14:17:05 +00:00
|
|
|
qs := sr(ctx, qry.Stats(), r.FormValue("stats"))
|
2021-07-05 10:47:34 +00:00
|
|
|
|
2023-02-02 04:29:13 +00:00
|
|
|
return apiFuncResult{&QueryData{
|
2021-08-31 11:31:19 +00:00
|
|
|
ResultType: res.Value.Type(),
|
|
|
|
Result: res.Value,
|
|
|
|
Stats: qs,
|
|
|
|
}, nil, res.Warnings, qry.Close}
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 09:47:45 +00:00
|
|
|
func (api *API) queryExemplars(r *http.Request) apiFuncResult {
|
2023-07-06 15:48:13 +00:00
|
|
|
start, err := parseTimeParam(r, "start", MinTime)
|
2021-03-16 09:47:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return invalidParamError(err, "start")
|
|
|
|
}
|
2023-07-06 15:48:13 +00:00
|
|
|
end, err := parseTimeParam(r, "end", MaxTime)
|
2021-03-16 09:47:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return invalidParamError(err, "end")
|
|
|
|
}
|
|
|
|
if end.Before(start) {
|
|
|
|
err := errors.New("end timestamp must not be before start timestamp")
|
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
|
|
|
}
|
|
|
|
|
|
|
|
expr, err := parser.ParseExpr(r.FormValue("query"))
|
|
|
|
if err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
|
|
|
}
|
|
|
|
|
|
|
|
selectors := parser.ExtractSelectors(expr)
|
|
|
|
if len(selectors) < 1 {
|
|
|
|
return apiFuncResult{nil, nil, nil, nil}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := r.Context()
|
|
|
|
eq, err := api.ExemplarQueryable.ExemplarQuerier(ctx)
|
|
|
|
if err != nil {
|
2022-10-20 09:17:00 +00:00
|
|
|
return apiFuncResult{nil, returnAPIError(err), nil, nil}
|
2021-03-16 09:47:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res, err := eq.Select(timestamp.FromTime(start), timestamp.FromTime(end), selectors...)
|
|
|
|
if err != nil {
|
2022-10-20 09:17:00 +00:00
|
|
|
return apiFuncResult{nil, returnAPIError(err), nil, nil}
|
2021-03-16 09:47:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return apiFuncResult{res, nil, nil, nil}
|
|
|
|
}
|
|
|
|
|
2018-11-14 09:55:54 +00:00
|
|
|
func returnAPIError(err error) *apiError {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-11-08 03:49:39 +00:00
|
|
|
var eqc promql.ErrQueryCanceled
|
|
|
|
var eqt promql.ErrQueryTimeout
|
|
|
|
var es promql.ErrStorage
|
|
|
|
switch {
|
|
|
|
case errors.As(err, &eqc):
|
2018-11-14 09:55:54 +00:00
|
|
|
return &apiError{errorCanceled, err}
|
2023-11-08 03:49:39 +00:00
|
|
|
case errors.As(err, &eqt):
|
2018-11-14 09:55:54 +00:00
|
|
|
return &apiError{errorTimeout, err}
|
2023-11-08 03:49:39 +00:00
|
|
|
case errors.As(err, &es):
|
2018-11-14 09:55:54 +00:00
|
|
|
return &apiError{errorInternal, err}
|
|
|
|
}
|
|
|
|
|
2023-01-25 19:22:25 +00:00
|
|
|
if errors.Is(err, context.Canceled) {
|
|
|
|
return &apiError{errorCanceled, err}
|
|
|
|
}
|
|
|
|
|
2018-11-14 09:55:54 +00:00
|
|
|
return &apiError{errorExec, err}
|
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
func (api *API) labelNames(r *http.Request) apiFuncResult {
|
2024-02-29 15:31:13 +00:00
|
|
|
limit, err := parseLimitParam(r.FormValue("limit"))
|
|
|
|
if err != nil {
|
|
|
|
return invalidParamError(err, "limit")
|
|
|
|
}
|
|
|
|
|
2023-07-06 15:48:13 +00:00
|
|
|
start, err := parseTimeParam(r, "start", MinTime)
|
2020-05-30 12:50:09 +00:00
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "start")
|
2020-05-30 12:50:09 +00:00
|
|
|
}
|
2023-07-06 15:48:13 +00:00
|
|
|
end, err := parseTimeParam(r, "end", MaxTime)
|
2020-05-30 12:50:09 +00:00
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "end")
|
2020-05-30 12:50:09 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 11:02:19 +00:00
|
|
|
matcherSets, err := parseMatchersParam(r.Form["match[]"])
|
|
|
|
if err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
|
|
|
}
|
|
|
|
|
2023-09-12 10:37:38 +00:00
|
|
|
q, err := api.Queryable.Querier(timestamp.FromTime(start), timestamp.FromTime(end))
|
2018-11-19 10:21:14 +00:00
|
|
|
if err != nil {
|
2022-10-20 09:17:00 +00:00
|
|
|
return apiFuncResult{nil, returnAPIError(err), nil, nil}
|
2018-11-19 10:21:14 +00:00
|
|
|
}
|
|
|
|
defer q.Close()
|
|
|
|
|
2020-12-22 11:02:19 +00:00
|
|
|
var (
|
|
|
|
names []string
|
2023-09-14 16:57:31 +00:00
|
|
|
warnings annotations.Annotations
|
2020-12-22 11:02:19 +00:00
|
|
|
)
|
2023-11-13 18:28:48 +00:00
|
|
|
if len(matcherSets) > 1 {
|
2020-12-22 11:02:19 +00:00
|
|
|
labelNamesSet := make(map[string]struct{})
|
2021-07-20 12:38:08 +00:00
|
|
|
|
|
|
|
for _, matchers := range matcherSets {
|
2023-09-14 08:39:51 +00:00
|
|
|
vals, callWarnings, err := q.LabelNames(r.Context(), matchers...)
|
2021-07-20 12:38:08 +00:00
|
|
|
if err != nil {
|
2022-10-20 09:17:00 +00:00
|
|
|
return apiFuncResult{nil, returnAPIError(err), warnings, nil}
|
2020-12-22 11:02:19 +00:00
|
|
|
}
|
2021-07-20 12:38:08 +00:00
|
|
|
|
2023-09-14 16:57:31 +00:00
|
|
|
warnings.Merge(callWarnings)
|
2021-07-20 12:38:08 +00:00
|
|
|
for _, val := range vals {
|
|
|
|
labelNamesSet[val] = struct{}{}
|
|
|
|
}
|
2020-12-22 11:02:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the map to an array.
|
|
|
|
names = make([]string, 0, len(labelNamesSet))
|
|
|
|
for key := range labelNamesSet {
|
|
|
|
names = append(names, key)
|
|
|
|
}
|
2022-09-30 14:33:56 +00:00
|
|
|
slices.Sort(names)
|
2020-12-22 11:02:19 +00:00
|
|
|
} else {
|
2023-11-13 18:28:48 +00:00
|
|
|
var matchers []*labels.Matcher
|
|
|
|
if len(matcherSets) == 1 {
|
|
|
|
matchers = matcherSets[0]
|
|
|
|
}
|
|
|
|
names, warnings, err = q.LabelNames(r.Context(), matchers...)
|
2020-12-22 11:02:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorExec, err}, warnings, nil}
|
|
|
|
}
|
2018-11-19 10:21:14 +00:00
|
|
|
}
|
2020-12-22 11:02:19 +00:00
|
|
|
|
2020-07-31 15:03:02 +00:00
|
|
|
if names == nil {
|
|
|
|
names = []string{}
|
|
|
|
}
|
2024-02-29 15:31:13 +00:00
|
|
|
|
2024-05-21 17:07:29 +00:00
|
|
|
if len(names) > limit {
|
2024-02-29 15:31:13 +00:00
|
|
|
names = names[:limit]
|
|
|
|
warnings = warnings.Add(errors.New("results truncated due to limit"))
|
|
|
|
}
|
2019-06-17 07:31:17 +00:00
|
|
|
return apiFuncResult{names, nil, warnings, nil}
|
2018-11-19 10:21:14 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 18:03:26 +00:00
|
|
|
func (api *API) labelValues(r *http.Request) (result apiFuncResult) {
|
2017-10-04 19:04:15 +00:00
|
|
|
ctx := r.Context()
|
|
|
|
name := route.Param(ctx, "name")
|
2015-06-08 19:19:52 +00:00
|
|
|
|
2015-08-20 15:18:46 +00:00
|
|
|
if !model.LabelNameRE.MatchString(name) {
|
2023-11-08 03:49:39 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, fmt.Errorf("invalid label name: %q", name)}, nil, nil}
|
2015-06-08 19:19:52 +00:00
|
|
|
}
|
2020-05-30 12:50:09 +00:00
|
|
|
|
2024-02-29 15:31:13 +00:00
|
|
|
limit, err := parseLimitParam(r.FormValue("limit"))
|
|
|
|
if err != nil {
|
|
|
|
return invalidParamError(err, "limit")
|
|
|
|
}
|
|
|
|
|
2023-07-06 15:48:13 +00:00
|
|
|
start, err := parseTimeParam(r, "start", MinTime)
|
2020-05-30 12:50:09 +00:00
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "start")
|
2020-05-30 12:50:09 +00:00
|
|
|
}
|
2023-07-06 15:48:13 +00:00
|
|
|
end, err := parseTimeParam(r, "end", MaxTime)
|
2020-05-30 12:50:09 +00:00
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "end")
|
2020-05-30 12:50:09 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 11:02:19 +00:00
|
|
|
matcherSets, err := parseMatchersParam(r.Form["match[]"])
|
|
|
|
if err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
|
|
|
}
|
|
|
|
|
2023-09-12 10:37:38 +00:00
|
|
|
q, err := api.Queryable.Querier(timestamp.FromTime(start), timestamp.FromTime(end))
|
2016-10-12 17:34:22 +00:00
|
|
|
if err != nil {
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorExec, err}, nil, nil}
|
2016-10-12 17:34:22 +00:00
|
|
|
}
|
2020-04-17 18:03:26 +00:00
|
|
|
// From now on, we must only return with a finalizer in the result (to
|
|
|
|
// be called by the caller) or call q.Close ourselves (which is required
|
|
|
|
// in the case of a panic).
|
|
|
|
defer func() {
|
|
|
|
if result.finalizer == nil {
|
|
|
|
q.Close()
|
|
|
|
}
|
|
|
|
}()
|
Load only some offsets into the symbol table into memory.
Rather than keeping the entire symbol table in memory, keep every nth
offset and walk from there to the entry we need. This ends up slightly
slower, ~360ms per 1M series returned from PostingsForMatchers which is
not much considering the rest of the CPU such a query would go on to
use.
Make LabelValues use the postings tables, rather than having
to do symbol lookups. Use yoloString, as PostingsForMatchers
doesn't need the strings to stick around and adjust the API
call to keep the Querier open until it's all marshalled.
Remove allocatedSymbols memory optimisation, we no longer keep all the
symbol strings in heap memory. Remove LabelValuesFor and LabelIndices,
they're dead code. Ensure we've still tests for label indices,
and add missing test that we can work with old V1 Format index files.
PostingForMatchers performance is slightly better, with a big drop in
allocation counts due to using yoloString for LabelValues:
benchmark old ns/op new ns/op delta
BenchmarkPostingsForMatchers/Block/n="1"-4 36698 36681 -0.05%
BenchmarkPostingsForMatchers/Block/n="1",j="foo"-4 522786 560887 +7.29%
BenchmarkPostingsForMatchers/Block/j="foo",n="1"-4 511652 537680 +5.09%
BenchmarkPostingsForMatchers/Block/n="1",j!="foo"-4 522102 564239 +8.07%
BenchmarkPostingsForMatchers/Block/i=~".*"-4 113689911 111795919 -1.67%
BenchmarkPostingsForMatchers/Block/i=~".+"-4 135825572 132871085 -2.18%
BenchmarkPostingsForMatchers/Block/i=~""-4 40782628 38038181 -6.73%
BenchmarkPostingsForMatchers/Block/i!=""-4 31267869 29194327 -6.63%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",j="foo"-4 112733329 111568823 -1.03%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",i!="2",j="foo"-4 112868153 111232029 -1.45%
BenchmarkPostingsForMatchers/Block/n="1",i!=""-4 31338257 29349446 -6.35%
BenchmarkPostingsForMatchers/Block/n="1",i!="",j="foo"-4 32054482 29972436 -6.50%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",j="foo"-4 136504654 133968442 -1.86%
BenchmarkPostingsForMatchers/Block/n="1",i=~"1.+",j="foo"-4 27960350 27264997 -2.49%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!="2",j="foo"-4 136765564 133860724 -2.12%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!~"2.*",j="foo"-4 163714583 159453668 -2.60%
benchmark old allocs new allocs delta
BenchmarkPostingsForMatchers/Block/n="1"-4 6 6 +0.00%
BenchmarkPostingsForMatchers/Block/n="1",j="foo"-4 11 11 +0.00%
BenchmarkPostingsForMatchers/Block/j="foo",n="1"-4 11 11 +0.00%
BenchmarkPostingsForMatchers/Block/n="1",j!="foo"-4 17 15 -11.76%
BenchmarkPostingsForMatchers/Block/i=~".*"-4 100012 12 -99.99%
BenchmarkPostingsForMatchers/Block/i=~".+"-4 200040 100040 -49.99%
BenchmarkPostingsForMatchers/Block/i=~""-4 200045 100045 -49.99%
BenchmarkPostingsForMatchers/Block/i!=""-4 200041 100041 -49.99%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",j="foo"-4 100017 17 -99.98%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",i!="2",j="foo"-4 100023 23 -99.98%
BenchmarkPostingsForMatchers/Block/n="1",i!=""-4 200046 100046 -49.99%
BenchmarkPostingsForMatchers/Block/n="1",i!="",j="foo"-4 200050 100050 -49.99%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",j="foo"-4 200049 100049 -49.99%
BenchmarkPostingsForMatchers/Block/n="1",i=~"1.+",j="foo"-4 111150 11150 -89.97%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!="2",j="foo"-4 200055 100055 -49.99%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!~"2.*",j="foo"-4 311238 111238 -64.26%
benchmark old bytes new bytes delta
BenchmarkPostingsForMatchers/Block/n="1"-4 296 296 +0.00%
BenchmarkPostingsForMatchers/Block/n="1",j="foo"-4 424 424 +0.00%
BenchmarkPostingsForMatchers/Block/j="foo",n="1"-4 424 424 +0.00%
BenchmarkPostingsForMatchers/Block/n="1",j!="foo"-4 552 1544 +179.71%
BenchmarkPostingsForMatchers/Block/i=~".*"-4 1600482 1606125 +0.35%
BenchmarkPostingsForMatchers/Block/i=~".+"-4 17259065 17264709 +0.03%
BenchmarkPostingsForMatchers/Block/i=~""-4 17259150 17264780 +0.03%
BenchmarkPostingsForMatchers/Block/i!=""-4 17259048 17264680 +0.03%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",j="foo"-4 1600610 1606242 +0.35%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",i!="2",j="foo"-4 1600813 1606434 +0.35%
BenchmarkPostingsForMatchers/Block/n="1",i!=""-4 17259176 17264808 +0.03%
BenchmarkPostingsForMatchers/Block/n="1",i!="",j="foo"-4 17259304 17264936 +0.03%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",j="foo"-4 17259333 17264965 +0.03%
BenchmarkPostingsForMatchers/Block/n="1",i=~"1.+",j="foo"-4 3142628 3148262 +0.18%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!="2",j="foo"-4 17259509 17265141 +0.03%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!~"2.*",j="foo"-4 20405680 20416944 +0.06%
However overall Select performance is down and involves more allocs, due to
having to do more than a simple map lookup to resolve a symbol and that all the strings
returned are allocated:
benchmark old ns/op new ns/op delta
BenchmarkQuerierSelect/Block/1of1000000-4 506092636 862678244 +70.46%
BenchmarkQuerierSelect/Block/10of1000000-4 505638968 860917636 +70.26%
BenchmarkQuerierSelect/Block/100of1000000-4 505229450 882150048 +74.60%
BenchmarkQuerierSelect/Block/1000of1000000-4 515905414 862241115 +67.13%
BenchmarkQuerierSelect/Block/10000of1000000-4 516785354 874841110 +69.29%
BenchmarkQuerierSelect/Block/100000of1000000-4 540742808 907030187 +67.74%
BenchmarkQuerierSelect/Block/1000000of1000000-4 815224288 1181236903 +44.90%
benchmark old allocs new allocs delta
BenchmarkQuerierSelect/Block/1of1000000-4 4000020 6000020 +50.00%
BenchmarkQuerierSelect/Block/10of1000000-4 4000038 6000038 +50.00%
BenchmarkQuerierSelect/Block/100of1000000-4 4000218 6000218 +50.00%
BenchmarkQuerierSelect/Block/1000of1000000-4 4002018 6002018 +49.97%
BenchmarkQuerierSelect/Block/10000of1000000-4 4020018 6020018 +49.75%
BenchmarkQuerierSelect/Block/100000of1000000-4 4200018 6200018 +47.62%
BenchmarkQuerierSelect/Block/1000000of1000000-4 6000018 8000019 +33.33%
benchmark old bytes new bytes delta
BenchmarkQuerierSelect/Block/1of1000000-4 176001468 227201476 +29.09%
BenchmarkQuerierSelect/Block/10of1000000-4 176002620 227202628 +29.09%
BenchmarkQuerierSelect/Block/100of1000000-4 176014140 227214148 +29.09%
BenchmarkQuerierSelect/Block/1000of1000000-4 176129340 227329348 +29.07%
BenchmarkQuerierSelect/Block/10000of1000000-4 177281340 228481348 +28.88%
BenchmarkQuerierSelect/Block/100000of1000000-4 188801340 240001348 +27.12%
BenchmarkQuerierSelect/Block/1000000of1000000-4 304001340 355201616 +16.84%
Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
2019-12-12 16:55:32 +00:00
|
|
|
closer := func() {
|
|
|
|
q.Close()
|
|
|
|
}
|
2016-10-12 17:34:22 +00:00
|
|
|
|
2020-12-22 11:02:19 +00:00
|
|
|
var (
|
|
|
|
vals []string
|
2023-09-14 16:57:31 +00:00
|
|
|
warnings annotations.Annotations
|
2020-12-22 11:02:19 +00:00
|
|
|
)
|
2023-11-13 18:28:48 +00:00
|
|
|
if len(matcherSets) > 1 {
|
2023-09-14 16:57:31 +00:00
|
|
|
var callWarnings annotations.Annotations
|
2020-12-22 11:02:19 +00:00
|
|
|
labelValuesSet := make(map[string]struct{})
|
2021-02-09 17:38:35 +00:00
|
|
|
for _, matchers := range matcherSets {
|
2023-09-14 14:02:04 +00:00
|
|
|
vals, callWarnings, err = q.LabelValues(ctx, name, matchers...)
|
2021-02-09 17:38:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorExec, err}, warnings, closer}
|
2020-12-22 11:02:19 +00:00
|
|
|
}
|
2023-09-14 16:57:31 +00:00
|
|
|
warnings.Merge(callWarnings)
|
2021-02-09 17:38:35 +00:00
|
|
|
for _, val := range vals {
|
|
|
|
labelValuesSet[val] = struct{}{}
|
2020-12-22 11:02:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vals = make([]string, 0, len(labelValuesSet))
|
2021-02-09 17:38:35 +00:00
|
|
|
for val := range labelValuesSet {
|
|
|
|
vals = append(vals, val)
|
2020-12-22 11:02:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-11-13 18:28:48 +00:00
|
|
|
var matchers []*labels.Matcher
|
|
|
|
if len(matcherSets) == 1 {
|
|
|
|
matchers = matcherSets[0]
|
|
|
|
}
|
|
|
|
vals, warnings, err = q.LabelValues(ctx, name, matchers...)
|
2020-12-22 11:02:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorExec, err}, warnings, closer}
|
|
|
|
}
|
|
|
|
|
2021-02-09 17:38:35 +00:00
|
|
|
if vals == nil {
|
|
|
|
vals = []string{}
|
|
|
|
}
|
2020-07-31 15:03:02 +00:00
|
|
|
}
|
2015-06-04 16:07:57 +00:00
|
|
|
|
2022-09-30 14:33:56 +00:00
|
|
|
slices.Sort(vals)
|
2021-02-09 17:38:35 +00:00
|
|
|
|
2024-05-21 17:07:29 +00:00
|
|
|
if len(vals) > limit {
|
2024-02-29 15:31:13 +00:00
|
|
|
vals = vals[:limit]
|
|
|
|
warnings = warnings.Add(errors.New("results truncated due to limit"))
|
|
|
|
}
|
|
|
|
|
Load only some offsets into the symbol table into memory.
Rather than keeping the entire symbol table in memory, keep every nth
offset and walk from there to the entry we need. This ends up slightly
slower, ~360ms per 1M series returned from PostingsForMatchers which is
not much considering the rest of the CPU such a query would go on to
use.
Make LabelValues use the postings tables, rather than having
to do symbol lookups. Use yoloString, as PostingsForMatchers
doesn't need the strings to stick around and adjust the API
call to keep the Querier open until it's all marshalled.
Remove allocatedSymbols memory optimisation, we no longer keep all the
symbol strings in heap memory. Remove LabelValuesFor and LabelIndices,
they're dead code. Ensure we've still tests for label indices,
and add missing test that we can work with old V1 Format index files.
PostingForMatchers performance is slightly better, with a big drop in
allocation counts due to using yoloString for LabelValues:
benchmark old ns/op new ns/op delta
BenchmarkPostingsForMatchers/Block/n="1"-4 36698 36681 -0.05%
BenchmarkPostingsForMatchers/Block/n="1",j="foo"-4 522786 560887 +7.29%
BenchmarkPostingsForMatchers/Block/j="foo",n="1"-4 511652 537680 +5.09%
BenchmarkPostingsForMatchers/Block/n="1",j!="foo"-4 522102 564239 +8.07%
BenchmarkPostingsForMatchers/Block/i=~".*"-4 113689911 111795919 -1.67%
BenchmarkPostingsForMatchers/Block/i=~".+"-4 135825572 132871085 -2.18%
BenchmarkPostingsForMatchers/Block/i=~""-4 40782628 38038181 -6.73%
BenchmarkPostingsForMatchers/Block/i!=""-4 31267869 29194327 -6.63%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",j="foo"-4 112733329 111568823 -1.03%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",i!="2",j="foo"-4 112868153 111232029 -1.45%
BenchmarkPostingsForMatchers/Block/n="1",i!=""-4 31338257 29349446 -6.35%
BenchmarkPostingsForMatchers/Block/n="1",i!="",j="foo"-4 32054482 29972436 -6.50%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",j="foo"-4 136504654 133968442 -1.86%
BenchmarkPostingsForMatchers/Block/n="1",i=~"1.+",j="foo"-4 27960350 27264997 -2.49%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!="2",j="foo"-4 136765564 133860724 -2.12%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!~"2.*",j="foo"-4 163714583 159453668 -2.60%
benchmark old allocs new allocs delta
BenchmarkPostingsForMatchers/Block/n="1"-4 6 6 +0.00%
BenchmarkPostingsForMatchers/Block/n="1",j="foo"-4 11 11 +0.00%
BenchmarkPostingsForMatchers/Block/j="foo",n="1"-4 11 11 +0.00%
BenchmarkPostingsForMatchers/Block/n="1",j!="foo"-4 17 15 -11.76%
BenchmarkPostingsForMatchers/Block/i=~".*"-4 100012 12 -99.99%
BenchmarkPostingsForMatchers/Block/i=~".+"-4 200040 100040 -49.99%
BenchmarkPostingsForMatchers/Block/i=~""-4 200045 100045 -49.99%
BenchmarkPostingsForMatchers/Block/i!=""-4 200041 100041 -49.99%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",j="foo"-4 100017 17 -99.98%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",i!="2",j="foo"-4 100023 23 -99.98%
BenchmarkPostingsForMatchers/Block/n="1",i!=""-4 200046 100046 -49.99%
BenchmarkPostingsForMatchers/Block/n="1",i!="",j="foo"-4 200050 100050 -49.99%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",j="foo"-4 200049 100049 -49.99%
BenchmarkPostingsForMatchers/Block/n="1",i=~"1.+",j="foo"-4 111150 11150 -89.97%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!="2",j="foo"-4 200055 100055 -49.99%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!~"2.*",j="foo"-4 311238 111238 -64.26%
benchmark old bytes new bytes delta
BenchmarkPostingsForMatchers/Block/n="1"-4 296 296 +0.00%
BenchmarkPostingsForMatchers/Block/n="1",j="foo"-4 424 424 +0.00%
BenchmarkPostingsForMatchers/Block/j="foo",n="1"-4 424 424 +0.00%
BenchmarkPostingsForMatchers/Block/n="1",j!="foo"-4 552 1544 +179.71%
BenchmarkPostingsForMatchers/Block/i=~".*"-4 1600482 1606125 +0.35%
BenchmarkPostingsForMatchers/Block/i=~".+"-4 17259065 17264709 +0.03%
BenchmarkPostingsForMatchers/Block/i=~""-4 17259150 17264780 +0.03%
BenchmarkPostingsForMatchers/Block/i!=""-4 17259048 17264680 +0.03%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",j="foo"-4 1600610 1606242 +0.35%
BenchmarkPostingsForMatchers/Block/n="1",i=~".*",i!="2",j="foo"-4 1600813 1606434 +0.35%
BenchmarkPostingsForMatchers/Block/n="1",i!=""-4 17259176 17264808 +0.03%
BenchmarkPostingsForMatchers/Block/n="1",i!="",j="foo"-4 17259304 17264936 +0.03%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",j="foo"-4 17259333 17264965 +0.03%
BenchmarkPostingsForMatchers/Block/n="1",i=~"1.+",j="foo"-4 3142628 3148262 +0.18%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!="2",j="foo"-4 17259509 17265141 +0.03%
BenchmarkPostingsForMatchers/Block/n="1",i=~".+",i!~"2.*",j="foo"-4 20405680 20416944 +0.06%
However overall Select performance is down and involves more allocs, due to
having to do more than a simple map lookup to resolve a symbol and that all the strings
returned are allocated:
benchmark old ns/op new ns/op delta
BenchmarkQuerierSelect/Block/1of1000000-4 506092636 862678244 +70.46%
BenchmarkQuerierSelect/Block/10of1000000-4 505638968 860917636 +70.26%
BenchmarkQuerierSelect/Block/100of1000000-4 505229450 882150048 +74.60%
BenchmarkQuerierSelect/Block/1000of1000000-4 515905414 862241115 +67.13%
BenchmarkQuerierSelect/Block/10000of1000000-4 516785354 874841110 +69.29%
BenchmarkQuerierSelect/Block/100000of1000000-4 540742808 907030187 +67.74%
BenchmarkQuerierSelect/Block/1000000of1000000-4 815224288 1181236903 +44.90%
benchmark old allocs new allocs delta
BenchmarkQuerierSelect/Block/1of1000000-4 4000020 6000020 +50.00%
BenchmarkQuerierSelect/Block/10of1000000-4 4000038 6000038 +50.00%
BenchmarkQuerierSelect/Block/100of1000000-4 4000218 6000218 +50.00%
BenchmarkQuerierSelect/Block/1000of1000000-4 4002018 6002018 +49.97%
BenchmarkQuerierSelect/Block/10000of1000000-4 4020018 6020018 +49.75%
BenchmarkQuerierSelect/Block/100000of1000000-4 4200018 6200018 +47.62%
BenchmarkQuerierSelect/Block/1000000of1000000-4 6000018 8000019 +33.33%
benchmark old bytes new bytes delta
BenchmarkQuerierSelect/Block/1of1000000-4 176001468 227201476 +29.09%
BenchmarkQuerierSelect/Block/10of1000000-4 176002620 227202628 +29.09%
BenchmarkQuerierSelect/Block/100of1000000-4 176014140 227214148 +29.09%
BenchmarkQuerierSelect/Block/1000of1000000-4 176129340 227329348 +29.07%
BenchmarkQuerierSelect/Block/10000of1000000-4 177281340 228481348 +28.88%
BenchmarkQuerierSelect/Block/100000of1000000-4 188801340 240001348 +27.12%
BenchmarkQuerierSelect/Block/1000000of1000000-4 304001340 355201616 +16.84%
Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
2019-12-12 16:55:32 +00:00
|
|
|
return apiFuncResult{vals, nil, warnings, closer}
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 13:09:59 +00:00
|
|
|
var (
|
2023-07-06 15:48:13 +00:00
|
|
|
// MinTime is the default timestamp used for the begin of optional time ranges.
|
|
|
|
// Exposed to let downstream projects to reference it.
|
|
|
|
MinTime = time.Unix(math.MinInt64/1000+62135596801, 0).UTC()
|
2019-07-08 09:43:59 +00:00
|
|
|
|
2023-07-06 15:48:13 +00:00
|
|
|
// MaxTime is the default timestamp used for the end of optional time ranges.
|
|
|
|
// Exposed to let downstream projects to reference it.
|
|
|
|
MaxTime = time.Unix(math.MaxInt64/1000-62135596801, 999999999).UTC()
|
|
|
|
|
|
|
|
minTimeFormatted = MinTime.Format(time.RFC3339Nano)
|
|
|
|
maxTimeFormatted = MaxTime.Format(time.RFC3339Nano)
|
2017-01-16 13:09:59 +00:00
|
|
|
)
|
|
|
|
|
2020-04-17 20:40:39 +00:00
|
|
|
func (api *API) series(r *http.Request) (result apiFuncResult) {
|
2023-09-12 10:37:38 +00:00
|
|
|
ctx := r.Context()
|
|
|
|
|
2018-08-17 15:24:35 +00:00
|
|
|
if err := r.ParseForm(); err != nil {
|
2023-11-08 03:49:39 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, fmt.Errorf("error parsing form values: %w", err)}, nil, nil}
|
2018-08-17 15:24:35 +00:00
|
|
|
}
|
2015-06-09 14:09:31 +00:00
|
|
|
if len(r.Form["match[]"]) == 0 {
|
2019-03-25 23:01:12 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, errors.New("no match[] parameter provided")}, nil, nil}
|
2015-06-09 14:09:31 +00:00
|
|
|
}
|
2016-05-11 21:59:52 +00:00
|
|
|
|
2024-02-29 15:31:13 +00:00
|
|
|
limit, err := parseLimitParam(r.FormValue("limit"))
|
|
|
|
if err != nil {
|
|
|
|
return invalidParamError(err, "limit")
|
|
|
|
}
|
|
|
|
|
2023-07-06 15:48:13 +00:00
|
|
|
start, err := parseTimeParam(r, "start", MinTime)
|
2020-03-06 10:33:01 +00:00
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "start")
|
2016-05-11 21:59:52 +00:00
|
|
|
}
|
2023-07-06 15:48:13 +00:00
|
|
|
end, err := parseTimeParam(r, "end", MaxTime)
|
2020-03-06 10:33:01 +00:00
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "end")
|
2016-05-11 21:59:52 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 11:02:19 +00:00
|
|
|
matcherSets, err := parseMatchersParam(r.Form["match[]"])
|
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "match[]")
|
2020-12-15 17:24:57 +00:00
|
|
|
}
|
|
|
|
|
2023-09-12 10:37:38 +00:00
|
|
|
q, err := api.Queryable.Querier(timestamp.FromTime(start), timestamp.FromTime(end))
|
2016-12-30 09:43:44 +00:00
|
|
|
if err != nil {
|
2022-10-20 09:17:00 +00:00
|
|
|
return apiFuncResult{nil, returnAPIError(err), nil, nil}
|
2016-12-30 09:43:44 +00:00
|
|
|
}
|
2020-04-17 20:40:39 +00:00
|
|
|
// From now on, we must only return with a finalizer in the result (to
|
|
|
|
// be called by the caller) or call q.Close ourselves (which is required
|
|
|
|
// in the case of a panic).
|
|
|
|
defer func() {
|
|
|
|
if result.finalizer == nil {
|
|
|
|
q.Close()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
closer := func() {
|
|
|
|
q.Close()
|
|
|
|
}
|
2016-12-30 09:43:44 +00:00
|
|
|
|
2020-10-14 09:06:17 +00:00
|
|
|
hints := &storage.SelectHints{
|
|
|
|
Start: timestamp.FromTime(start),
|
|
|
|
End: timestamp.FromTime(end),
|
|
|
|
Func: "series", // There is no series function, this token is used for lookups that don't need samples.
|
|
|
|
}
|
2022-09-16 07:40:41 +00:00
|
|
|
var set storage.SeriesSet
|
2020-10-14 09:06:17 +00:00
|
|
|
|
2022-09-16 07:40:41 +00:00
|
|
|
if len(matcherSets) > 1 {
|
|
|
|
var sets []storage.SeriesSet
|
|
|
|
for _, mset := range matcherSets {
|
|
|
|
// We need to sort this select results to merge (deduplicate) the series sets later.
|
2023-09-12 10:37:38 +00:00
|
|
|
s := q.Select(ctx, true, hints, mset...)
|
2022-09-16 07:40:41 +00:00
|
|
|
sets = append(sets, s)
|
|
|
|
}
|
|
|
|
set = storage.NewMergeSeriesSet(sets, storage.ChainedSeriesMerge)
|
|
|
|
} else {
|
|
|
|
// At this point at least one match exists.
|
2023-09-12 10:37:38 +00:00
|
|
|
set = q.Select(ctx, false, hints, matcherSets[0]...)
|
2016-12-30 09:43:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-04 09:09:11 +00:00
|
|
|
metrics := []labels.Labels{}
|
2024-02-29 15:31:13 +00:00
|
|
|
|
|
|
|
warnings := set.Warnings()
|
|
|
|
|
2017-04-04 09:09:11 +00:00
|
|
|
for set.Next() {
|
2024-03-19 17:37:43 +00:00
|
|
|
if err := ctx.Err(); err != nil {
|
|
|
|
return apiFuncResult{nil, returnAPIError(err), warnings, closer}
|
|
|
|
}
|
2017-04-04 09:09:11 +00:00
|
|
|
metrics = append(metrics, set.At().Labels())
|
2020-06-09 16:57:31 +00:00
|
|
|
|
2024-05-21 17:07:29 +00:00
|
|
|
if len(metrics) > limit {
|
|
|
|
metrics = metrics[:limit]
|
2024-02-29 15:31:13 +00:00
|
|
|
warnings.Add(errors.New("results truncated due to limit"))
|
|
|
|
return apiFuncResult{metrics, nil, warnings, closer}
|
|
|
|
}
|
|
|
|
}
|
2017-04-04 09:09:11 +00:00
|
|
|
if set.Err() != nil {
|
2022-10-20 09:17:00 +00:00
|
|
|
return apiFuncResult{nil, returnAPIError(set.Err()), warnings, closer}
|
2017-04-04 09:09:11 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 20:40:39 +00:00
|
|
|
return apiFuncResult{metrics, nil, warnings, closer}
|
2015-06-09 14:09:31 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 00:27:13 +00:00
|
|
|
func (api *API) dropSeries(_ *http.Request) apiFuncResult {
|
2019-03-25 23:01:12 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorInternal, errors.New("not implemented")}, nil, nil}
|
2015-06-09 14:09:31 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 17:51:27 +00:00
|
|
|
// Target has the information for one target.
|
2016-12-02 12:31:43 +00:00
|
|
|
type Target struct {
|
|
|
|
// Labels before any processing.
|
2024-01-29 10:19:02 +00:00
|
|
|
DiscoveredLabels labels.Labels `json:"discoveredLabels"`
|
2016-12-02 12:31:43 +00:00
|
|
|
// Any labels that are added to this target and its metrics.
|
2024-01-29 10:19:02 +00:00
|
|
|
Labels labels.Labels `json:"labels"`
|
2016-12-02 12:31:43 +00:00
|
|
|
|
2019-11-11 21:42:24 +00:00
|
|
|
ScrapePool string `json:"scrapePool"`
|
|
|
|
ScrapeURL string `json:"scrapeUrl"`
|
2020-02-17 17:19:15 +00:00
|
|
|
GlobalURL string `json:"globalUrl"`
|
2016-12-02 12:31:43 +00:00
|
|
|
|
2019-11-11 21:42:24 +00:00
|
|
|
LastError string `json:"lastError"`
|
|
|
|
LastScrape time.Time `json:"lastScrape"`
|
|
|
|
LastScrapeDuration float64 `json:"lastScrapeDuration"`
|
|
|
|
Health scrape.TargetHealth `json:"health"`
|
2021-08-31 15:37:32 +00:00
|
|
|
|
|
|
|
ScrapeInterval string `json:"scrapeInterval"`
|
|
|
|
ScrapeTimeout string `json:"scrapeTimeout"`
|
2016-12-02 12:31:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-23 10:55:08 +00:00
|
|
|
type ScrapePoolsDiscovery struct {
|
|
|
|
ScrapePools []string `json:"scrapePools"`
|
|
|
|
}
|
|
|
|
|
2018-02-21 17:26:18 +00:00
|
|
|
// DroppedTarget has the information for one target that was dropped during relabelling.
|
|
|
|
type DroppedTarget struct {
|
|
|
|
// Labels before any processing.
|
2024-01-29 10:20:20 +00:00
|
|
|
DiscoveredLabels labels.Labels `json:"discoveredLabels"`
|
2018-02-21 17:26:18 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 11:46:37 +00:00
|
|
|
// TargetDiscovery has all the active targets.
|
2017-01-13 16:15:04 +00:00
|
|
|
type TargetDiscovery struct {
|
2023-08-14 14:39:25 +00:00
|
|
|
ActiveTargets []*Target `json:"activeTargets"`
|
|
|
|
DroppedTargets []*DroppedTarget `json:"droppedTargets"`
|
|
|
|
DroppedTargetCounts map[string]int `json:"droppedTargetCounts"`
|
2017-01-13 16:15:04 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 17:19:15 +00:00
|
|
|
// GlobalURLOptions contains fields used for deriving the global URL for local targets.
|
|
|
|
type GlobalURLOptions struct {
|
|
|
|
ListenAddress string
|
|
|
|
Host string
|
|
|
|
Scheme string
|
|
|
|
}
|
|
|
|
|
2021-02-05 11:45:44 +00:00
|
|
|
// sanitizeSplitHostPort acts like net.SplitHostPort.
|
|
|
|
// Additionally, if there is no port in the host passed as input, we return the
|
|
|
|
// original host, making sure that IPv6 addresses are not surrounded by square
|
|
|
|
// brackets.
|
|
|
|
func sanitizeSplitHostPort(input string) (string, string, error) {
|
|
|
|
host, port, err := net.SplitHostPort(input)
|
|
|
|
if err != nil && strings.HasSuffix(err.Error(), "missing port in address") {
|
|
|
|
var errWithPort error
|
|
|
|
host, _, errWithPort = net.SplitHostPort(input + ":80")
|
|
|
|
if errWithPort == nil {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return host, port, err
|
|
|
|
}
|
|
|
|
|
2020-02-17 17:19:15 +00:00
|
|
|
func getGlobalURL(u *url.URL, opts GlobalURLOptions) (*url.URL, error) {
|
2021-02-05 11:45:44 +00:00
|
|
|
host, port, err := sanitizeSplitHostPort(u.Host)
|
2020-02-17 17:19:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return u, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, lhr := range LocalhostRepresentations {
|
|
|
|
if host == lhr {
|
|
|
|
_, ownPort, err := net.SplitHostPort(opts.ListenAddress)
|
|
|
|
if err != nil {
|
|
|
|
return u, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if port == ownPort {
|
|
|
|
// Only in the case where the target is on localhost and its port is
|
|
|
|
// the same as the one we're listening on, we know for sure that
|
|
|
|
// we're monitoring our own process and that we need to change the
|
|
|
|
// scheme, hostname, and port to the externally reachable ones as
|
|
|
|
// well. We shouldn't need to touch the path at all, since if a
|
|
|
|
// path prefix is defined, the path under which we scrape ourselves
|
|
|
|
// should already contain the prefix.
|
|
|
|
u.Scheme = opts.Scheme
|
|
|
|
u.Host = opts.Host
|
|
|
|
} else {
|
|
|
|
// Otherwise, we only know that localhost is not reachable
|
|
|
|
// externally, so we replace only the hostname by the one in the
|
|
|
|
// external URL. It could be the wrong hostname for the service on
|
|
|
|
// this port, but it's still the best possible guess.
|
2021-02-05 11:45:44 +00:00
|
|
|
host, _, err := sanitizeSplitHostPort(opts.Host)
|
2020-02-17 17:19:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return u, err
|
|
|
|
}
|
2021-02-05 11:45:44 +00:00
|
|
|
u.Host = host
|
|
|
|
if port != "" {
|
|
|
|
u.Host = net.JoinHostPort(u.Host, port)
|
|
|
|
}
|
2020-02-17 17:19:15 +00:00
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return u, nil
|
|
|
|
}
|
|
|
|
|
2022-12-23 10:55:08 +00:00
|
|
|
func (api *API) scrapePools(r *http.Request) apiFuncResult {
|
|
|
|
names := api.scrapePoolsRetriever(r.Context()).ScrapePools()
|
|
|
|
sort.Strings(names)
|
|
|
|
res := &ScrapePoolsDiscovery{ScrapePools: names}
|
|
|
|
return apiFuncResult{data: res, err: nil, warnings: nil, finalizer: nil}
|
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
func (api *API) targets(r *http.Request) apiFuncResult {
|
2019-11-11 21:42:24 +00:00
|
|
|
sortKeys := func(targets map[string][]*scrape.Target) ([]string, int) {
|
2018-10-25 08:19:20 +00:00
|
|
|
var n int
|
|
|
|
keys := make([]string, 0, len(targets))
|
|
|
|
for k := range targets {
|
|
|
|
keys = append(keys, k)
|
|
|
|
n += len(targets[k])
|
|
|
|
}
|
2022-09-30 14:33:56 +00:00
|
|
|
slices.Sort(keys)
|
2019-11-11 21:42:24 +00:00
|
|
|
return keys, n
|
|
|
|
}
|
|
|
|
|
2022-12-23 10:55:08 +00:00
|
|
|
scrapePool := r.URL.Query().Get("scrapePool")
|
2019-11-11 21:42:24 +00:00
|
|
|
state := strings.ToLower(r.URL.Query().Get("state"))
|
|
|
|
showActive := state == "" || state == "any" || state == "active"
|
|
|
|
showDropped := state == "" || state == "any" || state == "dropped"
|
|
|
|
res := &TargetDiscovery{}
|
|
|
|
|
|
|
|
if showActive {
|
2020-04-16 08:30:47 +00:00
|
|
|
targetsActive := api.targetRetriever(r.Context()).TargetsActive()
|
2019-11-11 21:42:24 +00:00
|
|
|
activeKeys, numTargets := sortKeys(targetsActive)
|
|
|
|
res.ActiveTargets = make([]*Target, 0, numTargets)
|
2023-04-16 12:15:13 +00:00
|
|
|
builder := labels.NewScratchBuilder(0)
|
2019-11-11 21:42:24 +00:00
|
|
|
|
|
|
|
for _, key := range activeKeys {
|
2022-12-23 10:55:08 +00:00
|
|
|
if scrapePool != "" && key != scrapePool {
|
|
|
|
continue
|
|
|
|
}
|
2019-11-11 21:42:24 +00:00
|
|
|
for _, target := range targetsActive[key] {
|
|
|
|
lastErrStr := ""
|
|
|
|
lastErr := target.LastError()
|
|
|
|
if lastErr != nil {
|
|
|
|
lastErrStr = lastErr.Error()
|
|
|
|
}
|
|
|
|
|
2020-02-17 17:19:15 +00:00
|
|
|
globalURL, err := getGlobalURL(target.URL(), api.globalURLOptions)
|
|
|
|
|
2019-11-11 21:42:24 +00:00
|
|
|
res.ActiveTargets = append(res.ActiveTargets, &Target{
|
2024-01-29 10:19:02 +00:00
|
|
|
DiscoveredLabels: target.DiscoveredLabels(),
|
2023-04-16 12:15:13 +00:00
|
|
|
Labels: target.Labels(&builder),
|
2020-02-17 17:19:15 +00:00
|
|
|
ScrapePool: key,
|
|
|
|
ScrapeURL: target.URL().String(),
|
|
|
|
GlobalURL: globalURL.String(),
|
|
|
|
LastError: func() string {
|
style: Replace `else if` cascades with `switch`
Wiser coders than myself have come to the conclusion that a `switch`
statement is almost always superior to a statement that includes any
`else if`.
The exceptions that I have found in our codebase are just these two:
* The `if else` is followed by an additional statement before the next
condition (separated by a `;`).
* The whole thing is within a `for` loop and `break` statements are
used. In this case, using `switch` would require tagging the `for`
loop, which probably tips the balance.
Why are `switch` statements more readable?
For one, fewer curly braces. But more importantly, the conditions all
have the same alignment, so the whole thing follows the natural flow
of going down a list of conditions. With `else if`, in contrast, all
conditions but the first are "hidden" behind `} else if `, harder to
spot and (for no good reason) presented differently from the first
condition.
I'm sure the aforemention wise coders can list even more reasons.
In any case, I like it so much that I have found myself recommending
it in code reviews. I would like to make it a habit in our code base,
without making it a hard requirement that we would test on the CI. But
for that, there has to be a role model, so this commit eliminates all
`if else` occurrences, unless it is autogenerated code or fits one of
the exceptions above.
Signed-off-by: beorn7 <beorn@grafana.com>
2023-04-12 14:14:31 +00:00
|
|
|
switch {
|
|
|
|
case err == nil && lastErrStr == "":
|
2020-02-17 17:19:15 +00:00
|
|
|
return ""
|
style: Replace `else if` cascades with `switch`
Wiser coders than myself have come to the conclusion that a `switch`
statement is almost always superior to a statement that includes any
`else if`.
The exceptions that I have found in our codebase are just these two:
* The `if else` is followed by an additional statement before the next
condition (separated by a `;`).
* The whole thing is within a `for` loop and `break` statements are
used. In this case, using `switch` would require tagging the `for`
loop, which probably tips the balance.
Why are `switch` statements more readable?
For one, fewer curly braces. But more importantly, the conditions all
have the same alignment, so the whole thing follows the natural flow
of going down a list of conditions. With `else if`, in contrast, all
conditions but the first are "hidden" behind `} else if `, harder to
spot and (for no good reason) presented differently from the first
condition.
I'm sure the aforemention wise coders can list even more reasons.
In any case, I like it so much that I have found myself recommending
it in code reviews. I would like to make it a habit in our code base,
without making it a hard requirement that we would test on the CI. But
for that, there has to be a role model, so this commit eliminates all
`if else` occurrences, unless it is autogenerated code or fits one of
the exceptions above.
Signed-off-by: beorn7 <beorn@grafana.com>
2023-04-12 14:14:31 +00:00
|
|
|
case err != nil:
|
2023-11-08 03:49:39 +00:00
|
|
|
return fmt.Errorf("%s: %w", lastErrStr, err).Error()
|
style: Replace `else if` cascades with `switch`
Wiser coders than myself have come to the conclusion that a `switch`
statement is almost always superior to a statement that includes any
`else if`.
The exceptions that I have found in our codebase are just these two:
* The `if else` is followed by an additional statement before the next
condition (separated by a `;`).
* The whole thing is within a `for` loop and `break` statements are
used. In this case, using `switch` would require tagging the `for`
loop, which probably tips the balance.
Why are `switch` statements more readable?
For one, fewer curly braces. But more importantly, the conditions all
have the same alignment, so the whole thing follows the natural flow
of going down a list of conditions. With `else if`, in contrast, all
conditions but the first are "hidden" behind `} else if `, harder to
spot and (for no good reason) presented differently from the first
condition.
I'm sure the aforemention wise coders can list even more reasons.
In any case, I like it so much that I have found myself recommending
it in code reviews. I would like to make it a habit in our code base,
without making it a hard requirement that we would test on the CI. But
for that, there has to be a role model, so this commit eliminates all
`if else` occurrences, unless it is autogenerated code or fits one of
the exceptions above.
Signed-off-by: beorn7 <beorn@grafana.com>
2023-04-12 14:14:31 +00:00
|
|
|
default:
|
|
|
|
return lastErrStr
|
2020-02-17 17:19:15 +00:00
|
|
|
}
|
|
|
|
}(),
|
2019-11-11 21:42:24 +00:00
|
|
|
LastScrape: target.LastScrape(),
|
|
|
|
LastScrapeDuration: target.LastScrapeDuration().Seconds(),
|
|
|
|
Health: target.Health(),
|
2021-08-31 15:37:32 +00:00
|
|
|
ScrapeInterval: target.GetValue(model.ScrapeIntervalLabel),
|
|
|
|
ScrapeTimeout: target.GetValue(model.ScrapeTimeoutLabel),
|
2019-11-11 21:42:24 +00:00
|
|
|
})
|
|
|
|
}
|
2018-02-21 17:26:18 +00:00
|
|
|
}
|
2019-11-11 21:42:24 +00:00
|
|
|
} else {
|
|
|
|
res.ActiveTargets = []*Target{}
|
|
|
|
}
|
2023-08-14 14:39:25 +00:00
|
|
|
if showDropped {
|
|
|
|
res.DroppedTargetCounts = api.targetRetriever(r.Context()).TargetsDroppedCounts()
|
|
|
|
}
|
2019-11-11 21:42:24 +00:00
|
|
|
if showDropped {
|
2022-12-23 10:55:08 +00:00
|
|
|
targetsDropped := api.targetRetriever(r.Context()).TargetsDropped()
|
|
|
|
droppedKeys, numTargets := sortKeys(targetsDropped)
|
|
|
|
res.DroppedTargets = make([]*DroppedTarget, 0, numTargets)
|
|
|
|
for _, key := range droppedKeys {
|
|
|
|
if scrapePool != "" && key != scrapePool {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, target := range targetsDropped[key] {
|
|
|
|
res.DroppedTargets = append(res.DroppedTargets, &DroppedTarget{
|
2024-01-29 10:20:20 +00:00
|
|
|
DiscoveredLabels: target.DiscoveredLabels(),
|
2022-12-23 10:55:08 +00:00
|
|
|
})
|
|
|
|
}
|
2019-11-11 21:42:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res.DroppedTargets = []*DroppedTarget{}
|
2018-02-21 17:26:18 +00:00
|
|
|
}
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{res, nil, nil, nil}
|
2016-12-02 12:31:43 +00:00
|
|
|
}
|
|
|
|
|
2018-11-08 14:11:38 +00:00
|
|
|
func matchLabels(lset labels.Labels, matchers []*labels.Matcher) bool {
|
|
|
|
for _, m := range matchers {
|
|
|
|
if !m.Matches(lset.Get(m.Name)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
func (api *API) targetMetadata(r *http.Request) apiFuncResult {
|
2018-05-18 07:32:11 +00:00
|
|
|
limit := -1
|
|
|
|
if s := r.FormValue("limit"); s != "" {
|
|
|
|
var err error
|
|
|
|
if limit, err = strconv.Atoi(s); err != nil {
|
2019-03-25 23:01:12 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, errors.New("limit must be a number")}, nil, nil}
|
2018-05-18 07:32:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 11:09:44 +00:00
|
|
|
matchTarget := r.FormValue("match_target")
|
|
|
|
var matchers []*labels.Matcher
|
|
|
|
var err error
|
|
|
|
if matchTarget != "" {
|
2020-02-03 18:06:39 +00:00
|
|
|
matchers, err = parser.ParseMetricSelector(matchTarget)
|
2019-11-14 11:09:44 +00:00
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "match_target")
|
2019-11-14 11:09:44 +00:00
|
|
|
}
|
2018-05-18 07:32:11 +00:00
|
|
|
}
|
|
|
|
|
2023-04-16 12:15:13 +00:00
|
|
|
builder := labels.NewScratchBuilder(0)
|
2018-06-05 10:30:19 +00:00
|
|
|
metric := r.FormValue("metric")
|
2019-12-10 14:56:16 +00:00
|
|
|
res := []metricMetadata{}
|
2020-04-16 08:30:47 +00:00
|
|
|
for _, tt := range api.targetRetriever(r.Context()).TargetsActive() {
|
2018-09-26 09:20:56 +00:00
|
|
|
for _, t := range tt {
|
|
|
|
if limit >= 0 && len(res) >= limit {
|
|
|
|
break
|
2018-05-18 07:32:11 +00:00
|
|
|
}
|
2023-04-16 12:15:13 +00:00
|
|
|
targetLabels := t.Labels(&builder)
|
2018-11-08 14:11:38 +00:00
|
|
|
// Filter targets that don't satisfy the label matchers.
|
2023-04-16 12:15:13 +00:00
|
|
|
if matchTarget != "" && !matchLabels(targetLabels, matchers) {
|
2018-11-08 14:11:38 +00:00
|
|
|
continue
|
2018-09-26 09:20:56 +00:00
|
|
|
}
|
|
|
|
// If no metric is specified, get the full list for the target.
|
|
|
|
if metric == "" {
|
2023-11-22 18:50:57 +00:00
|
|
|
for _, md := range t.ListMetadata() {
|
2018-09-26 09:20:56 +00:00
|
|
|
res = append(res, metricMetadata{
|
2023-04-16 12:15:13 +00:00
|
|
|
Target: targetLabels,
|
2018-09-26 09:20:56 +00:00
|
|
|
Metric: md.Metric,
|
|
|
|
Type: md.Type,
|
|
|
|
Help: md.Help,
|
2018-10-05 16:11:16 +00:00
|
|
|
Unit: md.Unit,
|
2018-09-26 09:20:56 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Get metadata for the specified metric.
|
2023-11-22 18:50:57 +00:00
|
|
|
if md, ok := t.GetMetadata(metric); ok {
|
2018-05-18 07:32:11 +00:00
|
|
|
res = append(res, metricMetadata{
|
2023-04-16 12:15:13 +00:00
|
|
|
Target: targetLabels,
|
2018-05-18 07:32:11 +00:00
|
|
|
Type: md.Type,
|
|
|
|
Help: md.Help,
|
2018-10-05 16:11:16 +00:00
|
|
|
Unit: md.Unit,
|
2018-05-18 07:32:11 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-10 14:56:16 +00:00
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{res, nil, nil, nil}
|
2018-05-18 07:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type metricMetadata struct {
|
2023-11-22 14:39:21 +00:00
|
|
|
Target labels.Labels `json:"target"`
|
|
|
|
Metric string `json:"metric,omitempty"`
|
|
|
|
Type model.MetricType `json:"type"`
|
|
|
|
Help string `json:"help"`
|
|
|
|
Unit string `json:"unit"`
|
2018-05-18 07:32:11 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 17:51:27 +00:00
|
|
|
// AlertmanagerDiscovery has all the active Alertmanagers.
|
2017-01-13 09:20:11 +00:00
|
|
|
type AlertmanagerDiscovery struct {
|
2018-02-21 09:00:07 +00:00
|
|
|
ActiveAlertmanagers []*AlertmanagerTarget `json:"activeAlertmanagers"`
|
|
|
|
DroppedAlertmanagers []*AlertmanagerTarget `json:"droppedAlertmanagers"`
|
2017-01-13 09:20:11 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 17:51:27 +00:00
|
|
|
// AlertmanagerTarget has info on one AM.
|
2017-01-13 09:20:11 +00:00
|
|
|
type AlertmanagerTarget struct {
|
|
|
|
URL string `json:"url"`
|
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
func (api *API) alertmanagers(r *http.Request) apiFuncResult {
|
2020-05-18 18:02:32 +00:00
|
|
|
urls := api.alertmanagerRetriever(r.Context()).Alertmanagers()
|
|
|
|
droppedURLS := api.alertmanagerRetriever(r.Context()).DroppedAlertmanagers()
|
2018-02-21 09:00:07 +00:00
|
|
|
ams := &AlertmanagerDiscovery{ActiveAlertmanagers: make([]*AlertmanagerTarget, len(urls)), DroppedAlertmanagers: make([]*AlertmanagerTarget, len(droppedURLS))}
|
2017-04-25 05:42:33 +00:00
|
|
|
for i, url := range urls {
|
|
|
|
ams.ActiveAlertmanagers[i] = &AlertmanagerTarget{URL: url.String()}
|
2017-01-13 09:20:11 +00:00
|
|
|
}
|
2018-02-21 09:00:07 +00:00
|
|
|
for i, url := range droppedURLS {
|
|
|
|
ams.DroppedAlertmanagers[i] = &AlertmanagerTarget{URL: url.String()}
|
|
|
|
}
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{ams, nil, nil, nil}
|
2017-01-13 09:20:11 +00:00
|
|
|
}
|
|
|
|
|
2018-06-27 07:15:17 +00:00
|
|
|
// AlertDiscovery has info for all active alerts.
|
2018-03-25 16:50:34 +00:00
|
|
|
type AlertDiscovery struct {
|
2018-06-27 07:15:17 +00:00
|
|
|
Alerts []*Alert `json:"alerts"`
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
|
|
|
|
2018-06-27 07:15:17 +00:00
|
|
|
// Alert has info for an alert.
|
2018-03-25 16:50:34 +00:00
|
|
|
type Alert struct {
|
2023-01-09 11:21:38 +00:00
|
|
|
Labels labels.Labels `json:"labels"`
|
|
|
|
Annotations labels.Labels `json:"annotations"`
|
|
|
|
State string `json:"state"`
|
|
|
|
ActiveAt *time.Time `json:"activeAt,omitempty"`
|
2023-01-19 10:33:54 +00:00
|
|
|
KeepFiringSince *time.Time `json:"keepFiringSince,omitempty"`
|
2023-01-09 11:21:38 +00:00
|
|
|
Value string `json:"value"`
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
func (api *API) alerts(r *http.Request) apiFuncResult {
|
2020-05-18 18:02:32 +00:00
|
|
|
alertingRules := api.rulesRetriever(r.Context()).AlertingRules()
|
2018-06-27 07:15:17 +00:00
|
|
|
alerts := []*Alert{}
|
2018-03-25 16:50:34 +00:00
|
|
|
|
2018-06-27 07:15:17 +00:00
|
|
|
for _, alertingRule := range alertingRules {
|
|
|
|
alerts = append(
|
|
|
|
alerts,
|
|
|
|
rulesAlertsToAPIAlerts(alertingRule.ActiveAlerts())...,
|
|
|
|
)
|
|
|
|
}
|
2018-03-25 16:50:34 +00:00
|
|
|
|
2018-06-27 07:15:17 +00:00
|
|
|
res := &AlertDiscovery{Alerts: alerts}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{res, nil, nil, nil}
|
2018-06-27 07:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func rulesAlertsToAPIAlerts(rulesAlerts []*rules.Alert) []*Alert {
|
|
|
|
apiAlerts := make([]*Alert, len(rulesAlerts))
|
|
|
|
for i, ruleAlert := range rulesAlerts {
|
|
|
|
apiAlerts[i] = &Alert{
|
2023-01-19 10:33:54 +00:00
|
|
|
Labels: ruleAlert.Labels,
|
|
|
|
Annotations: ruleAlert.Annotations,
|
|
|
|
State: ruleAlert.State.String(),
|
|
|
|
ActiveAt: &ruleAlert.ActiveAt,
|
|
|
|
Value: strconv.FormatFloat(ruleAlert.Value, 'e', -1, 64),
|
|
|
|
}
|
|
|
|
if !ruleAlert.KeepFiringSince.IsZero() {
|
|
|
|
apiAlerts[i].KeepFiringSince = &ruleAlert.KeepFiringSince
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-27 07:15:17 +00:00
|
|
|
return apiAlerts
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 14:56:16 +00:00
|
|
|
func (api *API) metricMetadata(r *http.Request) apiFuncResult {
|
2023-11-22 14:39:21 +00:00
|
|
|
metrics := map[string]map[metadata.Metadata]struct{}{}
|
2019-12-10 14:56:16 +00:00
|
|
|
|
|
|
|
limit := -1
|
|
|
|
if s := r.FormValue("limit"); s != "" {
|
|
|
|
var err error
|
|
|
|
if limit, err = strconv.Atoi(s); err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, errors.New("limit must be a number")}, nil, nil}
|
|
|
|
}
|
|
|
|
}
|
2023-06-12 15:17:20 +00:00
|
|
|
limitPerMetric := -1
|
|
|
|
if s := r.FormValue("limit_per_metric"); s != "" {
|
|
|
|
var err error
|
|
|
|
if limitPerMetric, err = strconv.Atoi(s); err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, errors.New("limit_per_metric must be a number")}, nil, nil}
|
|
|
|
}
|
|
|
|
}
|
2019-12-10 14:56:16 +00:00
|
|
|
|
2019-12-10 15:22:10 +00:00
|
|
|
metric := r.FormValue("metric")
|
2020-04-16 08:30:47 +00:00
|
|
|
for _, tt := range api.targetRetriever(r.Context()).TargetsActive() {
|
2019-12-10 14:56:16 +00:00
|
|
|
for _, t := range tt {
|
2019-12-10 15:22:10 +00:00
|
|
|
if metric == "" {
|
2023-11-22 18:50:57 +00:00
|
|
|
for _, mm := range t.ListMetadata() {
|
2023-11-22 14:39:21 +00:00
|
|
|
m := metadata.Metadata{Type: mm.Type, Help: mm.Help, Unit: mm.Unit}
|
2019-12-10 15:22:10 +00:00
|
|
|
ms, ok := metrics[mm.Metric]
|
|
|
|
|
2023-06-12 15:17:20 +00:00
|
|
|
if limitPerMetric > 0 && len(ms) >= limitPerMetric {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-12-10 15:22:10 +00:00
|
|
|
if !ok {
|
2023-11-22 14:39:21 +00:00
|
|
|
ms = map[metadata.Metadata]struct{}{}
|
2019-12-10 15:22:10 +00:00
|
|
|
metrics[mm.Metric] = ms
|
|
|
|
}
|
|
|
|
ms[m] = struct{}{}
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-11-22 18:50:57 +00:00
|
|
|
if md, ok := t.GetMetadata(metric); ok {
|
2023-11-22 14:39:21 +00:00
|
|
|
m := metadata.Metadata{Type: md.Type, Help: md.Help, Unit: md.Unit}
|
2019-12-10 15:22:10 +00:00
|
|
|
ms, ok := metrics[md.Metric]
|
2019-12-10 14:56:16 +00:00
|
|
|
|
2023-06-12 15:17:20 +00:00
|
|
|
if limitPerMetric > 0 && len(ms) >= limitPerMetric {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-12-10 14:56:16 +00:00
|
|
|
if !ok {
|
2023-11-22 14:39:21 +00:00
|
|
|
ms = map[metadata.Metadata]struct{}{}
|
2019-12-10 15:22:10 +00:00
|
|
|
metrics[md.Metric] = ms
|
2019-12-10 14:56:16 +00:00
|
|
|
}
|
|
|
|
ms[m] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-10 15:22:10 +00:00
|
|
|
// Put the elements from the pseudo-set into a slice for marshaling.
|
2023-11-22 14:39:21 +00:00
|
|
|
res := map[string][]metadata.Metadata{}
|
2019-12-10 14:56:16 +00:00
|
|
|
for name, set := range metrics {
|
|
|
|
if limit >= 0 && len(res) >= limit {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2023-11-22 14:39:21 +00:00
|
|
|
s := []metadata.Metadata{}
|
2019-12-10 14:56:16 +00:00
|
|
|
for metadata := range set {
|
|
|
|
s = append(s, metadata)
|
|
|
|
}
|
|
|
|
res[name] = s
|
|
|
|
}
|
|
|
|
|
|
|
|
return apiFuncResult{res, nil, nil, nil}
|
|
|
|
}
|
|
|
|
|
2023-10-03 20:09:25 +00:00
|
|
|
// RuleDiscovery has info for all rules.
|
2018-06-27 07:15:17 +00:00
|
|
|
type RuleDiscovery struct {
|
|
|
|
RuleGroups []*RuleGroup `json:"groups"`
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
|
|
|
|
2023-10-03 20:09:25 +00:00
|
|
|
// RuleGroup has info for rules which are part of a group.
|
2018-06-27 07:15:17 +00:00
|
|
|
type RuleGroup struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
File string `json:"file"`
|
|
|
|
// In order to preserve rule ordering, while exposing type (alerting or recording)
|
|
|
|
// specific properties, both alerting and recording rules are exposed in the
|
|
|
|
// same array.
|
2021-11-21 17:00:27 +00:00
|
|
|
Rules []Rule `json:"rules"`
|
2020-01-27 09:27:43 +00:00
|
|
|
Interval float64 `json:"interval"`
|
2022-01-12 03:44:22 +00:00
|
|
|
Limit int `json:"limit"`
|
2020-01-27 09:27:43 +00:00
|
|
|
EvaluationTime float64 `json:"evaluationTime"`
|
|
|
|
LastEvaluation time.Time `json:"lastEvaluation"`
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
|
|
|
|
2021-11-21 17:00:27 +00:00
|
|
|
type Rule interface{}
|
2018-03-25 16:50:34 +00:00
|
|
|
|
2021-11-21 17:00:27 +00:00
|
|
|
type AlertingRule struct {
|
2019-12-09 22:42:59 +00:00
|
|
|
// State can be "pending", "firing", "inactive".
|
2020-01-27 09:27:43 +00:00
|
|
|
State string `json:"state"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Query string `json:"query"`
|
|
|
|
Duration float64 `json:"duration"`
|
2023-01-09 11:21:38 +00:00
|
|
|
KeepFiringFor float64 `json:"keepFiringFor"`
|
2020-01-27 09:27:43 +00:00
|
|
|
Labels labels.Labels `json:"labels"`
|
|
|
|
Annotations labels.Labels `json:"annotations"`
|
|
|
|
Alerts []*Alert `json:"alerts"`
|
|
|
|
Health rules.RuleHealth `json:"health"`
|
|
|
|
LastError string `json:"lastError,omitempty"`
|
|
|
|
EvaluationTime float64 `json:"evaluationTime"`
|
|
|
|
LastEvaluation time.Time `json:"lastEvaluation"`
|
2018-06-27 07:15:17 +00:00
|
|
|
// Type of an alertingRule is always "alerting".
|
|
|
|
Type string `json:"type"`
|
|
|
|
}
|
|
|
|
|
2021-11-21 17:00:27 +00:00
|
|
|
type RecordingRule struct {
|
2020-01-27 09:27:43 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Query string `json:"query"`
|
|
|
|
Labels labels.Labels `json:"labels,omitempty"`
|
|
|
|
Health rules.RuleHealth `json:"health"`
|
|
|
|
LastError string `json:"lastError,omitempty"`
|
|
|
|
EvaluationTime float64 `json:"evaluationTime"`
|
|
|
|
LastEvaluation time.Time `json:"lastEvaluation"`
|
2018-06-27 07:15:17 +00:00
|
|
|
// Type of a recordingRule is always "recording".
|
|
|
|
Type string `json:"type"`
|
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
func (api *API) rules(r *http.Request) apiFuncResult {
|
2023-04-18 15:26:21 +00:00
|
|
|
if err := r.ParseForm(); err != nil {
|
2023-11-08 03:49:39 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, fmt.Errorf("error parsing form values: %w", err)}, nil, nil}
|
2023-04-18 15:26:21 +00:00
|
|
|
}
|
2019-12-09 22:42:59 +00:00
|
|
|
|
2023-04-18 15:26:21 +00:00
|
|
|
queryFormToSet := func(values []string) map[string]struct{} {
|
|
|
|
set := make(map[string]struct{}, len(values))
|
|
|
|
for _, v := range values {
|
|
|
|
set[v] = struct{}{}
|
2023-04-18 09:07:32 +00:00
|
|
|
}
|
2023-04-18 15:26:21 +00:00
|
|
|
return set
|
2023-04-18 09:07:32 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 15:26:21 +00:00
|
|
|
rnSet := queryFormToSet(r.Form["rule_name[]"])
|
|
|
|
rgSet := queryFormToSet(r.Form["rule_group[]"])
|
|
|
|
fSet := queryFormToSet(r.Form["file[]"])
|
|
|
|
|
2024-07-10 12:18:29 +00:00
|
|
|
matcherSets, err := parseMatchersParam(r.Form["match[]"])
|
|
|
|
if err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
|
|
|
}
|
|
|
|
|
2020-05-18 18:02:32 +00:00
|
|
|
ruleGroups := api.rulesRetriever(r.Context()).RuleGroups()
|
2023-04-20 10:20:10 +00:00
|
|
|
res := &RuleDiscovery{RuleGroups: make([]*RuleGroup, 0, len(ruleGroups))}
|
2020-12-24 00:27:13 +00:00
|
|
|
typ := strings.ToLower(r.URL.Query().Get("type"))
|
2019-12-09 22:42:59 +00:00
|
|
|
|
2020-12-24 00:27:13 +00:00
|
|
|
if typ != "" && typ != "alert" && typ != "record" {
|
2023-11-08 03:49:39 +00:00
|
|
|
return invalidParamError(fmt.Errorf("not supported value %q", typ), "type")
|
2019-12-09 22:42:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 00:27:13 +00:00
|
|
|
returnAlerts := typ == "" || typ == "alert"
|
|
|
|
returnRecording := typ == "" || typ == "record"
|
2019-12-09 22:42:59 +00:00
|
|
|
|
2023-10-18 02:02:03 +00:00
|
|
|
excludeAlerts, err := parseExcludeAlerts(r)
|
|
|
|
if err != nil {
|
|
|
|
return invalidParamError(err, "exclude_alerts")
|
|
|
|
}
|
|
|
|
|
2023-04-20 10:20:10 +00:00
|
|
|
rgs := make([]*RuleGroup, 0, len(ruleGroups))
|
|
|
|
for _, grp := range ruleGroups {
|
2023-04-18 15:26:21 +00:00
|
|
|
if len(rgSet) > 0 {
|
|
|
|
if _, ok := rgSet[grp.Name()]; !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(fSet) > 0 {
|
|
|
|
if _, ok := fSet[grp.File()]; !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-27 07:15:17 +00:00
|
|
|
apiRuleGroup := &RuleGroup{
|
2020-01-27 09:27:43 +00:00
|
|
|
Name: grp.Name(),
|
|
|
|
File: grp.File(),
|
|
|
|
Interval: grp.Interval().Seconds(),
|
2022-01-12 03:44:22 +00:00
|
|
|
Limit: grp.Limit(),
|
2021-11-21 17:00:27 +00:00
|
|
|
Rules: []Rule{},
|
2020-08-25 10:38:06 +00:00
|
|
|
EvaluationTime: grp.GetEvaluationTime().Seconds(),
|
|
|
|
LastEvaluation: grp.GetLastEvaluation(),
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
2024-07-10 12:18:29 +00:00
|
|
|
|
|
|
|
for _, rr := range grp.Rules(matcherSets...) {
|
2021-11-21 17:00:27 +00:00
|
|
|
var enrichedRule Rule
|
2018-06-27 07:15:17 +00:00
|
|
|
|
2023-04-18 15:26:21 +00:00
|
|
|
if len(rnSet) > 0 {
|
|
|
|
if _, ok := rnSet[rr.Name()]; !ok {
|
2023-04-18 09:07:32 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-23 13:00:10 +00:00
|
|
|
lastError := ""
|
2023-04-18 09:07:32 +00:00
|
|
|
if rr.LastError() != nil {
|
|
|
|
lastError = rr.LastError().Error()
|
2018-08-23 13:00:10 +00:00
|
|
|
}
|
2023-04-18 09:07:32 +00:00
|
|
|
switch rule := rr.(type) {
|
2018-06-27 07:15:17 +00:00
|
|
|
case *rules.AlertingRule:
|
2019-12-09 22:42:59 +00:00
|
|
|
if !returnAlerts {
|
|
|
|
break
|
|
|
|
}
|
2023-10-18 02:02:03 +00:00
|
|
|
var activeAlerts []*Alert
|
|
|
|
if !excludeAlerts {
|
|
|
|
activeAlerts = rulesAlertsToAPIAlerts(rule.ActiveAlerts())
|
|
|
|
}
|
2021-11-21 17:00:27 +00:00
|
|
|
enrichedRule = AlertingRule{
|
2020-01-27 09:27:43 +00:00
|
|
|
State: rule.State().String(),
|
|
|
|
Name: rule.Name(),
|
|
|
|
Query: rule.Query().String(),
|
2020-02-01 07:31:37 +00:00
|
|
|
Duration: rule.HoldDuration().Seconds(),
|
2023-01-09 11:21:38 +00:00
|
|
|
KeepFiringFor: rule.KeepFiringFor().Seconds(),
|
2020-01-27 09:27:43 +00:00
|
|
|
Labels: rule.Labels(),
|
|
|
|
Annotations: rule.Annotations(),
|
2023-10-18 02:02:03 +00:00
|
|
|
Alerts: activeAlerts,
|
2020-01-27 09:27:43 +00:00
|
|
|
Health: rule.Health(),
|
|
|
|
LastError: lastError,
|
|
|
|
EvaluationTime: rule.GetEvaluationDuration().Seconds(),
|
|
|
|
LastEvaluation: rule.GetEvaluationTimestamp(),
|
|
|
|
Type: "alerting",
|
2018-06-27 07:15:17 +00:00
|
|
|
}
|
|
|
|
case *rules.RecordingRule:
|
2019-12-09 22:42:59 +00:00
|
|
|
if !returnRecording {
|
|
|
|
break
|
|
|
|
}
|
2021-11-21 17:00:27 +00:00
|
|
|
enrichedRule = RecordingRule{
|
2020-01-27 09:27:43 +00:00
|
|
|
Name: rule.Name(),
|
|
|
|
Query: rule.Query().String(),
|
|
|
|
Labels: rule.Labels(),
|
|
|
|
Health: rule.Health(),
|
|
|
|
LastError: lastError,
|
|
|
|
EvaluationTime: rule.GetEvaluationDuration().Seconds(),
|
|
|
|
LastEvaluation: rule.GetEvaluationTimestamp(),
|
|
|
|
Type: "recording",
|
2018-06-27 07:15:17 +00:00
|
|
|
}
|
|
|
|
default:
|
2023-11-08 03:49:39 +00:00
|
|
|
err := fmt.Errorf("failed to assert type of rule '%v'", rule.Name())
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorInternal, err}, nil, nil}
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
2023-04-18 09:07:32 +00:00
|
|
|
|
2019-12-09 22:42:59 +00:00
|
|
|
if enrichedRule != nil {
|
|
|
|
apiRuleGroup.Rules = append(apiRuleGroup.Rules, enrichedRule)
|
|
|
|
}
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
2023-04-18 09:07:32 +00:00
|
|
|
|
|
|
|
// If the rule group response has no rules, skip it - this means we filtered all the rules of this group.
|
|
|
|
if len(apiRuleGroup.Rules) > 0 {
|
2023-04-20 10:20:10 +00:00
|
|
|
rgs = append(rgs, apiRuleGroup)
|
2023-04-18 09:07:32 +00:00
|
|
|
}
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
2023-04-20 10:20:10 +00:00
|
|
|
res.RuleGroups = rgs
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{res, nil, nil, nil}
|
2018-03-25 16:50:34 +00:00
|
|
|
}
|
|
|
|
|
2023-10-18 02:02:03 +00:00
|
|
|
func parseExcludeAlerts(r *http.Request) (bool, error) {
|
|
|
|
excludeAlertsParam := strings.ToLower(r.URL.Query().Get("exclude_alerts"))
|
|
|
|
|
|
|
|
if excludeAlertsParam == "" {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
excludeAlerts, err := strconv.ParseBool(excludeAlertsParam)
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("error converting exclude_alerts: %w", err)
|
|
|
|
}
|
|
|
|
return excludeAlerts, nil
|
|
|
|
}
|
|
|
|
|
2017-05-11 15:09:24 +00:00
|
|
|
type prometheusConfig struct {
|
|
|
|
YAML string `json:"yaml"`
|
|
|
|
}
|
|
|
|
|
2020-12-24 00:27:13 +00:00
|
|
|
func (api *API) serveRuntimeInfo(_ *http.Request) apiFuncResult {
|
2019-11-02 15:53:32 +00:00
|
|
|
status, err := api.runtimeInfo()
|
|
|
|
if err != nil {
|
|
|
|
return apiFuncResult{status, &apiError{errorInternal, err}, nil, nil}
|
|
|
|
}
|
|
|
|
return apiFuncResult{status, nil, nil, nil}
|
|
|
|
}
|
|
|
|
|
2020-12-24 00:27:13 +00:00
|
|
|
func (api *API) serveBuildInfo(_ *http.Request) apiFuncResult {
|
2019-11-02 15:53:32 +00:00
|
|
|
return apiFuncResult{api.buildInfo, nil, nil, nil}
|
|
|
|
}
|
|
|
|
|
2020-12-24 00:27:13 +00:00
|
|
|
func (api *API) serveConfig(_ *http.Request) apiFuncResult {
|
2017-05-11 15:09:24 +00:00
|
|
|
cfg := &prometheusConfig{
|
|
|
|
YAML: api.config().String(),
|
|
|
|
}
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{cfg, nil, nil, nil}
|
2017-05-11 15:09:24 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 00:27:13 +00:00
|
|
|
func (api *API) serveFlags(_ *http.Request) apiFuncResult {
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{api.flagsMap, nil, nil, nil}
|
api: Added v1/status/flags endpoint. (#3864)
Endpoint URL: /api/v1/status/flags
Example Output:
```json
{
"status": "success",
"data": {
"alertmanager.notification-queue-capacity": "10000",
"alertmanager.timeout": "10s",
"completion-bash": "false",
"completion-script-bash": "false",
"completion-script-zsh": "false",
"config.file": "my_cool_prometheus.yaml",
"help": "false",
"help-long": "false",
"help-man": "false",
"log.level": "info",
"query.lookback-delta": "5m",
"query.max-concurrency": "20",
"query.timeout": "2m",
"storage.tsdb.max-block-duration": "36h",
"storage.tsdb.min-block-duration": "2h",
"storage.tsdb.no-lockfile": "false",
"storage.tsdb.path": "data/",
"storage.tsdb.retention": "15d",
"version": "false",
"web.console.libraries": "console_libraries",
"web.console.templates": "consoles",
"web.enable-admin-api": "false",
"web.enable-lifecycle": "false",
"web.external-url": "",
"web.listen-address": "0.0.0.0:9090",
"web.max-connections": "512",
"web.read-timeout": "5m",
"web.route-prefix": "/",
"web.user-assets": ""
}
}
```
Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
2018-02-21 08:49:02 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 15:13:21 +00:00
|
|
|
// TSDBStat holds the information about individual cardinality.
|
|
|
|
type TSDBStat struct {
|
2019-11-12 10:15:20 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Value uint64 `json:"value"`
|
|
|
|
}
|
|
|
|
|
2020-09-29 20:05:33 +00:00
|
|
|
// HeadStats has information about the TSDB head.
|
|
|
|
type HeadStats struct {
|
2021-01-07 06:41:32 +00:00
|
|
|
NumSeries uint64 `json:"numSeries"`
|
|
|
|
NumLabelPairs int `json:"numLabelPairs"`
|
|
|
|
ChunkCount int64 `json:"chunkCount"`
|
|
|
|
MinTime int64 `json:"minTime"`
|
|
|
|
MaxTime int64 `json:"maxTime"`
|
2020-09-29 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 15:13:21 +00:00
|
|
|
// TSDBStatus has information of cardinality statistics from postings.
|
|
|
|
type TSDBStatus struct {
|
|
|
|
HeadStats HeadStats `json:"headStats"`
|
|
|
|
SeriesCountByMetricName []TSDBStat `json:"seriesCountByMetricName"`
|
|
|
|
LabelValueCountByLabelName []TSDBStat `json:"labelValueCountByLabelName"`
|
|
|
|
MemoryInBytesByLabelName []TSDBStat `json:"memoryInBytesByLabelName"`
|
|
|
|
SeriesCountByLabelValuePair []TSDBStat `json:"seriesCountByLabelValuePair"`
|
2019-11-12 10:15:20 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 15:13:21 +00:00
|
|
|
// TSDBStatsFromIndexStats converts a index.Stat slice to a TSDBStat slice.
|
|
|
|
func TSDBStatsFromIndexStats(stats []index.Stat) []TSDBStat {
|
|
|
|
result := make([]TSDBStat, 0, len(stats))
|
2020-04-29 16:16:14 +00:00
|
|
|
for _, item := range stats {
|
2022-06-07 15:13:21 +00:00
|
|
|
item := TSDBStat{Name: item.Name, Value: item.Count}
|
2020-04-29 16:16:14 +00:00
|
|
|
result = append(result, item)
|
2019-11-12 10:15:20 +00:00
|
|
|
}
|
2020-04-29 16:16:14 +00:00
|
|
|
return result
|
|
|
|
}
|
2019-11-12 10:15:20 +00:00
|
|
|
|
2023-05-22 12:37:07 +00:00
|
|
|
func (api *API) serveTSDBStatus(r *http.Request) apiFuncResult {
|
|
|
|
limit := 10
|
|
|
|
if s := r.FormValue("limit"); s != "" {
|
|
|
|
var err error
|
|
|
|
if limit, err = strconv.Atoi(s); err != nil || limit < 1 {
|
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, errors.New("limit must be a positive number")}, nil, nil}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s, err := api.db.Stats(labels.MetricName, limit)
|
2020-04-29 16:16:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return apiFuncResult{nil, &apiError{errorInternal, err}, nil, nil}
|
2019-11-12 10:15:20 +00:00
|
|
|
}
|
2020-09-29 20:05:33 +00:00
|
|
|
metrics, err := api.gatherer.Gather()
|
|
|
|
if err != nil {
|
2023-11-08 03:49:39 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorInternal, fmt.Errorf("error gathering runtime status: %w", err)}, nil, nil}
|
2020-09-29 20:05:33 +00:00
|
|
|
}
|
|
|
|
chunkCount := int64(math.NaN())
|
|
|
|
for _, mF := range metrics {
|
|
|
|
if *mF.Name == "prometheus_tsdb_head_chunks" {
|
2023-06-07 10:29:04 +00:00
|
|
|
m := mF.Metric[0]
|
2020-09-29 20:05:33 +00:00
|
|
|
if m.Gauge != nil {
|
|
|
|
chunkCount = int64(m.Gauge.GetValue())
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-07 15:13:21 +00:00
|
|
|
return apiFuncResult{TSDBStatus{
|
2020-09-29 20:05:33 +00:00
|
|
|
HeadStats: HeadStats{
|
2021-01-07 06:41:32 +00:00
|
|
|
NumSeries: s.NumSeries,
|
|
|
|
ChunkCount: chunkCount,
|
|
|
|
MinTime: s.MinTime,
|
|
|
|
MaxTime: s.MaxTime,
|
|
|
|
NumLabelPairs: s.IndexPostingStats.NumLabelPairs,
|
2020-09-29 20:05:33 +00:00
|
|
|
},
|
2022-06-07 15:13:21 +00:00
|
|
|
SeriesCountByMetricName: TSDBStatsFromIndexStats(s.IndexPostingStats.CardinalityMetricsStats),
|
|
|
|
LabelValueCountByLabelName: TSDBStatsFromIndexStats(s.IndexPostingStats.CardinalityLabelStats),
|
|
|
|
MemoryInBytesByLabelName: TSDBStatsFromIndexStats(s.IndexPostingStats.LabelValueStats),
|
|
|
|
SeriesCountByLabelValuePair: TSDBStatsFromIndexStats(s.IndexPostingStats.LabelValuePairsStats),
|
2020-04-29 16:16:14 +00:00
|
|
|
}, nil, nil, nil}
|
2019-11-12 10:15:20 +00:00
|
|
|
}
|
|
|
|
|
2021-06-05 14:29:32 +00:00
|
|
|
type walReplayStatus struct {
|
|
|
|
Min int `json:"min"`
|
|
|
|
Max int `json:"max"`
|
|
|
|
Current int `json:"current"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API) serveWALReplayStatus(w http.ResponseWriter, r *http.Request) {
|
|
|
|
httputil.SetCORS(w, api.CORSOrigin, r)
|
|
|
|
status, err := api.db.WALReplayStatus()
|
|
|
|
if err != nil {
|
|
|
|
api.respondError(w, &apiError{errorInternal, err}, nil)
|
|
|
|
}
|
2023-01-25 03:30:47 +00:00
|
|
|
api.respond(w, r, walReplayStatus{
|
2021-06-05 14:29:32 +00:00
|
|
|
Min: status.Min,
|
|
|
|
Max: status.Max,
|
|
|
|
Current: status.Current,
|
2023-09-14 16:57:31 +00:00
|
|
|
}, nil, "")
|
2021-06-05 14:29:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-23 20:28:17 +00:00
|
|
|
func (api *API) remoteRead(w http.ResponseWriter, r *http.Request) {
|
2021-02-26 16:43:19 +00:00
|
|
|
// This is only really for tests - this will never be nil IRL.
|
|
|
|
if api.remoteReadHandler != nil {
|
|
|
|
api.remoteReadHandler.ServeHTTP(w, r)
|
|
|
|
} else {
|
|
|
|
http.Error(w, "not found", http.StatusNotFound)
|
2019-08-19 20:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 11:04:48 +00:00
|
|
|
func (api *API) remoteWrite(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if api.remoteWriteHandler != nil {
|
|
|
|
api.remoteWriteHandler.ServeHTTP(w, r)
|
|
|
|
} else {
|
2023-03-11 12:50:52 +00:00
|
|
|
http.Error(w, "remote write receiver needs to be enabled with --web.enable-remote-write-receiver", http.StatusNotFound)
|
2021-01-30 11:04:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-28 10:35:28 +00:00
|
|
|
func (api *API) otlpWrite(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if api.otlpWriteHandler != nil {
|
|
|
|
api.otlpWriteHandler.ServeHTTP(w, r)
|
|
|
|
} else {
|
|
|
|
http.Error(w, "otlp write receiver needs to be enabled with --enable-feature=otlp-write-receiver", http.StatusNotFound)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
func (api *API) deleteSeries(r *http.Request) apiFuncResult {
|
2017-12-03 05:07:05 +00:00
|
|
|
if !api.enableAdmin {
|
2019-01-04 13:47:38 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorUnavailable, errors.New("admin APIs disabled")}, nil, nil}
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
2018-08-17 15:24:35 +00:00
|
|
|
if err := r.ParseForm(); err != nil {
|
2023-11-08 03:49:39 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, fmt.Errorf("error parsing form values: %w", err)}, nil, nil}
|
2018-08-17 15:24:35 +00:00
|
|
|
}
|
2017-12-03 05:07:05 +00:00
|
|
|
if len(r.Form["match[]"]) == 0 {
|
2019-03-25 23:01:12 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorBadData, errors.New("no match[] parameter provided")}, nil, nil}
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 15:48:13 +00:00
|
|
|
start, err := parseTimeParam(r, "start", MinTime)
|
2020-03-06 10:33:01 +00:00
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "start")
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
2023-07-06 15:48:13 +00:00
|
|
|
end, err := parseTimeParam(r, "end", MaxTime)
|
2020-03-06 10:33:01 +00:00
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "end")
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range r.Form["match[]"] {
|
2020-02-03 18:06:39 +00:00
|
|
|
matchers, err := parser.ParseMetricSelector(s)
|
2017-12-03 05:07:05 +00:00
|
|
|
if err != nil {
|
2020-12-24 00:27:13 +00:00
|
|
|
return invalidParamError(err, "match[]")
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
2023-09-13 13:43:06 +00:00
|
|
|
if err := api.db.Delete(r.Context(), timestamp.FromTime(start), timestamp.FromTime(end), matchers...); err != nil {
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorInternal, err}, nil, nil}
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{nil, nil, nil, nil}
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
func (api *API) snapshot(r *http.Request) apiFuncResult {
|
2017-12-03 05:07:05 +00:00
|
|
|
if !api.enableAdmin {
|
2019-01-04 13:47:38 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorUnavailable, errors.New("admin APIs disabled")}, nil, nil}
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
2018-10-02 10:48:07 +00:00
|
|
|
var (
|
|
|
|
skipHead bool
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if r.FormValue("skip_head") != "" {
|
|
|
|
skipHead, err = strconv.ParseBool(r.FormValue("skip_head"))
|
|
|
|
if err != nil {
|
2023-11-08 03:49:39 +00:00
|
|
|
return invalidParamError(fmt.Errorf("unable to parse boolean: %w", err), "skip_head")
|
2018-10-02 10:48:07 +00:00
|
|
|
}
|
2018-08-17 15:24:35 +00:00
|
|
|
}
|
2018-03-08 10:43:41 +00:00
|
|
|
|
2017-12-03 05:07:05 +00:00
|
|
|
var (
|
2020-04-29 16:16:14 +00:00
|
|
|
snapdir = filepath.Join(api.dbDir, "snapshots")
|
2020-11-01 20:07:38 +00:00
|
|
|
name = fmt.Sprintf("%s-%016x",
|
2017-12-10 19:19:34 +00:00
|
|
|
time.Now().UTC().Format("20060102T150405Z0700"),
|
2020-11-01 20:07:38 +00:00
|
|
|
rand.Int63())
|
2017-12-10 19:19:34 +00:00
|
|
|
dir = filepath.Join(snapdir, name)
|
2017-12-03 05:07:05 +00:00
|
|
|
)
|
2021-10-22 08:06:44 +00:00
|
|
|
if err := os.MkdirAll(dir, 0o777); err != nil {
|
2023-11-08 03:49:39 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorInternal, fmt.Errorf("create snapshot directory: %w", err)}, nil, nil}
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
2020-04-29 16:16:14 +00:00
|
|
|
if err := api.db.Snapshot(dir, !skipHead); err != nil {
|
2023-11-08 03:49:39 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorInternal, fmt.Errorf("create snapshot: %w", err)}, nil, nil}
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{struct {
|
2017-12-03 05:07:05 +00:00
|
|
|
Name string `json:"name"`
|
2018-11-30 14:27:12 +00:00
|
|
|
}{name}, nil, nil, nil}
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 11:05:41 +00:00
|
|
|
func (api *API) cleanTombstones(*http.Request) apiFuncResult {
|
2017-12-03 05:07:05 +00:00
|
|
|
if !api.enableAdmin {
|
2019-01-04 13:47:38 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorUnavailable, errors.New("admin APIs disabled")}, nil, nil}
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
2020-04-29 16:16:14 +00:00
|
|
|
if err := api.db.CleanTombstones(); err != nil {
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{nil, &apiError{errorInternal, err}, nil, nil}
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 14:27:12 +00:00
|
|
|
return apiFuncResult{nil, nil, nil, nil}
|
2017-12-03 05:07:05 +00:00
|
|
|
}
|
|
|
|
|
2023-09-14 16:57:31 +00:00
|
|
|
// Query string is needed to get the position information for the annotations, and it
|
|
|
|
// can be empty if the position information isn't needed.
|
|
|
|
func (api *API) respond(w http.ResponseWriter, req *http.Request, data interface{}, warnings annotations.Annotations, query string) {
|
2018-11-30 14:27:12 +00:00
|
|
|
statusMessage := statusSuccess
|
2024-07-06 09:05:00 +00:00
|
|
|
warn, info := warnings.AsStrings(query, 10, 10)
|
2023-01-25 03:30:47 +00:00
|
|
|
|
|
|
|
resp := &Response{
|
2018-11-30 14:27:12 +00:00
|
|
|
Status: statusMessage,
|
|
|
|
Data: data,
|
2024-07-06 09:05:00 +00:00
|
|
|
Warnings: warn,
|
|
|
|
Infos: info,
|
2023-01-25 03:30:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 02:27:09 +00:00
|
|
|
codec, err := api.negotiateCodec(req, resp)
|
2015-06-04 16:07:57 +00:00
|
|
|
if err != nil {
|
2023-02-27 02:27:09 +00:00
|
|
|
api.respondError(w, &apiError{errorNotAcceptable, err}, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-25 03:30:47 +00:00
|
|
|
b, err := codec.Encode(resp)
|
2015-06-04 16:07:57 +00:00
|
|
|
if err != nil {
|
2024-06-04 12:54:17 +00:00
|
|
|
level.Error(api.logger).Log("msg", "error marshaling response", "url", req.URL, "err", err)
|
2018-07-13 18:31:23 +00:00
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
2015-06-04 16:07:57 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-27 02:27:09 +00:00
|
|
|
w.Header().Set("Content-Type", codec.ContentType().String())
|
2018-07-13 18:31:23 +00:00
|
|
|
w.WriteHeader(http.StatusOK)
|
2018-07-06 17:44:45 +00:00
|
|
|
if n, err := w.Write(b); err != nil {
|
2024-06-04 12:54:17 +00:00
|
|
|
level.Error(api.logger).Log("msg", "error writing response", "url", req.URL, "bytesWritten", n, "err", err)
|
2018-07-06 17:44:45 +00:00
|
|
|
}
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 02:27:09 +00:00
|
|
|
func (api *API) negotiateCodec(req *http.Request, resp *Response) (Codec, error) {
|
|
|
|
for _, clause := range goautoneg.ParseAccept(req.Header.Get("Accept")) {
|
|
|
|
for _, codec := range api.codecs {
|
|
|
|
if codec.ContentType().Satisfies(clause) && codec.CanEncode(resp) {
|
|
|
|
return codec, nil
|
|
|
|
}
|
|
|
|
}
|
2023-01-25 03:30:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 02:27:09 +00:00
|
|
|
defaultCodec := api.codecs[0]
|
|
|
|
if !defaultCodec.CanEncode(resp) {
|
|
|
|
return nil, fmt.Errorf("cannot encode response as %s", defaultCodec.ContentType())
|
2023-01-25 03:30:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 02:27:09 +00:00
|
|
|
return defaultCodec, nil
|
2023-01-25 03:30:47 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 17:44:45 +00:00
|
|
|
func (api *API) respondError(w http.ResponseWriter, apiErr *apiError, data interface{}) {
|
2018-07-25 12:17:10 +00:00
|
|
|
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
2023-01-25 03:30:47 +00:00
|
|
|
b, err := json.Marshal(&Response{
|
2018-07-25 12:17:10 +00:00
|
|
|
Status: statusError,
|
|
|
|
ErrorType: apiErr.typ,
|
|
|
|
Error: apiErr.err.Error(),
|
|
|
|
Data: data,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2018-11-27 16:44:29 +00:00
|
|
|
level.Error(api.logger).Log("msg", "error marshaling json response", "err", err)
|
2018-07-25 12:17:10 +00:00
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
2015-11-11 22:00:54 +00:00
|
|
|
|
|
|
|
var code int
|
|
|
|
switch apiErr.typ {
|
|
|
|
case errorBadData:
|
|
|
|
code = http.StatusBadRequest
|
|
|
|
case errorExec:
|
2020-08-28 10:18:31 +00:00
|
|
|
code = http.StatusUnprocessableEntity
|
2023-01-25 19:22:25 +00:00
|
|
|
case errorCanceled:
|
|
|
|
code = statusClientClosedConnection
|
|
|
|
case errorTimeout:
|
2015-11-11 22:00:54 +00:00
|
|
|
code = http.StatusServiceUnavailable
|
2017-04-04 16:22:51 +00:00
|
|
|
case errorInternal:
|
|
|
|
code = http.StatusInternalServerError
|
2018-05-18 07:32:11 +00:00
|
|
|
case errorNotFound:
|
|
|
|
code = http.StatusNotFound
|
2023-02-27 02:27:09 +00:00
|
|
|
case errorNotAcceptable:
|
|
|
|
code = http.StatusNotAcceptable
|
2015-11-11 22:00:54 +00:00
|
|
|
default:
|
|
|
|
code = http.StatusInternalServerError
|
|
|
|
}
|
2015-06-04 16:07:57 +00:00
|
|
|
|
2018-07-25 12:17:10 +00:00
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.WriteHeader(code)
|
2018-07-06 17:44:45 +00:00
|
|
|
if n, err := w.Write(b); err != nil {
|
2018-07-25 12:35:47 +00:00
|
|
|
level.Error(api.logger).Log("msg", "error writing response", "bytesWritten", n, "err", err)
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-06 10:33:01 +00:00
|
|
|
func parseTimeParam(r *http.Request, paramName string, defaultValue time.Time) (time.Time, error) {
|
|
|
|
val := r.FormValue(paramName)
|
|
|
|
if val == "" {
|
|
|
|
return defaultValue, nil
|
|
|
|
}
|
|
|
|
result, err := parseTime(val)
|
|
|
|
if err != nil {
|
2023-11-08 03:49:39 +00:00
|
|
|
return time.Time{}, fmt.Errorf("Invalid time value for '%s': %w", paramName, err)
|
2020-03-06 10:33:01 +00:00
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2016-12-24 23:37:46 +00:00
|
|
|
func parseTime(s string) (time.Time, error) {
|
2015-06-04 16:07:57 +00:00
|
|
|
if t, err := strconv.ParseFloat(s, 64); err == nil {
|
2016-12-24 23:37:46 +00:00
|
|
|
s, ns := math.Modf(t)
|
2018-12-03 12:25:54 +00:00
|
|
|
ns = math.Round(ns*1000) / 1000
|
2020-03-29 16:35:39 +00:00
|
|
|
return time.Unix(int64(s), int64(ns*float64(time.Second))).UTC(), nil
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
|
2016-12-24 23:37:46 +00:00
|
|
|
return t, nil
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
2019-07-08 09:43:59 +00:00
|
|
|
|
|
|
|
// Stdlib's time parser can only handle 4 digit years. As a workaround until
|
|
|
|
// that is fixed we want to at least support our own boundary times.
|
|
|
|
// Context: https://github.com/prometheus/client_golang/issues/614
|
|
|
|
// Upstream issue: https://github.com/golang/go/issues/20555
|
|
|
|
switch s {
|
|
|
|
case minTimeFormatted:
|
2023-07-06 15:48:13 +00:00
|
|
|
return MinTime, nil
|
2019-07-08 09:43:59 +00:00
|
|
|
case maxTimeFormatted:
|
2023-07-06 15:48:13 +00:00
|
|
|
return MaxTime, nil
|
2019-07-08 09:43:59 +00:00
|
|
|
}
|
2023-11-08 03:49:39 +00:00
|
|
|
return time.Time{}, fmt.Errorf("cannot parse %q to a valid timestamp", s)
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func parseDuration(s string) (time.Duration, error) {
|
|
|
|
if d, err := strconv.ParseFloat(s, 64); err == nil {
|
2017-03-16 14:16:20 +00:00
|
|
|
ts := d * float64(time.Second)
|
|
|
|
if ts > float64(math.MaxInt64) || ts < float64(math.MinInt64) {
|
2023-11-08 03:49:39 +00:00
|
|
|
return 0, fmt.Errorf("cannot parse %q to a valid duration. It overflows int64", s)
|
2017-03-16 14:16:20 +00:00
|
|
|
}
|
|
|
|
return time.Duration(ts), nil
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
2016-01-29 14:23:11 +00:00
|
|
|
if d, err := model.ParseDuration(s); err == nil {
|
|
|
|
return time.Duration(d), nil
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
2023-11-08 03:49:39 +00:00
|
|
|
return 0, fmt.Errorf("cannot parse %q to a valid duration", s)
|
2015-06-04 16:07:57 +00:00
|
|
|
}
|
2018-02-07 12:27:57 +00:00
|
|
|
|
2020-12-22 11:02:19 +00:00
|
|
|
func parseMatchersParam(matchers []string) ([][]*labels.Matcher, error) {
|
2024-01-15 10:29:53 +00:00
|
|
|
matcherSets, err := parser.ParseMetricSelectors(matchers)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-12-22 11:02:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OUTER:
|
|
|
|
for _, ms := range matcherSets {
|
|
|
|
for _, lm := range ms {
|
|
|
|
if lm != nil && !lm.Matches("") {
|
|
|
|
continue OUTER
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, errors.New("match[] must contain at least one non-empty matcher")
|
|
|
|
}
|
|
|
|
return matcherSets, nil
|
|
|
|
}
|
2024-02-29 15:31:13 +00:00
|
|
|
|
|
|
|
func parseLimitParam(limitStr string) (limit int, err error) {
|
|
|
|
limit = math.MaxInt
|
|
|
|
if limitStr == "" {
|
|
|
|
return limit, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
limit, err = strconv.Atoi(limitStr)
|
|
|
|
if err != nil {
|
|
|
|
return limit, err
|
|
|
|
}
|
|
|
|
if limit <= 0 {
|
|
|
|
return limit, errors.New("limit must be positive")
|
|
|
|
}
|
|
|
|
|
|
|
|
return limit, nil
|
|
|
|
}
|