lib: rename lib/promutils to lib/promutil for the sake of consistency for *util package naming

This commit is contained in:
Aliaksandr Valialkin
2025-03-26 17:32:06 +01:00
parent b43c28ccdf
commit 0e0432db6c
128 changed files with 720 additions and 720 deletions

View File

@@ -6,7 +6,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestApplyRelabeling(t *testing.T) {
@@ -63,7 +63,7 @@ func TestAppendExtraLabels(t *testing.T) {
func parseSeries(data string) []prompbmarshal.TimeSeries {
var tss []prompbmarshal.TimeSeries
tss = append(tss, prompbmarshal.TimeSeries{
Labels: promutils.MustNewLabelsFromString(data).GetLabels(),
Labels: promutil.MustNewLabelsFromString(data).GetLabels(),
})
return tss
}

View File

@@ -25,7 +25,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/procutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/ratelimiter"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/streamaggr"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/timeserieslimits"
@@ -578,7 +578,7 @@ func tryShardingBlockAmongRemoteStorages(rwctxs []*remoteWriteCtx, tssBlock []pr
defer putTSSShards(x)
shards := x.shards
tmpLabels := promutils.GetLabels()
tmpLabels := promutil.GetLabels()
for _, ts := range tssBlock {
hashLabels := ts.Labels
if len(shardByURLLabelsMap) > 0 {
@@ -613,7 +613,7 @@ func tryShardingBlockAmongRemoteStorages(rwctxs []*remoteWriteCtx, tssBlock []pr
}
}
}
promutils.PutLabels(tmpLabels)
promutil.PutLabels(tmpLabels)
// Push sharded samples to remote storage systems in parallel in order to reduce
// the time needed for sending the data to multiple remote storage systems.

View File

@@ -1,15 +1,15 @@
package unittest
import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// alertTestCase holds alert_rule_test cases defined in test file
type alertTestCase struct {
EvalTime *promutils.Duration `yaml:"eval_time"`
GroupName string `yaml:"groupname"`
Alertname string `yaml:"alertname"`
ExpAlerts []expAlert `yaml:"exp_alerts"`
EvalTime *promutil.Duration `yaml:"eval_time"`
GroupName string `yaml:"groupname"`
Alertname string `yaml:"alertname"`
ExpAlerts []expAlert `yaml:"exp_alerts"`
}
// expAlert holds exp_alerts defined in test file

View File

@@ -14,7 +14,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/decimal"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/metricsql"
)
@@ -41,7 +41,7 @@ func httpWrite(address string, r io.Reader) {
}
// writeInputSeries send input series to vmstorage and flush them
func writeInputSeries(input []series, interval *promutils.Duration, startStamp time.Time, dst string) error {
func writeInputSeries(input []series, interval *promutil.Duration, startStamp time.Time, dst string) error {
r := testutil.WriteRequest{}
var err error
r.Timeseries, err = parseInputSeries(input, interval, startStamp)
@@ -56,7 +56,7 @@ func writeInputSeries(input []series, interval *promutils.Duration, startStamp t
return nil
}
func parseInputSeries(input []series, interval *promutils.Duration, startStamp time.Time) ([]testutil.TimeSeries, error) {
func parseInputSeries(input []series, interval *promutil.Duration, startStamp time.Time) ([]testutil.TimeSeries, error) {
var res []testutil.TimeSeries
for _, data := range input {
expr, err := metricsql.Parse(data.Series)

View File

@@ -5,7 +5,7 @@ import (
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/decimal"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseInputValue_Failure(t *testing.T) {
@@ -70,7 +70,7 @@ func TestParseInputValue_Success(t *testing.T) {
func TestParseInputSeries_Success(t *testing.T) {
f := func(input []series) {
t.Helper()
var interval promutils.Duration
var interval promutil.Duration
_, err := parseInputSeries(input, &interval, time.Now())
if err != nil {
t.Fatalf("expect to see no error: %v", err)
@@ -86,7 +86,7 @@ func TestParseInputSeries_Success(t *testing.T) {
func TestParseInputSeries_Fail(t *testing.T) {
f := func(input []series) {
t.Helper()
var interval promutils.Duration
var interval promutil.Duration
_, err := parseInputSeries(input, &interval, time.Now())
if err == nil {
t.Fatalf("expect to see error: %v", err)

View File

@@ -10,15 +10,15 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/datasource"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/metricsql"
)
// metricsqlTestCase holds metricsql_expr_test cases defined in test file
type metricsqlTestCase struct {
Expr string `yaml:"expr"`
EvalTime *promutils.Duration `yaml:"eval_time"`
ExpSamples []expSample `yaml:"exp_samples"`
Expr string `yaml:"expr"`
EvalTime *promutil.Duration `yaml:"eval_time"`
ExpSamples []expSample `yaml:"exp_samples"`
}
type expSample struct {
@@ -95,7 +95,7 @@ Outer:
return
}
func durationToTime(pd *promutils.Duration) time.Time {
func durationToTime(pd *promutil.Duration) time.Time {
if pd == nil {
return time.Time{}
}

View File

@@ -36,7 +36,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/metrics"
)
@@ -182,7 +182,7 @@ func ruleUnitTest(filename string, content []byte, externalLabels map[string]str
if unitTestInp.EvaluationInterval.Duration() == 0 {
fmt.Println("evaluation_interval set to 1m by default")
unitTestInp.EvaluationInterval = &promutils.Duration{D: 1 * time.Minute}
unitTestInp.EvaluationInterval = &promutil.Duration{D: 1 * time.Minute}
}
groupOrderMap := make(map[string]int)
@@ -312,7 +312,7 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i
defer tearDown()
if tg.Interval == nil {
tg.Interval = promutils.NewDuration(evalInterval)
tg.Interval = promutil.NewDuration(evalInterval)
}
err := writeInputSeries(tg.InputSeries, tg.Interval, testStartTime, fmt.Sprintf("http://127.0.0.1:%s/api/v1/write", httpListenAddr))
if err != nil {
@@ -472,15 +472,15 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i
// unitTestFile holds the contents of a single unit test file
type unitTestFile struct {
RuleFiles []string `yaml:"rule_files"`
EvaluationInterval *promutils.Duration `yaml:"evaluation_interval"`
GroupEvalOrder []string `yaml:"group_eval_order"`
Tests []testGroup `yaml:"tests"`
RuleFiles []string `yaml:"rule_files"`
EvaluationInterval *promutil.Duration `yaml:"evaluation_interval"`
GroupEvalOrder []string `yaml:"group_eval_order"`
Tests []testGroup `yaml:"tests"`
}
// testGroup is a group of input series and test cases associated with it
type testGroup struct {
Interval *promutils.Duration `yaml:"interval"`
Interval *promutil.Duration `yaml:"interval"`
InputSeries []series `yaml:"input_series"`
AlertRuleTests []alertTestCase `yaml:"alert_rule_test"`
MetricsqlExprTests []metricsqlTestCase `yaml:"metricsql_expr_test"`

View File

@@ -14,7 +14,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/config/log"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/utils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/envtemplate"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"gopkg.in/yaml.v2"
)
@@ -27,15 +27,15 @@ var (
type Group struct {
Type Type `yaml:"type,omitempty"`
File string
Name string `yaml:"name"`
Interval *promutils.Duration `yaml:"interval,omitempty"`
EvalOffset *promutils.Duration `yaml:"eval_offset,omitempty"`
Name string `yaml:"name"`
Interval *promutil.Duration `yaml:"interval,omitempty"`
EvalOffset *promutil.Duration `yaml:"eval_offset,omitempty"`
// EvalDelay will adjust the `time` parameter of rule evaluation requests to compensate intentional query delay from datasource.
// see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5155
EvalDelay *promutils.Duration `yaml:"eval_delay,omitempty"`
Limit int `yaml:"limit,omitempty"`
Rules []Rule `yaml:"rules"`
Concurrency int `yaml:"concurrency"`
EvalDelay *promutil.Duration `yaml:"eval_delay,omitempty"`
Limit int `yaml:"limit,omitempty"`
Rules []Rule `yaml:"rules"`
Concurrency int `yaml:"concurrency"`
// Labels is a set of label value pairs, that will be added to every rule.
// It has priority over the external labels.
Labels map[string]string `yaml:"labels"`
@@ -135,15 +135,15 @@ func (g *Group) Validate(validateTplFn ValidateTplFn, validateExpressions bool)
// recording rule or alerting rule.
type Rule struct {
ID uint64
Record string `yaml:"record,omitempty"`
Alert string `yaml:"alert,omitempty"`
Expr string `yaml:"expr"`
For *promutils.Duration `yaml:"for,omitempty"`
Record string `yaml:"record,omitempty"`
Alert string `yaml:"alert,omitempty"`
Expr string `yaml:"expr"`
For *promutil.Duration `yaml:"for,omitempty"`
// Alert will continue firing for this long even when the alerting expression no longer has results.
KeepFiringFor *promutils.Duration `yaml:"keep_firing_for,omitempty"`
Labels map[string]string `yaml:"labels,omitempty"`
Annotations map[string]string `yaml:"annotations,omitempty"`
Debug bool `yaml:"debug,omitempty"`
KeepFiringFor *promutil.Duration `yaml:"keep_firing_for,omitempty"`
Labels map[string]string `yaml:"labels,omitempty"`
Annotations map[string]string `yaml:"annotations,omitempty"`
Debug bool `yaml:"debug,omitempty"`
// UpdateEntriesLimit defines max number of rule's state updates stored in memory.
// Overrides `-rule.updateEntriesLimit`.
UpdateEntriesLimit *int `yaml:"update_entries_limit,omitempty"`

View File

@@ -11,7 +11,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/notifier"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/templates"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"gopkg.in/yaml.v2"
)
@@ -162,7 +162,7 @@ func TestGroupValidate_Failure(t *testing.T) {
Rules: []Rule{
{
Expr: "sum(up == 0 ) by (host)",
For: promutils.NewDuration(10 * time.Millisecond),
For: promutil.NewDuration(10 * time.Millisecond),
},
{
Expr: "sumSeries(time('foo.bar',10))",
@@ -172,13 +172,13 @@ func TestGroupValidate_Failure(t *testing.T) {
f(&Group{
Name: "negative interval",
Interval: promutils.NewDuration(-1),
Interval: promutil.NewDuration(-1),
}, false, "interval shouldn't be lower than 0")
f(&Group{
Name: "wrong eval_offset",
Interval: promutils.NewDuration(time.Minute),
EvalOffset: promutils.NewDuration(2 * time.Minute),
Interval: promutil.NewDuration(time.Minute),
EvalOffset: promutil.NewDuration(2 * time.Minute),
}, false, "eval_offset should be smaller than interval")
f(&Group{
@@ -309,7 +309,7 @@ func TestGroupValidate_Failure(t *testing.T) {
Record: "r1",
ID: 1,
Expr: "sumSeries(time('foo.bar',10))",
For: promutils.NewDuration(10 * time.Millisecond),
For: promutil.NewDuration(10 * time.Millisecond),
},
{
Record: "r2",
@@ -326,7 +326,7 @@ func TestGroupValidate_Failure(t *testing.T) {
{
Record: "r1",
Expr: "sum(up == 0 ) by (host)",
For: promutils.NewDuration(10 * time.Millisecond),
For: promutil.NewDuration(10 * time.Millisecond),
},
},
}, true, "bad LogsQL expr")
@@ -338,7 +338,7 @@ func TestGroupValidate_Failure(t *testing.T) {
{
Record: "r1",
Expr: "* | stats by (path) count()",
For: promutils.NewDuration(10 * time.Millisecond),
For: promutil.NewDuration(10 * time.Millisecond),
},
},
}, true, "bad prometheus expr")
@@ -488,7 +488,7 @@ func TestHashRule_Equal(t *testing.T) {
f(Rule{Alert: "record", Expr: "up == 1"}, Rule{Alert: "record", Expr: "up == 1"})
f(Rule{
Alert: "alert", Expr: "up == 1", For: promutils.NewDuration(time.Minute), KeepFiringFor: promutils.NewDuration(time.Minute),
Alert: "alert", Expr: "up == 1", For: promutil.NewDuration(time.Minute), KeepFiringFor: promutil.NewDuration(time.Minute),
}, Rule{Alert: "alert", Expr: "up == 1"})
}

View File

@@ -16,7 +16,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discovery/consul"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discovery/dns"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// Config contains list of supported configuration settings
@@ -44,7 +44,7 @@ type Config struct {
// AlertRelabelConfigs contains list of relabeling rules alert labels
AlertRelabelConfigs []promrelabel.RelabelConfig `yaml:"alert_relabel_configs,omitempty"`
// The timeout used when sending alerts.
Timeout *promutils.Duration `yaml:"timeout,omitempty"`
Timeout *promutil.Duration `yaml:"timeout,omitempty"`
// Checksum stores the hash of yaml definition for the config.
// May be used to detect any changes to the config file.
@@ -82,7 +82,7 @@ func (cfg *Config) UnmarshalYAML(unmarshal func(any) error) error {
cfg.Scheme = "http"
}
if cfg.Timeout.Duration() == 0 {
cfg.Timeout = promutils.NewDuration(time.Second * 10)
cfg.Timeout = promutil.NewDuration(time.Second * 10)
}
rCfg, err := promrelabel.ParseRelabelConfigs(cfg.RelabelConfigs)
if err != nil {
@@ -130,7 +130,7 @@ func parseConfig(path string) (*Config, error) {
return cfg, nil
}
func parseLabels(target string, metaLabels *promutils.Labels, cfg *Config) (string, *promutils.Labels, error) {
func parseLabels(target string, metaLabels *promutil.Labels, cfg *Config) (string, *promutil.Labels, error) {
labels := mergeLabels(target, metaLabels, cfg)
labels.Labels = cfg.parsedRelabelConfigs.Apply(labels.Labels, 0)
labels.RemoveMetaLabels()
@@ -176,9 +176,9 @@ func addMissingPort(scheme, target string) string {
return target
}
func mergeLabels(target string, metaLabels *promutils.Labels, cfg *Config) *promutils.Labels {
func mergeLabels(target string, metaLabels *promutil.Labels, cfg *Config) *promutil.Labels {
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
m := promutils.NewLabels(3 + metaLabels.Len())
m := promutil.NewLabels(3 + metaLabels.Len())
address := target
scheme := cfg.Scheme
alertsPath := path.Join("/", cfg.PathPrefix, alertManagerPath)

View File

@@ -9,7 +9,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discovery/consul"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discovery/dns"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// configWatcher supports dynamic reload of Notifier objects
@@ -157,7 +157,7 @@ func targetsFromLabels(labelsFn getLabels, cfg *Config, genFn AlertURLGenerator)
return targets, errors
}
type getLabels func() ([]*promutils.Labels, error)
type getLabels func() ([]*promutil.Labels, error)
func (cw *configWatcher) start() error {
if len(cw.cfg.StaticConfigs) > 0 {
@@ -183,8 +183,8 @@ func (cw *configWatcher) start() error {
}
if len(cw.cfg.ConsulSDConfigs) > 0 {
err := cw.add(TargetConsul, *consul.SDCheckInterval, func() ([]*promutils.Labels, error) {
var labels []*promutils.Labels
err := cw.add(TargetConsul, *consul.SDCheckInterval, func() ([]*promutil.Labels, error) {
var labels []*promutil.Labels
for i := range cw.cfg.ConsulSDConfigs {
sdc := &cw.cfg.ConsulSDConfigs[i]
targetLabels, err := sdc.GetLabels(cw.cfg.baseDir)
@@ -201,8 +201,8 @@ func (cw *configWatcher) start() error {
}
if len(cw.cfg.DNSSDConfigs) > 0 {
err := cw.add(TargetDNS, *dns.SDCheckInterval, func() ([]*promutils.Labels, error) {
var labels []*promutils.Labels
err := cw.add(TargetDNS, *dns.SDCheckInterval, func() ([]*promutil.Labels, error) {
var labels []*promutil.Labels
for i := range cw.cfg.DNSSDConfigs {
sdc := &cw.cfg.DNSSDConfigs[i]
targetLabels, err := sdc.GetLabels(cw.cfg.baseDir)

View File

@@ -9,7 +9,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
var (
@@ -189,7 +189,7 @@ func notifiersFromFlags(gen AlertURLGenerator) ([]Notifier, error) {
// list of labels added during discovery.
type Target struct {
Notifier
Labels *promutils.Labels
Labels *promutil.Labels
}
// TargetType defines how the Target was discovered

View File

@@ -9,7 +9,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/config"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/datasource"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/remotewrite"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
type fakeReplayQuerier struct {
@@ -88,7 +88,7 @@ func TestReplay(t *testing.T) {
// datapoints per step
f("2021-01-01T12:00:00.000Z", "2021-01-01T15:02:30.000Z", 60, []config.Group{
{Interval: promutils.NewDuration(time.Minute), Rules: []config.Rule{{Record: "foo", Expr: "sum(up)"}}},
{Interval: promutil.NewDuration(time.Minute), Rules: []config.Rule{{Record: "foo", Expr: "sum(up)"}}},
}, &fakeReplayQuerier{
registry: map[string]map[string]struct{}{
"sum(up)": {

View File

@@ -19,7 +19,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/utils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/decimal"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestAlertingRuleToTimeSeries(t *testing.T) {
@@ -841,7 +841,7 @@ func TestGroup_Restore(t *testing.T) {
// one active alert, no previous state
fn(
[]config.Rule{{Alert: "foo", Expr: "foo", For: promutils.NewDuration(time.Second)}},
[]config.Rule{{Alert: "foo", Expr: "foo", For: promutil.NewDuration(time.Second)}},
map[uint64]*notifier.Alert{
hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore"}): {
Name: "foo",
@@ -855,7 +855,7 @@ func TestGroup_Restore(t *testing.T) {
fqr.Set(`default_rollup(ALERTS_FOR_STATE{alertgroup="TestRestore",alertname="foo"}[3600s])`,
stateMetric("foo", ts))
fn(
[]config.Rule{{Alert: "foo", Expr: "foo", For: promutils.NewDuration(time.Second)}},
[]config.Rule{{Alert: "foo", Expr: "foo", For: promutil.NewDuration(time.Second)}},
map[uint64]*notifier.Alert{
hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore"}): {
Name: "foo",
@@ -869,8 +869,8 @@ func TestGroup_Restore(t *testing.T) {
stateMetric("bar", ts))
fn(
[]config.Rule{
{Alert: "foo", Expr: "foo", For: promutils.NewDuration(time.Second)},
{Alert: "bar", Expr: "bar", For: promutils.NewDuration(time.Second)},
{Alert: "foo", Expr: "foo", For: promutil.NewDuration(time.Second)},
{Alert: "bar", Expr: "bar", For: promutil.NewDuration(time.Second)},
},
map[uint64]*notifier.Alert{
hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore"}): {
@@ -891,8 +891,8 @@ func TestGroup_Restore(t *testing.T) {
stateMetric("bar", ts))
fn(
[]config.Rule{
{Alert: "foo", Expr: "foo", For: promutils.NewDuration(time.Second)},
{Alert: "bar", Expr: "bar", For: promutils.NewDuration(time.Second)},
{Alert: "foo", Expr: "foo", For: promutil.NewDuration(time.Second)},
{Alert: "bar", Expr: "bar", For: promutil.NewDuration(time.Second)},
},
map[uint64]*notifier.Alert{
hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore"}): {
@@ -910,7 +910,7 @@ func TestGroup_Restore(t *testing.T) {
fqr.Set(`default_rollup(ALERTS_FOR_STATE{alertname="bar",alertgroup="TestRestore"}[3600s])`,
stateMetric("wrong alert", ts))
fn(
[]config.Rule{{Alert: "foo", Expr: "foo", For: promutils.NewDuration(time.Second)}},
[]config.Rule{{Alert: "foo", Expr: "foo", For: promutil.NewDuration(time.Second)}},
map[uint64]*notifier.Alert{
hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore"}): {
Name: "foo",
@@ -923,7 +923,7 @@ func TestGroup_Restore(t *testing.T) {
fqr.Set(`default_rollup(ALERTS_FOR_STATE{alertgroup="TestRestore",alertname="foo",env="dev"}[3600s])`,
stateMetric("foo", ts, "env", "dev"))
fn(
[]config.Rule{{Alert: "foo", Expr: "foo", Labels: map[string]string{"env": "dev"}, For: promutils.NewDuration(time.Second)}},
[]config.Rule{{Alert: "foo", Expr: "foo", Labels: map[string]string{"env": "dev"}, For: promutil.NewDuration(time.Second)}},
map[uint64]*notifier.Alert{
hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore", "env": "dev"}): {
Name: "foo",
@@ -936,7 +936,7 @@ func TestGroup_Restore(t *testing.T) {
fqr.Set(`default_rollup(ALERTS_FOR_STATE{alertgroup="TestRestore",alertname="foo",env="dev"}[3600s])`,
stateMetric("foo", ts, "env", "dev", "team", "foo"))
fn(
[]config.Rule{{Alert: "foo", Expr: "foo", Labels: map[string]string{"env": "dev"}, For: promutils.NewDuration(time.Second)}},
[]config.Rule{{Alert: "foo", Expr: "foo", Labels: map[string]string{"env": "dev"}, For: promutil.NewDuration(time.Second)}},
map[uint64]*notifier.Alert{
hash(map[string]string{alertNameLabel: "foo", alertGroupNameLabel: "TestRestore", "env": "dev"}): {
Name: "foo",

View File

@@ -18,7 +18,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/notifier"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/remotewrite"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/templates"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func init() {
@@ -93,7 +93,7 @@ func TestUpdateWith(t *testing.T) {
{
Alert: "foo",
Expr: "up > 0",
For: promutils.NewDuration(time.Second),
For: promutil.NewDuration(time.Second),
Labels: map[string]string{
"bar": "baz",
},
@@ -105,7 +105,7 @@ func TestUpdateWith(t *testing.T) {
{
Alert: "bar",
Expr: "up > 0",
For: promutils.NewDuration(time.Second),
For: promutil.NewDuration(time.Second),
Labels: map[string]string{
"bar": "baz",
},
@@ -114,7 +114,7 @@ func TestUpdateWith(t *testing.T) {
{
Alert: "foo",
Expr: "up > 10",
For: promutils.NewDuration(time.Second),
For: promutil.NewDuration(time.Second),
Labels: map[string]string{
"baz": "bar",
},
@@ -125,8 +125,8 @@ func TestUpdateWith(t *testing.T) {
{
Alert: "bar",
Expr: "up > 0",
For: promutils.NewDuration(2 * time.Second),
KeepFiringFor: promutils.NewDuration(time.Minute),
For: promutil.NewDuration(2 * time.Second),
KeepFiringFor: promutil.NewDuration(time.Minute),
Labels: map[string]string{
"bar": "baz",
},

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"io"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// WriteMetricRelabelDebug writes /metric-relabel-debug page to w with the corresponding args.
@@ -26,7 +26,7 @@ func writeRelabelDebug(w io.Writer, isTargetRelabel bool, targetID, metric, rela
WriteRelabelDebugSteps(w, targetURL, targetID, format, nil, metric, relabelConfigs, err)
return
}
labels, err := promutils.NewLabelsFromString(metric)
labels, err := promutil.NewLabelsFromString(metric)
if err != nil {
err = fmt.Errorf("cannot parse metric: %w", err)
WriteRelabelDebugSteps(w, targetURL, targetID, format, nil, metric, relabelConfigs, err)
@@ -43,7 +43,7 @@ func writeRelabelDebug(w io.Writer, isTargetRelabel bool, targetID, metric, rela
WriteRelabelDebugSteps(w, targetURL, targetID, format, dss, metric, relabelConfigs, nil)
}
func newDebugRelabelSteps(pcs *ParsedConfigs, labels *promutils.Labels, isTargetRelabel bool) ([]DebugStep, string) {
func newDebugRelabelSteps(pcs *ParsedConfigs, labels *promutil.Labels, isTargetRelabel bool) ([]DebugStep, string) {
// The target relabeling below must be in sync with the code at scrapeWorkConfig.getScrapeWork if isTargetRelabel=true
// and with the code at scrapeWork.addRowToTimeseries when isTargetRelabeling=false
targetURL := ""
@@ -104,7 +104,7 @@ func newDebugRelabelSteps(pcs *ParsedConfigs, labels *promutils.Labels, isTarget
return dss, targetURL
}
func getChangedLabelNames(in, out *promutils.Labels) map[string]struct{} {
func getChangedLabelNames(in, out *promutil.Labels) map[string]struct{} {
inMap := in.ToMap()
outMap := out.ToMap()
changed := make(map[string]struct{})

View File

@@ -1,7 +1,7 @@
{% import (
"fmt"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/htmlcomponents"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
) %}
{% stripspace %}
@@ -100,8 +100,8 @@ function submitRelabelDebugForm(e) {
<tbody>
{% for i, ds := range dss %}
{% code
inLabels := promutils.MustNewLabelsFromString(ds.In)
outLabels := promutils.MustNewLabelsFromString(ds.Out)
inLabels := promutil.MustNewLabelsFromString(ds.In)
outLabels := promutil.MustNewLabelsFromString(ds.Out)
changedLabels := getChangedLabelNames(inLabels, outLabels)
%}
<tr>
@@ -151,8 +151,8 @@ function submitRelabelDebugForm(e) {
"steps": [
{% for i, ds := range dss %}
{% code
inLabels := promutils.MustNewLabelsFromString(ds.In)
outLabels := promutils.MustNewLabelsFromString(ds.Out)
inLabels := promutil.MustNewLabelsFromString(ds.In)
outLabels := promutil.MustNewLabelsFromString(ds.Out)
changedLabels := getChangedLabelNames(inLabels, outLabels)
%}
{
@@ -167,7 +167,7 @@ function submitRelabelDebugForm(e) {
}
{% endfunc %}
{% func labelsWithHighlight(labels *promutils.Labels, highlight map[string]struct{}, color string) %}
{% func labelsWithHighlight(labels *promutil.Labels, highlight map[string]struct{}, color string) %}
{% code
labelsList := labels.GetLabels()
metricName := ""
@@ -200,7 +200,7 @@ function submitRelabelDebugForm(e) {
{% endfunc %}
{% func mustFormatLabels(s string) %}
{% code labels := promutils.MustNewLabelsFromString(s) %}
{% code labels := promutil.MustNewLabelsFromString(s) %}
{%= labelsWithHighlight(labels, nil, "") %}
{% endfunc %}

View File

@@ -8,7 +8,7 @@ package promrelabel
import (
"fmt"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/htmlcomponents"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
//line lib/promrelabel/debug.qtpl:9
@@ -236,8 +236,8 @@ func streamrelabelDebugSteps(qw422016 *qt422016.Writer, dss []DebugStep, targetU
//line lib/promrelabel/debug.qtpl:101
for i, ds := range dss {
//line lib/promrelabel/debug.qtpl:103
inLabels := promutils.MustNewLabelsFromString(ds.In)
outLabels := promutils.MustNewLabelsFromString(ds.Out)
inLabels := promutil.MustNewLabelsFromString(ds.In)
outLabels := promutil.MustNewLabelsFromString(ds.Out)
changedLabels := getChangedLabelNames(inLabels, outLabels)
//line lib/promrelabel/debug.qtpl:106
@@ -368,8 +368,8 @@ func StreamRelabelDebugStepsJSON(qw422016 *qt422016.Writer, targetURL, targetID
//line lib/promrelabel/debug.qtpl:152
for i, ds := range dss {
//line lib/promrelabel/debug.qtpl:154
inLabels := promutils.MustNewLabelsFromString(ds.In)
outLabels := promutils.MustNewLabelsFromString(ds.Out)
inLabels := promutil.MustNewLabelsFromString(ds.In)
outLabels := promutil.MustNewLabelsFromString(ds.Out)
changedLabels := getChangedLabelNames(inLabels, outLabels)
//line lib/promrelabel/debug.qtpl:157
@@ -430,7 +430,7 @@ func RelabelDebugStepsJSON(targetURL, targetID string, dss []DebugStep, metric,
}
//line lib/promrelabel/debug.qtpl:170
func streamlabelsWithHighlight(qw422016 *qt422016.Writer, labels *promutils.Labels, highlight map[string]struct{}, color string) {
func streamlabelsWithHighlight(qw422016 *qt422016.Writer, labels *promutil.Labels, highlight map[string]struct{}, color string) {
//line lib/promrelabel/debug.qtpl:172
labelsList := labels.GetLabels()
metricName := ""
@@ -516,7 +516,7 @@ func streamlabelsWithHighlight(qw422016 *qt422016.Writer, labels *promutils.Labe
}
//line lib/promrelabel/debug.qtpl:200
func writelabelsWithHighlight(qq422016 qtio422016.Writer, labels *promutils.Labels, highlight map[string]struct{}, color string) {
func writelabelsWithHighlight(qq422016 qtio422016.Writer, labels *promutil.Labels, highlight map[string]struct{}, color string) {
//line lib/promrelabel/debug.qtpl:200
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promrelabel/debug.qtpl:200
@@ -527,7 +527,7 @@ func writelabelsWithHighlight(qq422016 qtio422016.Writer, labels *promutils.Labe
}
//line lib/promrelabel/debug.qtpl:200
func labelsWithHighlight(labels *promutils.Labels, highlight map[string]struct{}, color string) string {
func labelsWithHighlight(labels *promutil.Labels, highlight map[string]struct{}, color string) string {
//line lib/promrelabel/debug.qtpl:200
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promrelabel/debug.qtpl:200
@@ -544,7 +544,7 @@ func labelsWithHighlight(labels *promutils.Labels, highlight map[string]struct{}
//line lib/promrelabel/debug.qtpl:202
func streammustFormatLabels(qw422016 *qt422016.Writer, s string) {
//line lib/promrelabel/debug.qtpl:203
labels := promutils.MustNewLabelsFromString(s)
labels := promutil.MustNewLabelsFromString(s)
//line lib/promrelabel/debug.qtpl:204
streamlabelsWithHighlight(qw422016, labels, nil, "")

View File

@@ -5,7 +5,7 @@ import (
"encoding/json"
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"gopkg.in/yaml.v2"
)
@@ -169,7 +169,7 @@ func TestIfExpressionMatch(t *testing.T) {
if err := yaml.UnmarshalStrict([]byte(ifExpr), &ie); err != nil {
t.Fatalf("unexpected error during unmarshal: %s", err)
}
labels := promutils.MustNewLabelsFromString(metricWithLabels)
labels := promutil.MustNewLabelsFromString(metricWithLabels)
if !ie.Match(labels.GetLabels()) {
t.Fatalf("unexpected mismatch of ifExpr=%s for %s", ifExpr, metricWithLabels)
}
@@ -207,7 +207,7 @@ func TestIfExpressionMismatch(t *testing.T) {
if err := yaml.UnmarshalStrict([]byte(ifExpr), &ie); err != nil {
t.Fatalf("unexpected error during unmarshal: %s", err)
}
labels := promutils.MustNewLabelsFromString(metricWithLabels)
labels := promutil.MustNewLabelsFromString(metricWithLabels)
if ie.Match(labels.GetLabels()) {
t.Fatalf("unexpected match of ifExpr=%s for %s", ifExpr, metricWithLabels)
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/regexutil"
"github.com/cespare/xxhash/v2"
)
@@ -626,12 +626,12 @@ func LabelsToString(labels []prompbmarshal.Label) string {
// SortLabels sorts labels in alphabetical order.
func SortLabels(labels []prompbmarshal.Label) {
x := promutils.GetLabels()
x := promutil.GetLabels()
labelsOrig := x.Labels
x.Labels = labels
x.Sort()
x.Labels = labelsOrig
promutils.PutLabels(x)
promutil.PutLabels(x)
}
func fillLabelReferences(dst []byte, replacement string, labels []prompbmarshal.Label) []byte {

View File

@@ -6,7 +6,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestSanitizeMetricName(t *testing.T) {
@@ -95,7 +95,7 @@ func TestParsedRelabelConfigsApplyDebug(t *testing.T) {
if err != nil {
t.Fatalf("cannot parse %q: %s", config, err)
}
labels := promutils.MustNewLabelsFromString(metric)
labels := promutil.MustNewLabelsFromString(metric)
_, dss := pcs.ApplyDebug(labels.GetLabels())
if !reflect.DeepEqual(dss, dssExpected) {
t.Fatalf("unexpected result; got\n%s\nwant\n%s", dss, dssExpected)
@@ -170,7 +170,7 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
if err != nil {
t.Fatalf("cannot parse %q: %s", config, err)
}
labels := promutils.MustNewLabelsFromString(metric)
labels := promutil.MustNewLabelsFromString(metric)
resultLabels := pcs.Apply(labels.GetLabels(), 0)
if isFinalize {
resultLabels = FinalizeLabels(resultLabels[:0], resultLabels)
@@ -950,7 +950,7 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
func TestFinalizeLabels(t *testing.T) {
f := func(metric, resultExpected string) {
t.Helper()
labels := promutils.MustNewLabelsFromString(metric)
labels := promutil.MustNewLabelsFromString(metric)
resultLabels := FinalizeLabels(nil, labels.GetLabels())
result := LabelsToString(resultLabels)
if result != resultExpected {
@@ -966,7 +966,7 @@ func TestFinalizeLabels(t *testing.T) {
func TestFillLabelReferences(t *testing.T) {
f := func(replacement, metric, resultExpected string) {
t.Helper()
labels := promutils.MustNewLabelsFromString(metric)
labels := promutil.MustNewLabelsFromString(metric)
result := fillLabelReferences(nil, replacement, labels.GetLabels())
if string(result) != resultExpected {
t.Fatalf("unexpected result; got\n%q\nwant\n%q", result, resultExpected)
@@ -1047,7 +1047,7 @@ func TestParsedRelabelConfigsApplyForMultipleSeries(t *testing.T) {
totalLabels := 0
var labels []prompbmarshal.Label
for _, metric := range metrics {
labels = append(labels, promutils.MustNewLabelsFromString(metric).GetLabels()...)
labels = append(labels, promutil.MustNewLabelsFromString(metric).GetLabels()...)
resultLabels := pcs.Apply(labels, totalLabels)
SortLabels(resultLabels)
totalLabels += len(resultLabels)

View File

@@ -5,11 +5,11 @@ import (
"strings"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// GetScrapeURL makes scrape url and __address_ labels for the given labels and extraParams.
func GetScrapeURL(labels *promutils.Labels, extraParams map[string][]string) (string, string) {
func GetScrapeURL(labels *promutil.Labels, extraParams map[string][]string) (string, string) {
// See https://www.robustperception.io/life-of-a-label
scheme := labels.Get("__scheme__")
if len(scheme) == 0 {
@@ -61,7 +61,7 @@ func GetScrapeURL(labels *promutils.Labels, extraParams map[string][]string) (st
return scrapeURL, addressMustWithPort
}
func getParamsFromLabels(labels *promutils.Labels, extraParams map[string][]string) map[string][]string {
func getParamsFromLabels(labels *promutil.Labels, extraParams map[string][]string) map[string][]string {
// See https://www.robustperception.io/life-of-a-label
var m map[string][]string
for _, label := range labels.GetLabels() {

View File

@@ -3,13 +3,13 @@ package promrelabel
import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestGetScrapeURL(t *testing.T) {
f := func(labelsStr, expectedScrapeURL, expectedAddress string) {
t.Helper()
labels := promutils.MustNewLabelsFromString(labelsStr)
labels := promutil.MustNewLabelsFromString(labelsStr)
scrapeURL, address := GetScrapeURL(labels, nil)
if scrapeURL != expectedScrapeURL {
t.Fatalf("unexpected scrapeURL; got %q; want %q", scrapeURL, expectedScrapeURL)

View File

@@ -46,7 +46,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discovery/puppetdb"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discovery/vultr"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discovery/yandexcloud"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/timeutil"
)
@@ -265,9 +265,9 @@ func (cfg *Config) getJobNames() []string {
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/
type GlobalConfig struct {
ScrapeInterval *promutils.Duration `yaml:"scrape_interval,omitempty"`
ScrapeTimeout *promutils.Duration `yaml:"scrape_timeout,omitempty"`
ExternalLabels *promutils.Labels `yaml:"external_labels,omitempty"`
ScrapeInterval *promutil.Duration `yaml:"scrape_interval,omitempty"`
ScrapeTimeout *promutil.Duration `yaml:"scrape_timeout,omitempty"`
ExternalLabels *promutil.Labels `yaml:"external_labels,omitempty"`
RelabelConfigs []promrelabel.RelabelConfig `yaml:"relabel_configs,omitempty"`
MetricRelabelConfigs []promrelabel.RelabelConfig `yaml:"metric_relabel_configs,omitempty"`
}
@@ -276,12 +276,12 @@ type GlobalConfig struct {
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config
type ScrapeConfig struct {
JobName string `yaml:"job_name"`
ScrapeInterval *promutils.Duration `yaml:"scrape_interval,omitempty"`
ScrapeTimeout *promutils.Duration `yaml:"scrape_timeout,omitempty"`
MaxScrapeSize string `yaml:"max_scrape_size,omitempty"`
MetricsPath string `yaml:"metrics_path,omitempty"`
HonorLabels bool `yaml:"honor_labels,omitempty"`
JobName string `yaml:"job_name"`
ScrapeInterval *promutil.Duration `yaml:"scrape_interval,omitempty"`
ScrapeTimeout *promutil.Duration `yaml:"scrape_timeout,omitempty"`
MaxScrapeSize string `yaml:"max_scrape_size,omitempty"`
MetricsPath string `yaml:"metrics_path,omitempty"`
HonorLabels bool `yaml:"honor_labels,omitempty"`
// HonorTimestamps is set to false by default contrary to Prometheus, which sets it to true by default,
// because of the issue with gaps on graphs when scraping cadvisor or similar targets, which export invalid timestamps.
@@ -330,8 +330,8 @@ type ScrapeConfig struct {
DisableCompression bool `yaml:"disable_compression,omitempty"`
DisableKeepAlive bool `yaml:"disable_keepalive,omitempty"`
StreamParse bool `yaml:"stream_parse,omitempty"`
ScrapeAlignInterval *promutils.Duration `yaml:"scrape_align_interval,omitempty"`
ScrapeOffset *promutils.Duration `yaml:"scrape_offset,omitempty"`
ScrapeAlignInterval *promutil.Duration `yaml:"scrape_align_interval,omitempty"`
ScrapeOffset *promutil.Duration `yaml:"scrape_offset,omitempty"`
SeriesLimit *int `yaml:"series_limit,omitempty"`
NoStaleMarkers *bool `yaml:"no_stale_markers,omitempty"`
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
@@ -341,7 +341,7 @@ type ScrapeConfig struct {
}
func (sc *ScrapeConfig) mustStart(baseDir string) {
swosFunc := func(metaLabels *promutils.Labels) any {
swosFunc := func(metaLabels *promutil.Labels) any {
target := metaLabels.Get("__address__")
sw, err := sc.swc.getScrapeWork(target, nil, metaLabels)
if err != nil {
@@ -430,8 +430,8 @@ type FileSDConfig struct {
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#static_config
type StaticConfig struct {
Targets []string `yaml:"targets"`
Labels *promutils.Labels `yaml:"labels,omitempty"`
Targets []string `yaml:"targets"`
Labels *promutil.Labels `yaml:"labels,omitempty"`
}
func loadStaticConfigs(path string) ([]StaticConfig, error) {
@@ -824,7 +824,7 @@ func (cfg *Config) getYandexCloudSDScrapeWork(prev []*ScrapeWork) []*ScrapeWork
}
type targetLabelsGetter interface {
GetLabels(baseDir string) ([]*promutils.Labels, error)
GetLabels(baseDir string) ([]*promutil.Labels, error)
}
func (cfg *Config) getScrapeWorkGeneric(visitConfigs func(sc *ScrapeConfig, visitor func(sdc targetLabelsGetter)), discoveryType string, prev []*ScrapeWork) []*ScrapeWork {
@@ -1014,7 +1014,7 @@ type scrapeWorkConfig struct {
honorLabels bool
honorTimestamps bool
denyRedirects bool
externalLabels *promutils.Labels
externalLabels *promutil.Labels
relabelConfigs *promrelabel.ParsedConfigs
metricRelabelConfigs *promrelabel.ParsedConfigs
sampleLimit int
@@ -1027,7 +1027,7 @@ type scrapeWorkConfig struct {
noStaleMarkers bool
}
func appendScrapeWorkForTargetLabels(dst []*ScrapeWork, swc *scrapeWorkConfig, targetLabels []*promutils.Labels, discoveryType string) []*ScrapeWork {
func appendScrapeWorkForTargetLabels(dst []*ScrapeWork, swc *scrapeWorkConfig, targetLabels []*promutil.Labels, discoveryType string) []*ScrapeWork {
startTime := time.Now()
// Process targetLabels in parallel in order to reduce processing time for big number of targetLabels.
type result struct {
@@ -1036,7 +1036,7 @@ func appendScrapeWorkForTargetLabels(dst []*ScrapeWork, swc *scrapeWorkConfig, t
}
goroutines := cgroup.AvailableCPUs()
resultCh := make(chan result, len(targetLabels))
workCh := make(chan *promutils.Labels, goroutines)
workCh := make(chan *promutil.Labels, goroutines)
for i := 0; i < goroutines; i++ {
go func() {
for metaLabels := range workCh {
@@ -1071,8 +1071,8 @@ func appendScrapeWorkForTargetLabels(dst []*ScrapeWork, swc *scrapeWorkConfig, t
}
func (sdc *FileSDConfig) appendScrapeWork(dst []*ScrapeWork, baseDir string, swc *scrapeWorkConfig) []*ScrapeWork {
metaLabels := promutils.GetLabels()
defer promutils.PutLabels(metaLabels)
metaLabels := promutil.GetLabels()
defer promutil.PutLabels(metaLabels)
for _, file := range sdc.Files {
pathPattern := fscore.GetFilepath(baseDir, file)
paths := []string{pathPattern}
@@ -1109,7 +1109,7 @@ func (sdc *FileSDConfig) appendScrapeWork(dst []*ScrapeWork, baseDir string, swc
return dst
}
func (stc *StaticConfig) appendScrapeWork(dst []*ScrapeWork, swc *scrapeWorkConfig, metaLabels *promutils.Labels) []*ScrapeWork {
func (stc *StaticConfig) appendScrapeWork(dst []*ScrapeWork, swc *scrapeWorkConfig, metaLabels *promutil.Labels) []*ScrapeWork {
for _, target := range stc.Targets {
if target == "" {
// Do not return this error, since other targets may be valid
@@ -1129,7 +1129,7 @@ func (stc *StaticConfig) appendScrapeWork(dst []*ScrapeWork, swc *scrapeWorkConf
return dst
}
func appendScrapeWorkKey(dst []byte, labels *promutils.Labels) []byte {
func appendScrapeWorkKey(dst []byte, labels *promutil.Labels) []byte {
for _, label := range labels.GetLabels() {
// Do not use strconv.AppendQuote, since it is slow according to CPU profile.
dst = append(dst, label.Name...)
@@ -1162,12 +1162,12 @@ func getClusterMemberNumsForScrapeWork(key string, membersCount, replicasCount i
var scrapeWorkKeyBufPool bytesutil.ByteBufferPool
func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabels *promutils.Labels) (*ScrapeWork, error) {
labels := promutils.GetLabels()
defer promutils.PutLabels(labels)
func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabels *promutil.Labels) (*ScrapeWork, error) {
labels := promutil.GetLabels()
defer promutil.PutLabels(labels)
mergeLabels(labels, swc, target, extraLabels, metaLabels)
var originalLabels *promutils.Labels
var originalLabels *promutil.Labels
if !*dropOriginalLabels {
originalLabels = labels.Clone()
}
@@ -1315,7 +1315,7 @@ func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabel
return sw, nil
}
func sortOriginalLabelsIfNeeded(originalLabels *promutils.Labels) *promutils.Labels {
func sortOriginalLabelsIfNeeded(originalLabels *promutil.Labels) *promutil.Labels {
if originalLabels == nil {
return nil
}
@@ -1325,7 +1325,7 @@ func sortOriginalLabelsIfNeeded(originalLabels *promutils.Labels) *promutils.Lab
return originalLabels
}
func mergeLabels(dst *promutils.Labels, swc *scrapeWorkConfig, target string, extraLabels, metaLabels *promutils.Labels) {
func mergeLabels(dst *promutil.Labels, swc *scrapeWorkConfig, target string, extraLabels, metaLabels *promutil.Labels) {
if n := dst.Len(); n > 0 {
logger.Panicf("BUG: len(dst.Labels) must be 0; got %d", n)
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discovery/gce"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/stringsutil"
)
@@ -18,9 +18,9 @@ import (
func TestMergeLabels(t *testing.T) {
f := func(swc *scrapeWorkConfig, target string, extraLabelsMap, metaLabelsMap map[string]string, resultExpected string) {
t.Helper()
extraLabels := promutils.NewLabelsFromMap(extraLabelsMap)
metaLabels := promutils.NewLabelsFromMap(metaLabelsMap)
labels := promutils.NewLabels(0)
extraLabels := promutil.NewLabelsFromMap(extraLabelsMap)
metaLabels := promutil.NewLabelsFromMap(metaLabelsMap)
labels := promutil.NewLabels(0)
mergeLabels(labels, swc, target, extraLabels, metaLabels)
result := labels.String()
if result != resultExpected {
@@ -240,7 +240,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "host1:80",
"job": "abc",
}),
@@ -251,7 +251,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "host2:443",
"job": "abc",
}),
@@ -262,7 +262,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "host3:1234",
"job": "abc",
}),
@@ -273,7 +273,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "host4:1234",
"job": "abc",
}),
@@ -312,7 +312,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "8.8.8.8",
"job": "blackbox",
}),
@@ -475,7 +475,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "host1:80",
"job": "foo",
"qwe": "rty",
@@ -487,7 +487,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "host2:80",
"job": "foo",
"qwe": "rty",
@@ -499,7 +499,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "localhost:9090",
"job": "foo",
"yml": "test",
@@ -706,7 +706,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "s:80",
"job": "aa",
}),
@@ -728,7 +728,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "s:80",
"job": "aa",
}),
@@ -750,7 +750,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "s:80",
"job": "aa",
}),
@@ -772,7 +772,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "s:80",
"job": "aa",
}),
@@ -791,7 +791,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo.bar:1234",
"job": "foo",
}),
@@ -813,11 +813,11 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo.bar:1234",
"job": "foo",
}),
ExternalLabels: promutils.NewLabelsFromMap(map[string]string{
ExternalLabels: promutil.NewLabelsFromMap(map[string]string{
"datacenter": "foobar",
"jobs": "xxx",
}),
@@ -864,7 +864,7 @@ scrape_configs:
HonorLabels: true,
HonorTimestamps: true,
DenyRedirects: true,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo.bar:443",
"job": "foo",
"x": "y",
@@ -880,7 +880,7 @@ scrape_configs:
HonorLabels: true,
HonorTimestamps: true,
DenyRedirects: true,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "aaa:443",
"job": "foo",
"x": "y",
@@ -893,7 +893,7 @@ scrape_configs:
ScrapeInterval: 8 * time.Second,
ScrapeTimeout: 8 * time.Second,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "1.2.3.4:80",
"job": "qwer",
}),
@@ -904,7 +904,7 @@ scrape_configs:
ScrapeInterval: 8 * time.Second,
ScrapeTimeout: 8 * time.Second,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foobar:80",
"job": "asdf",
}),
@@ -952,7 +952,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"hash": "82",
"instance": "foo.bar:1234",
"prefix:url": "http://foo.bar:1234/metrics",
@@ -994,7 +994,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "fake.addr",
"job": "https",
}),
@@ -1028,7 +1028,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: 1,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo.bar:1234",
"job": "3",
}),
@@ -1051,7 +1051,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: 8 * 1024 * 1024,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo.bar:1234",
"job": "foo",
}),
@@ -1069,7 +1069,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo.bar:1234",
"job": "foo",
}),
@@ -1087,7 +1087,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo.bar:1234",
"job": "foo",
}),
@@ -1119,12 +1119,12 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"foo": "bar",
"instance": "pp:80",
"job": "yyy",
}),
ExternalLabels: promutils.NewLabelsFromMap(map[string]string{
ExternalLabels: promutil.NewLabelsFromMap(map[string]string{
"__address__": "aaasdf",
"__param_a": "jlfd",
"foo": "xx",
@@ -1172,7 +1172,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "192.168.1.2",
"job": "snmp",
}),
@@ -1201,7 +1201,7 @@ scrape_configs:
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo.bar:1234",
"job": "path wo slash",
}),
@@ -1229,7 +1229,7 @@ scrape_configs:
ScrapeOffset: time.Hour * 24 * 2,
MaxScrapeSize: maxScrapeSize.N,
NoStaleMarkers: true,
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo.bar:1234",
"job": "foo",
}),
@@ -1252,7 +1252,7 @@ scrape_configs:
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: maxScrapeSize.N,
jobNameOriginal: "foo",
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo.bar:1234",
"job": "foo",
}),
@@ -1295,7 +1295,7 @@ func TestScrapeConfigClone(t *testing.T) {
}
f(&ScrapeConfig{
JobName: "foo",
ScrapeInterval: promutils.NewDuration(time.Second * 47),
ScrapeInterval: promutil.NewDuration(time.Second * 47),
HonorLabels: true,
Params: map[string][]string{
"foo": {"bar", "baz"},

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func BenchmarkGetScrapeWork(b *testing.B) {
@@ -16,11 +16,11 @@ func BenchmarkGetScrapeWork(b *testing.B) {
scrapeTimeoutString: "10s",
}
target := "host1.com:1234"
extraLabels := promutils.NewLabelsFromMap(map[string]string{
extraLabels := promutil.NewLabelsFromMap(map[string]string{
"env": "prod",
"datacenter": "dc-foo",
})
metaLabels := promutils.NewLabelsFromMap(map[string]string{
metaLabels := promutil.NewLabelsFromMap(map[string]string{
"__meta_foo": "bar",
"__meta_kubernetes_namespace": "default",
"__address__": "foobar.com",

View File

@@ -8,7 +8,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -44,7 +44,7 @@ type SDConfig struct {
}
// GetLabels returns Azure labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
ac, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)
@@ -65,8 +65,8 @@ func (sdc *SDConfig) MustStop() {
}
}
func appendMachineLabels(vms []virtualMachine, port int, sdc *SDConfig) []*promutils.Labels {
ms := make([]*promutils.Labels, 0, len(vms))
func appendMachineLabels(vms []virtualMachine, port int, sdc *SDConfig) []*promutil.Labels {
ms := make([]*promutil.Labels, 0, len(vms))
for i := range vms {
vm := &vms[i]
for _, ips := range vm.ipAddresses {
@@ -74,7 +74,7 @@ func appendMachineLabels(vms []virtualMachine, port int, sdc *SDConfig) []*promu
continue
}
addr := discoveryutils.JoinHostPort(ips.privateIP, port)
m := promutils.NewLabels(16)
m := promutil.NewLabels(16)
m.Add("__address__", addr)
m.Add("__meta_azure_subscription_id", sdc.SubscriptionID)
m.Add("__meta_azure_machine_id", vm.ID)

View File

@@ -4,11 +4,11 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestAppendMachineLabels(t *testing.T) {
f := func(name string, vms []virtualMachine, expectedLabels []*promutils.Labels) {
f := func(name string, vms []virtualMachine, expectedLabels []*promutil.Labels) {
t.Run(name, func(t *testing.T) {
labelss := appendMachineLabels(vms, 80, &SDConfig{SubscriptionID: "some-id"})
discoveryutils.TestEqualLabelss(t, labelss, expectedLabels)
@@ -30,8 +30,8 @@ func TestAppendMachineLabels(t *testing.T) {
{privateIP: "10.10.10.1"},
},
},
}, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
}, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.10.10.1:80",
"__meta_azure_machine_id": "id-2",
"__meta_azure_subscription_id": "some-id",

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -43,7 +43,7 @@ type SDConfig struct {
}
// GetLabels returns Consul labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)

View File

@@ -7,13 +7,13 @@ import (
"strings"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// getServiceNodesLabels returns labels for Consul service nodes with given cfg.
func getServiceNodesLabels(cfg *apiConfig) []*promutils.Labels {
func getServiceNodesLabels(cfg *apiConfig) []*promutil.Labels {
sns := cfg.consulWatcher.getServiceNodesSnapshot()
var ms []*promutils.Labels
var ms []*promutil.Labels
for svc, sn := range sns {
for i := range sn {
ms = sn[i].appendTargetLabels(ms, svc, cfg.tagSeparator)
@@ -83,14 +83,14 @@ func ParseServiceNodes(data []byte) ([]ServiceNode, error) {
return sns, nil
}
func (sn *ServiceNode) appendTargetLabels(ms []*promutils.Labels, serviceName, tagSeparator string) []*promutils.Labels {
func (sn *ServiceNode) appendTargetLabels(ms []*promutil.Labels, serviceName, tagSeparator string) []*promutil.Labels {
var addr string
if sn.Service.Address != "" {
addr = discoveryutils.JoinHostPort(sn.Service.Address, sn.Service.Port)
} else {
addr = discoveryutils.JoinHostPort(sn.Node.Address, sn.Service.Port)
}
m := promutils.NewLabels(16)
m := promutil.NewLabels(16)
m.Add("__address__", addr)
m.Add("__meta_consul_address", sn.Node.Address)
m.Add("__meta_consul_dc", sn.Node.Datacenter)

View File

@@ -4,7 +4,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseServiceNodesFailure(t *testing.T) {
@@ -107,8 +107,8 @@ func TestParseServiceNodesSuccess(t *testing.T) {
// Check sn.appendTargetLabels()
tagSeparator := ","
labelss := sn.appendTargetLabels(nil, "redis", tagSeparator)
expectedLabelss := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabelss := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.1.10.12:8000",
"__meta_consul_address": "10.1.10.12",
"__meta_consul_dc": "dc1",

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -37,7 +37,7 @@ type SDConfig struct {
}
// GetLabels returns Consul labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)

View File

@@ -6,13 +6,13 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discovery/consul"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// getServiceNodesLabels returns labels for Consul service nodes with given cfg.
func getServiceNodesLabels(cfg *apiConfig) []*promutils.Labels {
func getServiceNodesLabels(cfg *apiConfig) []*promutil.Labels {
sns := cfg.consulWatcher.getServiceNodesSnapshot()
var ms []*promutils.Labels
var ms []*promutil.Labels
for svc, sn := range sns {
for i := range sn {
ms = appendTargetLabels(sn[i], ms, svc, cfg.tagSeparator, cfg.agent)
@@ -21,7 +21,7 @@ func getServiceNodesLabels(cfg *apiConfig) []*promutils.Labels {
return ms
}
func appendTargetLabels(sn consul.ServiceNode, ms []*promutils.Labels, serviceName, tagSeparator string, agent *consul.Agent) []*promutils.Labels {
func appendTargetLabels(sn consul.ServiceNode, ms []*promutil.Labels, serviceName, tagSeparator string, agent *consul.Agent) []*promutil.Labels {
var addr string
// If the service address is not empty it should be used instead of the node address
@@ -32,7 +32,7 @@ func appendTargetLabels(sn consul.ServiceNode, ms []*promutils.Labels, serviceNa
addr = discoveryutils.JoinHostPort(agent.Member.Addr, sn.Service.Port)
}
m := promutils.NewLabels(16)
m := promutil.NewLabels(16)
m.Add("__address__", addr)
m.Add("__meta_consulagent_address", agent.Member.Addr)
m.Add("__meta_consulagent_dc", agent.Config.Datacenter)

View File

@@ -5,7 +5,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discovery/consul"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseServiceNodesFailure(t *testing.T) {
@@ -114,8 +114,8 @@ func TestParseServiceNodesSuccess(t *testing.T) {
// Check sn.appendTargetLabels()
tagSeparator := ","
labelss := appendTargetLabels(sn, nil, "redis", tagSeparator, agent)
expectedLabelss := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabelss := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.1.10.12:8000",
"__meta_consulagent_address": "10.1.10.12",
"__meta_consulagent_dc": "dc1",

View File

@@ -10,7 +10,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -31,7 +31,7 @@ type SDConfig struct {
}
// GetLabels returns Digital Ocean droplet labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)
@@ -121,8 +121,8 @@ func (r *listDropletResponse) nextURLPath() (string, error) {
return u.RequestURI(), nil
}
func addDropletLabels(droplets []droplet, defaultPort int) []*promutils.Labels {
var ms []*promutils.Labels
func addDropletLabels(droplets []droplet, defaultPort int) []*promutil.Labels {
var ms []*promutil.Labels
for _, droplet := range droplets {
if len(droplet.Networks.V4) == 0 {
continue
@@ -133,7 +133,7 @@ func addDropletLabels(droplets []droplet, defaultPort int) []*promutils.Labels {
publicIPv6 := droplet.getIPByNet("v6", "public")
addr := discoveryutils.JoinHostPort(publicIPv4, defaultPort)
m := promutils.NewLabels(16)
m := promutil.NewLabels(16)
m.Add("__address__", addr)
m.Add("__meta_digitalocean_droplet_id", fmt.Sprintf("%d", droplet.ID))
m.Add("__meta_digitalocean_droplet_name", droplet.Name)

View File

@@ -4,11 +4,11 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestAddDropletLabels(t *testing.T) {
f := func(droplets []droplet, labelssExpected []*promutils.Labels) {
f := func(droplets []droplet, labelssExpected []*promutil.Labels) {
t.Helper()
labelss := addDropletLabels(droplets, 9100)
@@ -52,8 +52,8 @@ func TestAddDropletLabels(t *testing.T) {
},
},
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "100.100.100.100:9100",
"__meta_digitalocean_droplet_id": "15",
"__meta_digitalocean_droplet_name": "ubuntu-1",

View File

@@ -12,7 +12,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/netutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// SDCheckInterval defines interval for targets refresh.
@@ -32,7 +32,7 @@ type SDConfig struct {
}
// GetLabels returns DNS labels according to sdc.
func (sdc *SDConfig) GetLabels(_ string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(_ string) ([]*promutil.Labels, error) {
if len(sdc.Names) == 0 {
return nil, fmt.Errorf("`names` cannot be empty in `dns_sd_config`")
}
@@ -62,7 +62,7 @@ func (sdc *SDConfig) MustStop() {
// nothing to do
}
func getMXAddrLabels(ctx context.Context, sdc *SDConfig) []*promutils.Labels {
func getMXAddrLabels(ctx context.Context, sdc *SDConfig) []*promutil.Labels {
port := 25
if sdc.Port != nil {
port = *sdc.Port
@@ -83,7 +83,7 @@ func getMXAddrLabels(ctx context.Context, sdc *SDConfig) []*promutils.Labels {
}
}(name)
}
var ms []*promutils.Labels
var ms []*promutil.Labels
for range sdc.Names {
r := <-ch
if r.err != nil {
@@ -101,7 +101,7 @@ func getMXAddrLabels(ctx context.Context, sdc *SDConfig) []*promutils.Labels {
return ms
}
func getSRVAddrLabels(ctx context.Context, sdc *SDConfig) []*promutils.Labels {
func getSRVAddrLabels(ctx context.Context, sdc *SDConfig) []*promutil.Labels {
type result struct {
name string
as []*net.SRV
@@ -118,7 +118,7 @@ func getSRVAddrLabels(ctx context.Context, sdc *SDConfig) []*promutils.Labels {
}
}(name)
}
var ms []*promutils.Labels
var ms []*promutil.Labels
for range sdc.Names {
r := <-ch
if r.err != nil {
@@ -136,7 +136,7 @@ func getSRVAddrLabels(ctx context.Context, sdc *SDConfig) []*promutils.Labels {
return ms
}
func getAAddrLabels(ctx context.Context, sdc *SDConfig, lookupType string) ([]*promutils.Labels, error) {
func getAAddrLabels(ctx context.Context, sdc *SDConfig, lookupType string) ([]*promutil.Labels, error) {
if sdc.Port == nil {
return nil, fmt.Errorf("missing `port` in `dns_sd_config` for `type: %s`", lookupType)
}
@@ -157,7 +157,7 @@ func getAAddrLabels(ctx context.Context, sdc *SDConfig, lookupType string) ([]*p
}
}(name)
}
var ms []*promutils.Labels
var ms []*promutil.Labels
for range sdc.Names {
r := <-ch
if r.err != nil {
@@ -175,18 +175,18 @@ func getAAddrLabels(ctx context.Context, sdc *SDConfig, lookupType string) ([]*p
return ms, nil
}
func appendMXLabels(ms []*promutils.Labels, name, target string, port int) []*promutils.Labels {
func appendMXLabels(ms []*promutil.Labels, name, target string, port int) []*promutil.Labels {
addr := discoveryutils.JoinHostPort(target, port)
m := promutils.NewLabels(3)
m := promutil.NewLabels(3)
m.Add("__address__", addr)
m.Add("__meta_dns_name", name)
m.Add("__meta_dns_mx_record_target", target)
return append(ms, m)
}
func appendAddrLabels(ms []*promutils.Labels, name, target string, port int) []*promutils.Labels {
func appendAddrLabels(ms []*promutil.Labels, name, target string, port int) []*promutil.Labels {
addr := discoveryutils.JoinHostPort(target, port)
m := promutils.NewLabels(4)
m := promutil.NewLabels(4)
m.Add("__address__", addr)
m.Add("__meta_dns_name", name)
m.Add("__meta_dns_srv_record_target", target)

View File

@@ -8,7 +8,7 @@ import (
"strings"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// See https://github.com/moby/moby/blob/314759dc2f4745925d8dec6d15acc7761c6e5c92/docs/api/v1.41.yaml#L4024
@@ -41,7 +41,7 @@ type containerNetwork struct {
NetworkID string
}
func getContainersLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
func getContainersLabels(cfg *apiConfig) ([]*promutil.Labels, error) {
networkLabels, err := getNetworksLabelsByNetworkID(cfg)
if err != nil {
return nil, err
@@ -69,13 +69,13 @@ func parseContainers(data []byte) ([]container, error) {
return containers, nil
}
func addContainersLabels(containers []container, networkLabels map[string]*promutils.Labels, defaultPort int, hostNetworkingHost string, matchFirstNetwork bool) []*promutils.Labels {
func addContainersLabels(containers []container, networkLabels map[string]*promutil.Labels, defaultPort int, hostNetworkingHost string, matchFirstNetwork bool) []*promutil.Labels {
containersIdxByID := make(map[string]int)
for idx, c := range containers {
containersIdxByID[c.ID] = idx
}
var ms []*promutils.Labels
var ms []*promutil.Labels
for i := range containers {
c := &containers[i]
if len(c.Names) == 0 {
@@ -123,7 +123,7 @@ func addContainersLabels(containers []container, networkLabels map[string]*promu
if p.Type != "tcp" {
continue
}
m := promutils.NewLabels(16)
m := promutil.NewLabels(16)
m.Add("__address__", discoveryutils.JoinHostPort(n.IPAddress, p.PrivatePort))
m.Add("__meta_docker_network_ip", n.IPAddress)
m.Add("__meta_docker_port_private", strconv.Itoa(p.PrivatePort))
@@ -143,7 +143,7 @@ func addContainersLabels(containers []container, networkLabels map[string]*promu
if c.HostConfig.NetworkMode != "host" {
addr = discoveryutils.JoinHostPort(n.IPAddress, defaultPort)
}
m := promutils.NewLabels(16)
m := promutil.NewLabels(16)
m.Add("__address__", addr)
m.Add("__meta_docker_network_ip", n.IPAddress)
addCommonLabels(m, c, networkLabels[n.NetworkID])
@@ -156,7 +156,7 @@ func addContainersLabels(containers []container, networkLabels map[string]*promu
return ms
}
func addCommonLabels(m *promutils.Labels, c *container, networkLabels *promutils.Labels) {
func addCommonLabels(m *promutil.Labels, c *container, networkLabels *promutil.Labels) {
m.Add("__meta_docker_container_id", c.ID)
m.Add("__meta_docker_container_name", c.Names[0])
m.Add("__meta_docker_container_network_mode", c.HostConfig.NetworkMode)

View File

@@ -6,7 +6,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseContainers(t *testing.T) {
@@ -187,7 +187,7 @@ func TestParseContainers(t *testing.T) {
}
func TestAddContainerLabels(t *testing.T) {
f := func(c container, networkLabels map[string]*promutils.Labels, labelssExpected []*promutils.Labels) {
f := func(c container, networkLabels map[string]*promutil.Labels, labelssExpected []*promutil.Labels) {
t.Helper()
labelss := addContainersLabels([]container{c}, networkLabels, 8012, "foobar", false)
@@ -307,8 +307,8 @@ func TestAddContainerLabels(t *testing.T) {
},
},
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.17.0.2:8012",
"__meta_docker_container_id": "90bc3b31aa13da5c0b11af2e228d54b38428a84e25d4e249ae9e9c95e51a0700",
"__meta_docker_container_label_com_docker_compose_config_hash": "c9f0bd5bb31921f94cff367d819a30a0cc08d4399080897a6c5cd74b983156ec",
@@ -353,8 +353,8 @@ func TestAddContainerLabels(t *testing.T) {
},
},
}
labelssExpected = []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected = []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "foobar",
"__meta_docker_container_id": "90bc3b31aa13da5c0b11af2e228d54b38428a84e25d4e249ae9e9c95e51a0700",
"__meta_docker_container_label_com_docker_compose_config_hash": "c9f0bd5bb31921f94cff367d819a30a0cc08d4399080897a6c5cd74b983156ec",
@@ -407,8 +407,8 @@ func TestAddContainerLabels(t *testing.T) {
},
},
}
labelssExpected = []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected = []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.17.0.2:8080",
"__meta_docker_container_id": "90bc3b31aa13da5c0b11af2e228d54b38428a84e25d4e249ae9e9c95e51a0700",
"__meta_docker_container_label_com_docker_compose_config_hash": "c9f0bd5bb31921f94cff367d819a30a0cc08d4399080897a6c5cd74b983156ec",
@@ -575,8 +575,8 @@ func TestDockerMultiNetworkLabels(t *testing.T) {
}
// matchFirstNetwork = false
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.20.0.3:3306",
"__meta_docker_container_id": "f84b2a0cfaa58d9e70b0657e2b3c6f44f0e973de4163a871299b4acf127b224f",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -592,7 +592,7 @@ func TestDockerMultiNetworkLabels(t *testing.T) {
"__meta_docker_network_scope": "local",
"__meta_docker_port_private": "3306",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.20.0.3:33060",
"__meta_docker_container_id": "f84b2a0cfaa58d9e70b0657e2b3c6f44f0e973de4163a871299b4acf127b224f",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -608,7 +608,7 @@ func TestDockerMultiNetworkLabels(t *testing.T) {
"__meta_docker_network_scope": "local",
"__meta_docker_port_private": "33060",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.21.0.3:3306",
"__meta_docker_container_id": "f84b2a0cfaa58d9e70b0657e2b3c6f44f0e973de4163a871299b4acf127b224f",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -624,7 +624,7 @@ func TestDockerMultiNetworkLabels(t *testing.T) {
"__meta_docker_network_scope": "local",
"__meta_docker_port_private": "3306",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.21.0.3:33060",
"__meta_docker_container_id": "f84b2a0cfaa58d9e70b0657e2b3c6f44f0e973de4163a871299b4acf127b224f",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -645,8 +645,8 @@ func TestDockerMultiNetworkLabels(t *testing.T) {
discoveryutils.TestEqualLabelss(t, sortLabelss(labelss), sortLabelss(labelssExpected))
// matchFirstNetwork = true, so labels of `dockersd_private1` are removed
labelssExpected = []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected = []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.20.0.3:3306",
"__meta_docker_container_id": "f84b2a0cfaa58d9e70b0657e2b3c6f44f0e973de4163a871299b4acf127b224f",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -662,7 +662,7 @@ func TestDockerMultiNetworkLabels(t *testing.T) {
"__meta_docker_network_scope": "local",
"__meta_docker_port_private": "3306",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.20.0.3:33060",
"__meta_docker_container_id": "f84b2a0cfaa58d9e70b0657e2b3c6f44f0e973de4163a871299b4acf127b224f",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -857,8 +857,8 @@ func TestDockerLinkedNetworkSettings(t *testing.T) {
t.Fatalf("parseContainers() error: %s", err)
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.20.0.2:3306",
"__meta_docker_container_id": "f9ade4b83199d6f83020b7c0bfd1e8281b19dbf9e6cef2cf89bc45c8f8d20fe8",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -874,7 +874,7 @@ func TestDockerLinkedNetworkSettings(t *testing.T) {
"__meta_docker_network_scope": "local",
"__meta_docker_port_private": "3306",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.20.0.2:33060",
"__meta_docker_container_id": "f9ade4b83199d6f83020b7c0bfd1e8281b19dbf9e6cef2cf89bc45c8f8d20fe8",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -890,7 +890,7 @@ func TestDockerLinkedNetworkSettings(t *testing.T) {
"__meta_docker_network_scope": "local",
"__meta_docker_port_private": "33060",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.21.0.2:3306",
"__meta_docker_container_id": "f9ade4b83199d6f83020b7c0bfd1e8281b19dbf9e6cef2cf89bc45c8f8d20fe8",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -906,7 +906,7 @@ func TestDockerLinkedNetworkSettings(t *testing.T) {
"__meta_docker_network_scope": "local",
"__meta_docker_port_private": "3306",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.21.0.2:33060",
"__meta_docker_container_id": "f9ade4b83199d6f83020b7c0bfd1e8281b19dbf9e6cef2cf89bc45c8f8d20fe8",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -922,7 +922,7 @@ func TestDockerLinkedNetworkSettings(t *testing.T) {
"__meta_docker_network_scope": "local",
"__meta_docker_port_private": "33060",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.20.0.2:9104",
"__meta_docker_container_id": "59bf76e8816af98856b90dd619c91027145ca501043b1c51756d03b085882e06",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -939,7 +939,7 @@ func TestDockerLinkedNetworkSettings(t *testing.T) {
"__meta_docker_network_scope": "local",
"__meta_docker_port_private": "9104",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.21.0.2:9104",
"__meta_docker_container_id": "59bf76e8816af98856b90dd619c91027145ca501043b1c51756d03b085882e06",
"__meta_docker_container_label_com_docker_compose_project": "dockersd",
@@ -963,7 +963,7 @@ func TestDockerLinkedNetworkSettings(t *testing.T) {
}
func sortLabelss(labelss []*promutils.Labels) []*promutils.Labels {
func sortLabelss(labelss []*promutil.Labels) []*promutil.Labels {
sort.Slice(labelss, func(i, j int) bool {
return labelss[i].Get("__address__")+labelss[i].Get("__meta_docker_container_id") < labelss[j].Get("__address__")+labelss[j].Get("__meta_docker_container_id")
})

View File

@@ -6,7 +6,7 @@ import (
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -43,7 +43,7 @@ type Filter struct {
}
// GetLabels returns docker labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)

View File

@@ -6,7 +6,7 @@ import (
"strconv"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// See https://docs.docker.com/engine/api/v1.40/#tag/Network
@@ -19,7 +19,7 @@ type network struct {
Labels map[string]string
}
func getNetworksLabelsByNetworkID(cfg *apiConfig) (map[string]*promutils.Labels, error) {
func getNetworksLabelsByNetworkID(cfg *apiConfig) (map[string]*promutil.Labels, error) {
networks, err := getNetworks(cfg)
if err != nil {
return nil, err
@@ -43,10 +43,10 @@ func parseNetworks(data []byte) ([]network, error) {
return networks, nil
}
func getNetworkLabelsByNetworkID(networks []network) map[string]*promutils.Labels {
ms := make(map[string]*promutils.Labels)
func getNetworkLabelsByNetworkID(networks []network) map[string]*promutil.Labels {
ms := make(map[string]*promutil.Labels)
for _, network := range networks {
m := promutils.NewLabels(8)
m := promutil.NewLabels(8)
m.Add("__meta_docker_network_id", network.ID)
m.Add("__meta_docker_network_name", network.Name)
m.Add("__meta_docker_network_internal", strconv.FormatBool(network.Internal))

View File

@@ -6,11 +6,11 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestAddNetworkLabels(t *testing.T) {
f := func(networks []network, labelssExpected []*promutils.Labels) {
f := func(networks []network, labelssExpected []*promutil.Labels) {
t.Helper()
networkLabels := getNetworkLabelsByNetworkID(networks)
@@ -20,7 +20,7 @@ func TestAddNetworkLabels(t *testing.T) {
networkIDs = append(networkIDs, networkID)
}
sort.Strings(networkIDs)
var labelss []*promutils.Labels
var labelss []*promutil.Labels
for _, networkID := range networkIDs {
labelss = append(labelss, networkLabels[networkID])
}
@@ -39,8 +39,8 @@ func TestAddNetworkLabels(t *testing.T) {
},
},
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__meta_docker_network_id": "qs0hog6ldlei9ct11pr3c77v1",
"__meta_docker_network_ingress": "true",
"__meta_docker_network_internal": "false",

View File

@@ -6,7 +6,7 @@ import (
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -37,7 +37,7 @@ type Filter struct {
}
// GetLabels returns dockerswarm labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)

View File

@@ -6,7 +6,7 @@ import (
"strconv"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// See https://docs.docker.com/engine/api/v1.40/#tag/Network
@@ -19,7 +19,7 @@ type network struct {
Labels map[string]string
}
func getNetworksLabelsByNetworkID(cfg *apiConfig) (map[string]*promutils.Labels, error) {
func getNetworksLabelsByNetworkID(cfg *apiConfig) (map[string]*promutil.Labels, error) {
networks, err := getNetworks(cfg)
if err != nil {
return nil, err
@@ -43,10 +43,10 @@ func parseNetworks(data []byte) ([]network, error) {
return networks, nil
}
func getNetworkLabelsByNetworkID(networks []network) map[string]*promutils.Labels {
ms := make(map[string]*promutils.Labels)
func getNetworkLabelsByNetworkID(networks []network) map[string]*promutil.Labels {
ms := make(map[string]*promutil.Labels)
for _, network := range networks {
m := promutils.NewLabels(8)
m := promutil.NewLabels(8)
m.Add("__meta_dockerswarm_network_id", network.ID)
m.Add("__meta_dockerswarm_network_name", network.Name)
m.Add("__meta_dockerswarm_network_internal", strconv.FormatBool(network.Internal))

View File

@@ -6,11 +6,11 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestAddNetworkLabels(t *testing.T) {
f := func(networks []network, labelssExpected []*promutils.Labels) {
f := func(networks []network, labelssExpected []*promutil.Labels) {
t.Helper()
networkLabels := getNetworkLabelsByNetworkID(networks)
@@ -20,7 +20,7 @@ func TestAddNetworkLabels(t *testing.T) {
networkIDs = append(networkIDs, networkID)
}
sort.Strings(networkIDs)
var labelss []*promutils.Labels
var labelss []*promutil.Labels
for _, networkID := range networkIDs {
labelss = append(labelss, networkLabels[networkID])
}
@@ -39,8 +39,8 @@ func TestAddNetworkLabels(t *testing.T) {
},
},
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__meta_dockerswarm_network_id": "qs0hog6ldlei9ct11pr3c77v1",
"__meta_dockerswarm_network_ingress": "true",
"__meta_dockerswarm_network_internal": "false",

View File

@@ -5,7 +5,7 @@ import (
"fmt"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// See https://docs.docker.com/engine/api/v1.40/#tag/Node
@@ -50,7 +50,7 @@ type nodeManagerStatus struct {
Addr string
}
func getNodesLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
func getNodesLabels(cfg *apiConfig) ([]*promutil.Labels, error) {
nodes, err := getNodes(cfg)
if err != nil {
return nil, err
@@ -78,10 +78,10 @@ func parseNodes(data []byte) ([]node, error) {
return nodes, nil
}
func addNodeLabels(nodes []node, port int) []*promutils.Labels {
var ms []*promutils.Labels
func addNodeLabels(nodes []node, port int) []*promutil.Labels {
var ms []*promutil.Labels
for _, node := range nodes {
m := promutils.NewLabels(16)
m := promutil.NewLabels(16)
m.Add("__address__", discoveryutils.JoinHostPort(node.Status.Addr, port))
m.Add("__meta_dockerswarm_node_address", node.Status.Addr)
m.Add("__meta_dockerswarm_node_availability", node.Spec.Availability)

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseNodes(t *testing.T) {
@@ -80,7 +80,7 @@ func TestParseNodes(t *testing.T) {
}
func TestAddNodeLabels(t *testing.T) {
f := func(nodes []node, port int, resultExpected []*promutils.Labels) {
f := func(nodes []node, port int, resultExpected []*promutil.Labels) {
t.Helper()
result := addNodeLabels(nodes, port)
@@ -111,8 +111,8 @@ func TestAddNodeLabels(t *testing.T) {
},
},
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.31.40.97:9100",
"__meta_dockerswarm_node_address": "172.31.40.97",
"__meta_dockerswarm_node_availability": "active",

View File

@@ -7,7 +7,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// https://docs.docker.com/engine/api/v1.40/#tag/Service
@@ -60,7 +60,7 @@ type portConfig struct {
PublishedPort int
}
func getServicesLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
func getServicesLabels(cfg *apiConfig) ([]*promutil.Labels, error) {
services, err := getServices(cfg)
if err != nil {
return nil, err
@@ -102,10 +102,10 @@ func getServiceMode(svc service) string {
return ""
}
func addServicesLabels(services []service, networksLabels map[string]*promutils.Labels, port int) []*promutils.Labels {
var ms []*promutils.Labels
func addServicesLabels(services []service, networksLabels map[string]*promutil.Labels, port int) []*promutil.Labels {
var ms []*promutil.Labels
for _, service := range services {
commonLabels := promutils.NewLabels(10)
commonLabels := promutil.NewLabels(10)
commonLabels.Add("__meta_dockerswarm_service_id", service.ID)
commonLabels.Add("__meta_dockerswarm_service_name", service.Spec.Name)
commonLabels.Add("__meta_dockerswarm_service_mode", getServiceMode(service))
@@ -131,7 +131,7 @@ func addServicesLabels(services []service, networksLabels map[string]*promutils.
if ep.Protocol != "tcp" {
continue
}
m := promutils.NewLabels(24)
m := promutil.NewLabels(24)
m.Add("__address__", discoveryutils.JoinHostPort(ip.String(), ep.PublishedPort))
m.Add("__meta_dockerswarm_service_endpoint_port_name", ep.Name)
m.Add("__meta_dockerswarm_service_endpoint_port_publish_mode", ep.PublishMode)
@@ -143,7 +143,7 @@ func addServicesLabels(services []service, networksLabels map[string]*promutils.
ms = append(ms, m)
}
if !added {
m := promutils.NewLabels(24)
m := promutil.NewLabels(24)
m.Add("__address__", discoveryutils.JoinHostPort(ip.String(), port))
m.AddFrom(commonLabels)
m.AddFrom(networksLabels[vip.NetworkID])

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseServicesResponse(t *testing.T) {
@@ -126,7 +126,7 @@ func TestParseServicesResponse(t *testing.T) {
}
func TestAddServicesLabels(t *testing.T) {
f := func(services []service, networksLabels map[string]*promutils.Labels, labelssExpected []*promutils.Labels) {
f := func(services []service, networksLabels map[string]*promutil.Labels, labelssExpected []*promutil.Labels) {
t.Helper()
labelss := addServicesLabels(services, networksLabels, 9100)
@@ -167,8 +167,8 @@ func TestAddServicesLabels(t *testing.T) {
},
},
}
networksLabels := map[string]*promutils.Labels{
"qs0hog6ldlei9ct11pr3c77v1": promutils.NewLabelsFromMap(map[string]string{
networksLabels := map[string]*promutil.Labels{
"qs0hog6ldlei9ct11pr3c77v1": promutil.NewLabelsFromMap(map[string]string{
"__meta_dockerswarm_network_id": "qs0hog6ldlei9ct11pr3c77v1",
"__meta_dockerswarm_network_ingress": "true",
"__meta_dockerswarm_network_internal": "false",
@@ -177,8 +177,8 @@ func TestAddServicesLabels(t *testing.T) {
"__meta_dockerswarm_network_scope": "swarm",
}),
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.0.0.3:0",
"__meta_dockerswarm_network_id": "qs0hog6ldlei9ct11pr3c77v1",
"__meta_dockerswarm_network_ingress": "true",

View File

@@ -8,7 +8,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// See https://docs.docker.com/engine/api/v1.40/#tag/Task
@@ -50,7 +50,7 @@ type taskContainerSpec struct {
Labels map[string]string
}
func getTasksLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
func getTasksLabels(cfg *apiConfig) ([]*promutil.Labels, error) {
tasks, err := getTasks(cfg)
if err != nil {
return nil, err
@@ -91,10 +91,10 @@ func parseTasks(data []byte) ([]task, error) {
return tasks, nil
}
func addServicesLabelsForTask(services []service) []*promutils.Labels {
var ms []*promutils.Labels
func addServicesLabelsForTask(services []service) []*promutil.Labels {
var ms []*promutil.Labels
for _, svc := range services {
commonLabels := promutils.NewLabels(3)
commonLabels := promutil.NewLabels(3)
commonLabels.Add("__meta_dockerswarm_service_id", svc.ID)
commonLabels.Add("__meta_dockerswarm_service_name", svc.Spec.Name)
commonLabels.Add("__meta_dockerswarm_service_mode", getServiceMode(svc))
@@ -106,10 +106,10 @@ func addServicesLabelsForTask(services []service) []*promutils.Labels {
return ms
}
func addTasksLabels(tasks []task, nodesLabels, servicesLabels []*promutils.Labels, networksLabels map[string]*promutils.Labels, services []service, port int) []*promutils.Labels {
var ms []*promutils.Labels
func addTasksLabels(tasks []task, nodesLabels, servicesLabels []*promutil.Labels, networksLabels map[string]*promutil.Labels, services []service, port int) []*promutil.Labels {
var ms []*promutil.Labels
for _, task := range tasks {
commonLabels := promutils.NewLabels(8)
commonLabels := promutil.NewLabels(8)
commonLabels.Add("__meta_dockerswarm_task_id", task.ID)
commonLabels.Add("__meta_dockerswarm_task_container_id", task.Status.ContainerStatus.ContainerID)
commonLabels.Add("__meta_dockerswarm_task_desired_state", task.DesiredState)
@@ -132,7 +132,7 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []*promutils.Label
if port.Protocol != "tcp" {
continue
}
m := promutils.NewLabels(10)
m := promutil.NewLabels(10)
m.AddFrom(commonLabels)
m.Add("__address__", discoveryutils.JoinHostPort(commonLabels.Get("__meta_dockerswarm_node_address"), port.PublishedPort))
m.Add("__meta_dockerswarm_task_port_publish_mode", port.PublishMode)
@@ -153,7 +153,7 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []*promutils.Label
if ep.Protocol != "tcp" {
continue
}
m := promutils.NewLabels(20)
m := promutil.NewLabels(20)
m.AddFrom(commonLabels)
m.AddFrom(networkLabels)
m.Add("__address__", discoveryutils.JoinHostPort(ip.String(), ep.PublishedPort))
@@ -164,7 +164,7 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []*promutils.Label
added = true
}
if !added {
m := promutils.NewLabels(20)
m := promutil.NewLabels(20)
m.AddFrom(commonLabels)
m.AddFrom(networkLabels)
m.Add("__address__", discoveryutils.JoinHostPort(ip.String(), port))
@@ -179,7 +179,7 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []*promutils.Label
}
// addLabels adds labels from src to dst if they contain the given `key: value` pair.
func addLabels(dst *promutils.Labels, src []*promutils.Labels, key, value string) {
func addLabels(dst *promutil.Labels, src []*promutil.Labels, key, value string) {
for _, m := range src {
if m.Get(key) != value {
continue

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseTasks(t *testing.T) {
@@ -93,7 +93,7 @@ func TestParseTasks(t *testing.T) {
}
func TestAddTasksLabels(t *testing.T) {
f := func(tasks []task, nodesLabels []*promutils.Labels, networkLabels map[string]*promutils.Labels, serviceLabels []*promutils.Labels, services []service, labelssExpected []*promutils.Labels) {
f := func(tasks []task, nodesLabels []*promutil.Labels, networkLabels map[string]*promutil.Labels, serviceLabels []*promutil.Labels, services []service, labelssExpected []*promutil.Labels) {
t.Helper()
labelss := addTasksLabels(tasks, nodesLabels, serviceLabels, networkLabels, services, 9100)
@@ -126,21 +126,21 @@ func TestAddTasksLabels(t *testing.T) {
},
}
svcLabels := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
svcLabels := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__meta_dockerswarm_service_id": "t91nf284wzle1ya09lqvyjgnq",
"__meta_dockerswarm_service_name": "real_service_name",
"__meta_dockerswarm_service_mode": "real_service_mode",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__meta_dockerswarm_service_id": "fake_service_id",
"__meta_dockerswarm_service_name": "fake_service_name",
"__meta_dockerswarm_service_mode": "fake_service_mode",
}),
}
nodesLabels := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
nodesLabels := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.31.40.97:9100",
"__meta_dockerswarm_node_address": "172.31.40.97",
"__meta_dockerswarm_node_availability": "active",
@@ -154,8 +154,8 @@ func TestAddTasksLabels(t *testing.T) {
}),
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.31.40.97:6379",
"__meta_dockerswarm_node_address": "172.31.40.97",
"__meta_dockerswarm_node_availability": "active",
@@ -205,8 +205,8 @@ func TestAddTasksLabels(t *testing.T) {
},
}
networksLabels := map[string]*promutils.Labels{
"qs0hog6ldlei9ct11pr3c77v1": promutils.NewLabelsFromMap(map[string]string{
networksLabels := map[string]*promutil.Labels{
"qs0hog6ldlei9ct11pr3c77v1": promutil.NewLabelsFromMap(map[string]string{
"__meta_dockerswarm_network_id": "qs0hog6ldlei9ct11pr3c77v1",
"__meta_dockerswarm_network_ingress": "true",
"__meta_dockerswarm_network_internal": "false",
@@ -216,8 +216,8 @@ func TestAddTasksLabels(t *testing.T) {
}),
}
nodesLabels = []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
nodesLabels = []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.31.40.97:9100",
"__meta_dockerswarm_node_address": "172.31.40.97",
"__meta_dockerswarm_node_availability": "active",
@@ -231,13 +231,13 @@ func TestAddTasksLabels(t *testing.T) {
}),
}
svcLabels = []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
svcLabels = []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__meta_dockerswarm_service_id": "tgsci5gd31aai3jyudv98pqxf",
"__meta_dockerswarm_service_name": "redis2",
"__meta_dockerswarm_service_mode": "replicated",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__meta_dockerswarm_service_id": "fake_service_id",
"__meta_dockerswarm_service_name": "fake_service_name",
"__meta_dockerswarm_service_mode": "fake_service_mode",
@@ -279,8 +279,8 @@ func TestAddTasksLabels(t *testing.T) {
},
}
labelssExpected = []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected = []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.10.15.15:6379",
"__meta_dockerswarm_network_id": "qs0hog6ldlei9ct11pr3c77v1",
"__meta_dockerswarm_network_ingress": "true",

View File

@@ -7,7 +7,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/awsapi"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// SDCheckInterval defines interval for targets refresh.
@@ -35,7 +35,7 @@ type SDConfig struct {
}
// GetLabels returns ec2 labels according to sdc.
func (sdc *SDConfig) GetLabels(_ string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(_ string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)

View File

@@ -7,18 +7,18 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/awsapi"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// getInstancesLabels returns labels for ec2 instances obtained from the given cfg
func getInstancesLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
func getInstancesLabels(cfg *apiConfig) ([]*promutil.Labels, error) {
rs, err := getReservations(cfg)
if err != nil {
return nil, err
}
azMap := getAZMap(cfg)
region := cfg.awsConfig.GetRegion()
var ms []*promutils.Labels
var ms []*promutil.Labels
for _, r := range rs {
for _, inst := range r.InstanceSet.Items {
ms = inst.appendTargetLabels(ms, r.OwnerID, region, cfg.port, azMap)
@@ -136,13 +136,13 @@ func parseInstancesResponse(data []byte) (*InstancesResponse, error) {
return &v, nil
}
func (inst *Instance) appendTargetLabels(ms []*promutils.Labels, ownerID, region string, port int, azMap map[string]string) []*promutils.Labels {
func (inst *Instance) appendTargetLabels(ms []*promutil.Labels, ownerID, region string, port int, azMap map[string]string) []*promutil.Labels {
if len(inst.PrivateIPAddress) == 0 {
// Cannot scrape instance without private IP address
return ms
}
addr := discoveryutils.JoinHostPort(inst.PrivateIPAddress, port)
m := promutils.NewLabels(24)
m := promutil.NewLabels(24)
m.Add("__address__", addr)
m.Add("__meta_ec2_architecture", inst.Architecture)
m.Add("__meta_ec2_ami", inst.ImageID)

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestDescribeAvailabilityZonesResponse(t *testing.T) {
@@ -241,8 +241,8 @@ func TestParseInstancesResponse(t *testing.T) {
labelss := inst.appendTargetLabels(nil, ownerID, "region-a", port, map[string]string{
"eu-west-2c": "foobar-zone",
})
expectedLabels := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabels := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.31.11.152:423",
"__meta_ec2_architecture": "x86_64",
"__meta_ec2_availability_zone": "eu-west-2c",

View File

@@ -9,7 +9,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -83,7 +83,7 @@ type DataCenterInfo struct {
}
// GetLabels returns Eureka labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)
@@ -108,8 +108,8 @@ func (sdc *SDConfig) MustStop() {
}
}
func addInstanceLabels(apps *applications) []*promutils.Labels {
var ms []*promutils.Labels
func addInstanceLabels(apps *applications) []*promutil.Labels {
var ms []*promutil.Labels
for _, app := range apps.Applications {
for _, instance := range app.Instances {
instancePort := 80
@@ -117,7 +117,7 @@ func addInstanceLabels(apps *applications) []*promutils.Labels {
instancePort = instance.Port.Port
}
targetAddress := discoveryutils.JoinHostPort(instance.HostName, instancePort)
m := promutils.NewLabels(24)
m := promutil.NewLabels(24)
m.Add("__address__", targetAddress)
m.Add("instance", instance.InstanceID)
m.Add("__meta_eureka_app_name", app.Name)

View File

@@ -4,11 +4,11 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestAddInstanceLabels(t *testing.T) {
f := func(applications *applications, labelssExpected []*promutils.Labels) {
f := func(applications *applications, labelssExpected []*promutil.Labels) {
t.Helper()
labelss := addInstanceLabels(applications)
@@ -47,8 +47,8 @@ func TestAddInstanceLabels(t *testing.T) {
},
},
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "host-1:9100",
"instance": "some-id",
"__meta_eureka_app_instance_hostname": "host-1",

View File

@@ -5,7 +5,7 @@ import (
"fmt"
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// SDCheckInterval defines interval for targets refresh.
@@ -62,7 +62,7 @@ func (z ZoneYAML) MarshalYAML() (any, error) {
}
// GetLabels returns gce labels according to sdc.
func (sdc *SDConfig) GetLabels(_ string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(_ string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)

View File

@@ -8,13 +8,13 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// getInstancesLabels returns labels for gce instances obtained from the given cfg
func getInstancesLabels(cfg *apiConfig) []*promutils.Labels {
func getInstancesLabels(cfg *apiConfig) []*promutil.Labels {
insts := getInstances(cfg)
var ms []*promutils.Labels
var ms []*promutil.Labels
for _, inst := range insts {
ms = inst.appendTargetLabels(ms, cfg.project, cfg.tagSeparator, cfg.port)
}
@@ -89,7 +89,7 @@ type Instance struct {
NetworkInterfaces []NetworkInterface
Tags TagList
Metadata MetadataList
Labels *promutils.Labels
Labels *promutil.Labels
}
// NetworkInterface is network interface from https://cloud.google.com/compute/docs/reference/rest/v1/instances/list
@@ -132,13 +132,13 @@ func parseInstanceList(data []byte) (*InstanceList, error) {
return &il, nil
}
func (inst *Instance) appendTargetLabels(ms []*promutils.Labels, project, tagSeparator string, port int) []*promutils.Labels {
func (inst *Instance) appendTargetLabels(ms []*promutil.Labels, project, tagSeparator string, port int) []*promutil.Labels {
if len(inst.NetworkInterfaces) == 0 {
return ms
}
iface := inst.NetworkInterfaces[0]
addr := discoveryutils.JoinHostPort(iface.NetworkIP, port)
m := promutils.NewLabels(24)
m := promutil.NewLabels(24)
m.Add("__address__", addr)
m.Add("__meta_gce_instance_id", inst.ID)
m.Add("__meta_gce_instance_status", inst.Status)

View File

@@ -4,7 +4,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseInstanceListFailure(t *testing.T) {
@@ -147,8 +147,8 @@ func TestParseInstanceListSuccess(t *testing.T) {
tagSeparator := ","
port := 80
labelss := inst.appendTargetLabels(nil, project, tagSeparator, port)
expectedLabelss := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabelss := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.11.2.7:80",
"__meta_gce_instance_id": "7897352091592122",
"__meta_gce_instance_name": "play-1m-1-vmagent",

View File

@@ -6,11 +6,11 @@ import (
"net"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// getHCloudServerLabels returns labels for hcloud servers obtained from the given cfg
func getHCloudServerLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
func getHCloudServerLabels(cfg *apiConfig) ([]*promutil.Labels, error) {
networks, err := getHCloudNetworks(cfg)
if err != nil {
return nil, err
@@ -19,15 +19,15 @@ func getHCloudServerLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
if err != nil {
return nil, err
}
var ms []*promutils.Labels
var ms []*promutil.Labels
for i := range servers {
ms = appendHCloudTargetLabels(ms, &servers[i], networks, cfg.port)
}
return ms, nil
}
func appendHCloudTargetLabels(ms []*promutils.Labels, server *HCloudServer, networks []HCloudNetwork, port int) []*promutils.Labels {
m := promutils.NewLabels(24)
func appendHCloudTargetLabels(ms []*promutil.Labels, server *HCloudServer, networks []HCloudNetwork, port int) []*promutil.Labels {
m := promutil.NewLabels(24)
addr := discoveryutils.JoinHostPort(server.PublicNet.IPv4.IP, port)
m.Add("__address__", addr)

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseHCloudNetworksList(t *testing.T) {
@@ -312,8 +312,8 @@ func TestParseHCloudServerListResponse(t *testing.T) {
}
labelss := appendHCloudTargetLabels(nil, &sl[0], networks, port)
expectedLabels := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabels := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "1.2.3.4:123",
"__meta_hetzner_role": "hcloud",
"__meta_hetzner_server_id": "42",

View File

@@ -7,7 +7,7 @@ import (
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -28,7 +28,7 @@ type SDConfig struct {
}
// GetLabels returns Hetzner target labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)

View File

@@ -7,23 +7,23 @@ import (
"strings"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func getRobotServerLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
func getRobotServerLabels(cfg *apiConfig) ([]*promutil.Labels, error) {
servers, err := getRobotServers(cfg)
if err != nil {
return nil, err
}
var ms []*promutils.Labels
var ms []*promutil.Labels
for i := range servers {
ms = appendRobotTargetLabels(ms, &servers[i], cfg.port)
}
return ms, nil
}
func appendRobotTargetLabels(ms []*promutils.Labels, server *RobotServer, port int) []*promutils.Labels {
m := promutils.NewLabels(16)
func appendRobotTargetLabels(ms []*promutil.Labels, server *RobotServer, port int) []*promutil.Labels {
m := promutil.NewLabels(16)
addr := discoveryutils.JoinHostPort(server.ServerIP, port)
m.Add("__address__", addr)

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseRobotServerListResponse(t *testing.T) {
@@ -93,8 +93,8 @@ func TestParseRobotServerListResponse(t *testing.T) {
port := 123
labelss := appendRobotTargetLabels(nil, &rsl[0], port)
expectedLabels := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabels := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "123.123.123.123:123",
"__meta_hetzner_role": "robot",
"__meta_hetzner_server_id": "321",

View File

@@ -8,7 +8,7 @@ import (
"strconv"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/metrics"
)
@@ -25,8 +25,8 @@ type apiConfig struct {
// httpGroupTarget represent prometheus GroupTarget
// https://prometheus.io/docs/prometheus/latest/http_sd/
type httpGroupTarget struct {
Targets []string `json:"targets"`
Labels *promutils.Labels `json:"labels"`
Targets []string `json:"targets"`
Labels *promutil.Labels `json:"labels"`
}
func newAPIConfig(sdc *SDConfig, baseDir string) (*apiConfig, error) {

View File

@@ -4,7 +4,7 @@ import (
"reflect"
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseAPIResponse(t *testing.T) {
@@ -28,7 +28,7 @@ func TestParseAPIResponse(t *testing.T) {
path := "/ok"
resultExpected := []httpGroupTarget{
{
Labels: promutils.NewLabelsFromMap(map[string]string{"label-1": "value-1"}),
Labels: promutil.NewLabelsFromMap(map[string]string{"label-1": "value-1"}),
Targets: []string{"http://target-1:9100", "http://target-2:9150"},
},
}

View File

@@ -6,7 +6,7 @@ import (
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -26,7 +26,7 @@ type SDConfig struct {
}
// GetLabels returns http service discovery labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)
@@ -38,12 +38,12 @@ func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
return addHTTPTargetLabels(hts, sdc.URL), nil
}
func addHTTPTargetLabels(src []httpGroupTarget, sourceURL string) []*promutils.Labels {
ms := make([]*promutils.Labels, 0, len(src))
func addHTTPTargetLabels(src []httpGroupTarget, sourceURL string) []*promutil.Labels {
ms := make([]*promutil.Labels, 0, len(src))
for _, targetGroup := range src {
labels := targetGroup.Labels
for _, target := range targetGroup.Targets {
m := promutils.NewLabels(2 + labels.Len())
m := promutil.NewLabels(2 + labels.Len())
m.AddFrom(labels)
m.Add("__address__", target)
m.Add("__meta_url", sourceURL)

View File

@@ -4,11 +4,11 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestAddHTTPTargetLabels(t *testing.T) {
f := func(src []httpGroupTarget, labelssExpected []*promutils.Labels) {
f := func(src []httpGroupTarget, labelssExpected []*promutil.Labels) {
t.Helper()
labelss := addHTTPTargetLabels(src, "http://foo.bar/baz?aaa=bb")
@@ -19,17 +19,17 @@ func TestAddHTTPTargetLabels(t *testing.T) {
src := []httpGroupTarget{
{
Targets: []string{"127.0.0.1:9100", "127.0.0.2:91001"},
Labels: promutils.NewLabelsFromMap(map[string]string{"__meta_kubernetes_pod": "pod-1", "__meta_consul_dc": "dc-2"}),
Labels: promutil.NewLabelsFromMap(map[string]string{"__meta_kubernetes_pod": "pod-1", "__meta_consul_dc": "dc-2"}),
},
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "127.0.0.1:9100",
"__meta_kubernetes_pod": "pod-1",
"__meta_consul_dc": "dc-2",
"__meta_url": "http://foo.bar/baz?aaa=bb",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "127.0.0.2:91001",
"__meta_kubernetes_pod": "pod-1",
"__meta_consul_dc": "dc-2",

View File

@@ -23,7 +23,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/netutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/timerpool"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/timeutil"
)
@@ -49,7 +49,7 @@ type object interface {
key() string
// getTargetLabels must be called under gw.mu lock.
getTargetLabels(gw *groupWatcher) []*promutils.Labels
getTargetLabels(gw *groupWatcher) []*promutil.Labels
}
// parseObjectFunc must parse object from the given data.
@@ -154,7 +154,7 @@ func (aw *apiWatcher) updateScrapeWorks(uw *urlWatcher, swosByKey map[string][]a
aw.swosByURLWatcherLock.Unlock()
}
func (aw *apiWatcher) setScrapeWorks(uw *urlWatcher, key string, labelss []*promutils.Labels) {
func (aw *apiWatcher) setScrapeWorks(uw *urlWatcher, key string, labelss []*promutil.Labels) {
swos := getScrapeWorkObjectsForLabels(aw.swcFunc, labelss)
aw.swosByURLWatcherLock.Lock()
swosByKey := aw.swosByURLWatcher[uw]
@@ -181,7 +181,7 @@ func (aw *apiWatcher) removeScrapeWorks(uw *urlWatcher, key string) {
aw.swosByURLWatcherLock.Unlock()
}
func getScrapeWorkObjectsForLabels(swcFunc ScrapeWorkConstructorFunc, labelss []*promutils.Labels) []any {
func getScrapeWorkObjectsForLabels(swcFunc ScrapeWorkConstructorFunc, labelss []*promutil.Labels) []any {
// Do not pre-allocate swos, since it is likely the swos will be empty because of relabeling
var swos []any
for _, labels := range labelss {
@@ -404,7 +404,7 @@ func (gw *groupWatcher) getScrapeWorkObjectsByAPIWatcherLocked(objectsByKey map[
labelss := o.getTargetLabels(gw)
wg.Add(1)
limiterCh <- struct{}{}
go func(key string, labelss []*promutils.Labels) {
go func(key string, labelss []*promutil.Labels) {
for aw, e := range swosByAPIWatcher {
swos := getScrapeWorkObjectsForLabels(aw.swcFunc, labelss)
e.mu.Lock()
@@ -420,9 +420,9 @@ func (gw *groupWatcher) getScrapeWorkObjectsByAPIWatcherLocked(objectsByKey map[
return swosByAPIWatcher
}
func putLabelssToPool(labelss []*promutils.Labels) {
func putLabelssToPool(labelss []*promutil.Labels) {
for _, labels := range labelss {
promutils.PutLabels(labels)
promutil.PutLabels(labels)
}
}

View File

@@ -9,7 +9,7 @@ import (
"testing"
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestGetAPIPathsWithNamespaces(t *testing.T) {
@@ -921,7 +921,7 @@ func TestGetScrapeWorkObjects(t *testing.T) {
}
testAPIServer := httptest.NewServer(mux)
tc.sdc.APIServer = testAPIServer.URL
ac, err := newAPIConfig(tc.sdc, "", func(metaLabels *promutils.Labels) any {
ac, err := newAPIConfig(tc.sdc, "", func(metaLabels *promutil.Labels) any {
var res []any
for _, label := range metaLabels.Labels {
res = append(res, label.Name)

View File

@@ -3,7 +3,7 @@ package kubernetes
import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// ObjectMeta represents ObjectMeta from k8s API.
@@ -13,8 +13,8 @@ type ObjectMeta struct {
Name string
Namespace string
UID string
Labels *promutils.Labels
Annotations *promutils.Labels
Labels *promutil.Labels
Annotations *promutil.Labels
OwnerReferences []OwnerReference
}
@@ -28,7 +28,7 @@ type ListMeta struct {
ResourceVersion string
}
func (om *ObjectMeta) registerLabelsAndAnnotations(prefix string, m *promutils.Labels) {
func (om *ObjectMeta) registerLabelsAndAnnotations(prefix string, m *promutil.Labels) {
bb := bbPool.Get()
b := bb.B
for _, lb := range om.Labels.GetLabels() {

View File

@@ -7,7 +7,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func (eps *Endpoints) key() string {
@@ -92,13 +92,13 @@ type EndpointPort struct {
// getTargetLabels returns labels for each endpoint in eps.
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#endpoints
func (eps *Endpoints) getTargetLabels(gw *groupWatcher) []*promutils.Labels {
func (eps *Endpoints) getTargetLabels(gw *groupWatcher) []*promutil.Labels {
var svc *Service
if o := gw.getObjectByRoleLocked("service", eps.Metadata.Namespace, eps.Metadata.Name); o != nil {
svc = o.(*Service)
}
podPortsSeen := make(map[*Pod][]int)
var ms []*promutils.Labels
var ms []*promutil.Labels
for _, ess := range eps.Subsets {
for _, epp := range ess.Ports {
ms = appendEndpointLabelsForAddresses(ms, gw, podPortsSeen, eps, ess.Addresses, epp, svc, "true")
@@ -129,7 +129,7 @@ func (eps *Endpoints) getTargetLabels(gw *groupWatcher) []*promutils.Labels {
continue
}
addr := discoveryutils.JoinHostPort(p.Status.PodIP, cp.ContainerPort)
m := promutils.GetLabels()
m := promutil.GetLabels()
m.Add("__address__", addr)
p.appendCommonLabels(m, gw)
p.appendContainerLabels(m, c, &cp, isInit)
@@ -161,8 +161,8 @@ func (eps *Endpoints) getTargetLabels(gw *groupWatcher) []*promutils.Labels {
return ms
}
func appendEndpointLabelsForAddresses(ms []*promutils.Labels, gw *groupWatcher, podPortsSeen map[*Pod][]int, eps *Endpoints,
eas []EndpointAddress, epp EndpointPort, svc *Service, ready string) []*promutils.Labels {
func appendEndpointLabelsForAddresses(ms []*promutil.Labels, gw *groupWatcher, podPortsSeen map[*Pod][]int, eps *Endpoints,
eas []EndpointAddress, epp EndpointPort, svc *Service, ready string) []*promutil.Labels {
for _, ea := range eas {
var p *Pod
if ea.TargetRef.Name != "" {
@@ -179,7 +179,7 @@ func appendEndpointLabelsForAddresses(ms []*promutils.Labels, gw *groupWatcher,
}
func getEndpointLabelsForAddressAndPort(gw *groupWatcher, podPortsSeen map[*Pod][]int, eps *Endpoints, ea EndpointAddress, epp EndpointPort,
p *Pod, svc *Service, ready string) *promutils.Labels {
p *Pod, svc *Service, ready string) *promutil.Labels {
m := getEndpointLabels(eps.Metadata, ea, epp, ready)
if svc != nil {
svc.appendCommonLabels(m)
@@ -220,9 +220,9 @@ func getEndpointLabelsForAddressAndPort(gw *groupWatcher, podPortsSeen map[*Pod]
return m
}
func getEndpointLabels(om ObjectMeta, ea EndpointAddress, epp EndpointPort, ready string) *promutils.Labels {
func getEndpointLabels(om ObjectMeta, ea EndpointAddress, epp EndpointPort, ready string) *promutil.Labels {
addr := discoveryutils.JoinHostPort(ea.IP, epp.Port)
m := promutils.GetLabels()
m := promutil.GetLabels()
m.Add("__address__", addr)
m.Add("__meta_kubernetes_namespace", om.Namespace)
m.Add("__meta_kubernetes_endpoints_name", om.Name)

View File

@@ -4,7 +4,7 @@ import (
"bytes"
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseEndpointsListFailure(t *testing.T) {
@@ -90,8 +90,8 @@ func TestParseEndpointsListSuccess(t *testing.T) {
}
sortedLabelss := getSortedLabelss(objectsByKey)
expectedLabelss := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabelss := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.17.0.2:8443",
"__meta_kubernetes_endpoint_address_target_kind": "Pod",
"__meta_kubernetes_endpoint_address_target_name": "coredns-6955765f44-lnp6t",
@@ -119,7 +119,7 @@ func TestGetEndpointsLabels(t *testing.T) {
initContainerPorts map[string][]ContainerPort
endpointPorts []EndpointPort
}
f := func(t *testing.T, args testArgs, wantLabels []*promutils.Labels) {
f := func(t *testing.T, args testArgs, wantLabels []*promutil.Labels) {
t.Helper()
eps := Endpoints{
Metadata: ObjectMeta{
@@ -175,7 +175,7 @@ func TestGetEndpointsLabels(t *testing.T) {
}
node := Node{
Metadata: ObjectMeta{
Labels: promutils.NewLabelsFromMap(map[string]string{"node-label": "xyz"}),
Labels: promutil.NewLabelsFromMap(map[string]string{"node-label": "xyz"}),
},
}
for cn, ports := range args.initContainerPorts {
@@ -215,7 +215,7 @@ func TestGetEndpointsLabels(t *testing.T) {
},
}
gw.attachNodeMetadata = true
var sortedLabelss []*promutils.Labels
var sortedLabelss []*promutil.Labels
gotLabels := eps.getTargetLabels(&gw)
for _, lbs := range gotLabels {
lbs.Sort()
@@ -235,8 +235,8 @@ func TestGetEndpointsLabels(t *testing.T) {
Protocol: "foobar",
},
},
}, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
}, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.13.15.15:8081",
"__meta_kubernetes_endpoint_address_target_kind": "Pod",
"__meta_kubernetes_endpoint_address_target_name": "test-pod",
@@ -276,8 +276,8 @@ func TestGetEndpointsLabels(t *testing.T) {
Protocol: "https",
},
},
}, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
}, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.13.15.15:8081",
"__meta_kubernetes_endpoint_address_target_kind": "Pod",
"__meta_kubernetes_endpoint_address_target_name": "test-pod",
@@ -300,7 +300,7 @@ func TestGetEndpointsLabels(t *testing.T) {
"__meta_kubernetes_service_name": "test-eps",
"__meta_kubernetes_service_type": "service-type",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "192.168.15.1:8428",
"__meta_kubernetes_endpoint_address_target_kind": "Pod",
"__meta_kubernetes_endpoint_address_target_name": "test-pod",
@@ -343,8 +343,8 @@ func TestGetEndpointsLabels(t *testing.T) {
Protocol: "xabc",
},
},
}, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
}, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.13.15.15:8428",
"__meta_kubernetes_endpoint_address_target_kind": "Pod",
"__meta_kubernetes_endpoint_address_target_name": "test-pod",
@@ -390,8 +390,8 @@ func TestGetEndpointsLabels(t *testing.T) {
Protocol: "xabc",
},
},
}, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
}, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.13.15.15:8428",
"__meta_kubernetes_endpoint_address_target_kind": "Pod",
"__meta_kubernetes_endpoint_address_target_name": "test-pod",

View File

@@ -7,7 +7,7 @@ import (
"strconv"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func (eps *EndpointSlice) key() string {
@@ -38,7 +38,7 @@ func parseEndpointSlice(data []byte) (object, error) {
// getTargetLabels returns labels for eps.
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#endpointslices
func (eps *EndpointSlice) getTargetLabels(gw *groupWatcher) []*promutils.Labels {
func (eps *EndpointSlice) getTargetLabels(gw *groupWatcher) []*promutil.Labels {
// The associated service name is stored in kubernetes.io/service-name label.
// See https://kubernetes.io/docs/reference/labels-annotations-taints/#kubernetesioservice-name
svcName := eps.Metadata.Labels.Get("kubernetes.io/service-name")
@@ -47,7 +47,7 @@ func (eps *EndpointSlice) getTargetLabels(gw *groupWatcher) []*promutils.Labels
svc = o.(*Service)
}
podPortsSeen := make(map[*Pod][]int)
var ms []*promutils.Labels
var ms []*promutil.Labels
for _, ess := range eps.Endpoints {
var p *Pod
if o := gw.getObjectByRoleLocked("pod", ess.TargetRef.Namespace, ess.TargetRef.Name); o != nil {
@@ -79,7 +79,7 @@ func (eps *EndpointSlice) getTargetLabels(gw *groupWatcher) []*promutils.Labels
continue
}
addr := discoveryutils.JoinHostPort(p.Status.PodIP, cp.ContainerPort)
m := promutils.GetLabels()
m := promutil.GetLabels()
m.Add("__address__", addr)
p.appendCommonLabels(m, gw)
p.appendContainerLabels(m, c, &cp, isInit)
@@ -118,7 +118,7 @@ func (eps *EndpointSlice) getTargetLabels(gw *groupWatcher) []*promutils.Labels
// p appended to seen Ports
// if TargetRef matches
func getEndpointSliceLabelsForAddressAndPort(gw *groupWatcher, podPortsSeen map[*Pod][]int, addr string, eps *EndpointSlice, ea Endpoint, epp EndpointPort,
p *Pod, svc *Service) *promutils.Labels {
p *Pod, svc *Service) *promutil.Labels {
m := getEndpointSliceLabels(eps, addr, ea, epp)
if svc != nil {
svc.appendCommonLabels(m)
@@ -157,9 +157,9 @@ func getEndpointSliceLabelsForAddressAndPort(gw *groupWatcher, podPortsSeen map[
}
// //getEndpointSliceLabels builds labels for given EndpointSlice
func getEndpointSliceLabels(eps *EndpointSlice, addr string, ea Endpoint, epp EndpointPort) *promutils.Labels {
func getEndpointSliceLabels(eps *EndpointSlice, addr string, ea Endpoint, epp EndpointPort) *promutil.Labels {
addr = discoveryutils.JoinHostPort(addr, epp.Port)
m := promutils.GetLabels()
m := promutil.GetLabels()
m.Add("__address__", addr)
m.Add("__meta_kubernetes_namespace", eps.Metadata.Namespace)
m.Add("__meta_kubernetes_endpointslice_name", eps.Metadata.Name)

View File

@@ -4,7 +4,7 @@ import (
"bytes"
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseEndpointSliceListFail(t *testing.T) {
@@ -163,8 +163,8 @@ func TestParseEndpointSliceListSuccess(t *testing.T) {
t.Fatalf("unexpected resource version; got %s; want %s", meta.ResourceVersion, expectedResourceVersion)
}
sortedLabelss := getSortedLabelss(objectsByKey)
expectedLabelss := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabelss := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.244.0.3:53",
"__meta_kubernetes_endpointslice_address_target_kind": "Pod",
"__meta_kubernetes_endpointslice_address_target_name": "coredns-66bff467f8-z8czk",
@@ -184,7 +184,7 @@ func TestParseEndpointSliceListSuccess(t *testing.T) {
"__meta_kubernetes_endpointslice_port_protocol": "UDP",
"__meta_kubernetes_namespace": "kube-system",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.244.0.3:9153",
"__meta_kubernetes_endpointslice_address_target_kind": "Pod",
"__meta_kubernetes_endpointslice_address_target_name": "coredns-66bff467f8-z8czk",
@@ -204,7 +204,7 @@ func TestParseEndpointSliceListSuccess(t *testing.T) {
"__meta_kubernetes_endpointslice_port_protocol": "TCP",
"__meta_kubernetes_namespace": "kube-system",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.18.0.2:6443",
"__meta_kubernetes_endpointslice_address_type": "IPv4",
"__meta_kubernetes_endpointslice_endpoint_conditions_ready": "true",
@@ -229,13 +229,13 @@ func TestGetEndpointsliceLabels(t *testing.T) {
containerPorts map[string][]ContainerPort
endpointPorts []EndpointPort
}
f := func(t *testing.T, args testArgs, wantLabels []*promutils.Labels) {
f := func(t *testing.T, args testArgs, wantLabels []*promutil.Labels) {
t.Helper()
eps := EndpointSlice{
Metadata: ObjectMeta{
Name: "test-eps",
Namespace: "default",
Labels: promutils.NewLabelsFromMap(map[string]string{
Labels: promutil.NewLabelsFromMap(map[string]string{
"kubernetes.io/service-name": "test-svc",
}),
},
@@ -294,7 +294,7 @@ func TestGetEndpointsliceLabels(t *testing.T) {
}
node := Node{
Metadata: ObjectMeta{
Labels: promutils.NewLabelsFromMap(map[string]string{"node-label": "xyz"}),
Labels: promutil.NewLabelsFromMap(map[string]string{"node-label": "xyz"}),
},
}
for cn, ports := range args.initContainerPorts {
@@ -334,7 +334,7 @@ func TestGetEndpointsliceLabels(t *testing.T) {
},
}
gw.attachNodeMetadata = true
var sortedLabelss []*promutils.Labels
var sortedLabelss []*promutil.Labels
gotLabels := eps.getTargetLabels(&gw)
for _, lbs := range gotLabels {
lbs.Sort()
@@ -354,8 +354,8 @@ func TestGetEndpointsliceLabels(t *testing.T) {
Protocol: "foobar",
},
},
}, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
}, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.13.15.15:8081",
"__meta_kubernetes_endpointslice_address_target_kind": "Pod",
"__meta_kubernetes_endpointslice_address_target_name": "test-pod",
@@ -402,8 +402,8 @@ func TestGetEndpointsliceLabels(t *testing.T) {
Protocol: "https",
},
},
}, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
}, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.13.15.15:8081",
"__meta_kubernetes_endpointslice_address_target_kind": "Pod",
"__meta_kubernetes_endpointslice_address_target_name": "test-pod",
@@ -433,7 +433,7 @@ func TestGetEndpointsliceLabels(t *testing.T) {
"__meta_kubernetes_service_name": "test-svc",
"__meta_kubernetes_service_type": "service-type",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "192.168.15.1:8428",
"__meta_kubernetes_endpointslice_address_target_kind": "Pod",
"__meta_kubernetes_endpointslice_address_target_name": "test-pod",
@@ -479,8 +479,8 @@ func TestGetEndpointsliceLabels(t *testing.T) {
Protocol: "xabc",
},
},
}, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
}, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.13.15.15:8428",
"__meta_kubernetes_endpointslice_address_target_kind": "Pod",
"__meta_kubernetes_endpointslice_address_target_name": "test-pod",
@@ -533,8 +533,8 @@ func TestGetEndpointsliceLabels(t *testing.T) {
Protocol: "xabc",
},
},
}, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
}, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.13.15.15:8428",
"__meta_kubernetes_endpointslice_address_target_kind": "Pod",
"__meta_kubernetes_endpointslice_address_target_name": "test-pod",

View File

@@ -6,7 +6,7 @@ import (
"io"
"strings"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func (ig *Ingress) key() string {
@@ -91,8 +91,8 @@ type HTTPIngressPath struct {
// getTargetLabels returns labels for ig.
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#ingress
func (ig *Ingress) getTargetLabels(_ *groupWatcher) []*promutils.Labels {
var ms []*promutils.Labels
func (ig *Ingress) getTargetLabels(_ *groupWatcher) []*promutil.Labels {
var ms []*promutil.Labels
for _, r := range ig.Spec.Rules {
paths := getIngressRulePaths(r.HTTP.Paths)
scheme := getSchemeForHost(r.Host, ig.Spec.TLS)
@@ -131,8 +131,8 @@ func matchesHostPattern(pattern, host string) bool {
return pattern == host
}
func getLabelsForIngressPath(ig *Ingress, scheme, host, path string) *promutils.Labels {
m := promutils.GetLabels()
func getLabelsForIngressPath(ig *Ingress, scheme, host, path string) *promutil.Labels {
m := promutil.GetLabels()
m.Add("__address__", host)
m.Add("__meta_kubernetes_namespace", ig.Metadata.Namespace)
m.Add("__meta_kubernetes_ingress_name", ig.Metadata.Name)

View File

@@ -4,7 +4,7 @@ import (
"bytes"
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestMatchesHostPattern(t *testing.T) {
@@ -102,8 +102,8 @@ func TestParseIngressListSuccess(t *testing.T) {
t.Fatalf("unexpected resource version; got %s; want %s", meta.ResourceVersion, expectedResourceVersion)
}
sortedLabelss := getSortedLabelss(objectsByKey)
expectedLabelss := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabelss := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "foobar",
"__meta_kubernetes_ingress_annotation_kubectl_kubernetes_io_last_applied_configuration": `{"apiVersion":"networking.k8s.io/v1","kind":"Ingress","metadata":{"annotations":{},"name":"test-ingress","namespace":"default"},"spec":{"backend":{"serviceName":"testsvc","servicePort":80}}}` + "\n",
"__meta_kubernetes_ingress_annotationpresent_kubectl_kubernetes_io_last_applied_configuration": "true",

View File

@@ -6,7 +6,7 @@ import (
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -70,7 +70,7 @@ type Selector struct {
}
// ScrapeWorkConstructorFunc must construct ScrapeWork object for the given metaLabels.
type ScrapeWorkConstructorFunc func(metaLabels *promutils.Labels) any
type ScrapeWorkConstructorFunc func(metaLabels *promutil.Labels) any
// GetScrapeWorkObjects returns ScrapeWork objects for the given sdc.
//

View File

@@ -6,7 +6,7 @@ import (
"io"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// getNodesLabels returns labels for k8s nodes obtained from the given cfg
@@ -85,14 +85,14 @@ type NodeDaemonEndpoints struct {
// getTargetLabels returns labels for the given n.
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#node
func (n *Node) getTargetLabels(_ *groupWatcher) []*promutils.Labels {
func (n *Node) getTargetLabels(_ *groupWatcher) []*promutil.Labels {
addr := getNodeAddr(n.Status.Addresses)
if len(addr) == 0 {
// Skip node without address
return nil
}
addr = discoveryutils.JoinHostPort(addr, n.Status.DaemonEndpoints.KubeletEndpoint.Port)
m := promutils.GetLabels()
m := promutil.GetLabels()
m.Add("__address__", addr)
m.Add("instance", n.Metadata.Name)
m.Add("__meta_kubernetes_node_name", n.Metadata.Name)
@@ -106,7 +106,7 @@ func (n *Node) getTargetLabels(_ *groupWatcher) []*promutils.Labels {
addrTypesUsed[a.Type] = true
m.Add(discoveryutils.SanitizeLabelName("__meta_kubernetes_node_address_"+a.Type), a.Address)
}
return []*promutils.Labels{m}
return []*promutil.Labels{m}
}
func getNodeAddr(nas []NodeAddress) string {

View File

@@ -7,7 +7,7 @@ import (
"strconv"
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseNodeListFailure(t *testing.T) {
@@ -241,8 +241,8 @@ func TestParseNodeListSuccess(t *testing.T) {
t.Fatalf("unexpected resource version; got %s; want %s", meta.ResourceVersion, expectedResourceVersion)
}
sortedLabelss := getSortedLabelss(objectsByKey)
expectedLabelss := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabelss := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"instance": "m01",
"__address__": "172.17.0.2:10250",
"__meta_kubernetes_node_name": "m01",
@@ -287,9 +287,9 @@ func TestParseNodeListSuccess(t *testing.T) {
}
}
func getSortedLabelss(objectsByKey map[string]object) []*promutils.Labels {
func getSortedLabelss(objectsByKey map[string]object) []*promutil.Labels {
gw := newTestGroupWatcher()
var result []*promutils.Labels
var result []*promutil.Labels
for _, o := range objectsByKey {
labelss := o.getTargetLabels(gw)
for _, labels := range labelss {
@@ -308,7 +308,7 @@ func newTestGroupWatcher() *groupWatcher {
objectsByKey: map[string]object{
"/test-node": &Node{
Metadata: ObjectMeta{
Labels: promutils.NewLabelsFromMap(map[string]string{"node-label": "xyz"}),
Labels: promutil.NewLabelsFromMap(map[string]string{"node-label": "xyz"}),
},
},
},
@@ -318,19 +318,19 @@ func newTestGroupWatcher() *groupWatcher {
return &gw
}
func areEqualLabelss(a, b []*promutils.Labels) bool {
func areEqualLabelss(a, b []*promutil.Labels) bool {
sortLabelss(a)
sortLabelss(b)
return reflect.DeepEqual(a, b)
}
func sortLabelss(a []*promutils.Labels) {
func sortLabelss(a []*promutil.Labels) {
sort.Slice(a, func(i, j int) bool {
return marshalLabels(a[i]) < marshalLabels(a[j])
})
}
func marshalLabels(a *promutils.Labels) string {
func marshalLabels(a *promutil.Labels) string {
var b []byte
for _, label := range a.Labels {
b = strconv.AppendQuote(b, label.Name)

View File

@@ -8,7 +8,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func (p *Pod) key() string {
@@ -155,7 +155,7 @@ func (p *Pod) getContainerStatus(containerName string, isInit bool) *ContainerSt
// getTargetLabels returns labels for each port of the given p.
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#pod
func (p *Pod) getTargetLabels(gw *groupWatcher) []*promutils.Labels {
func (p *Pod) getTargetLabels(gw *groupWatcher) []*promutil.Labels {
if len(p.Status.PodIP) == 0 {
// Skip pod without IP, since such pods cannot be scraped.
return nil
@@ -165,7 +165,7 @@ func (p *Pod) getTargetLabels(gw *groupWatcher) []*promutils.Labels {
return nil
}
var ms []*promutils.Labels
var ms []*promutil.Labels
ms = appendPodLabels(ms, gw, p, p.Spec.Containers, false)
ms = appendPodLabels(ms, gw, p, p.Spec.InitContainers, true)
return ms
@@ -176,7 +176,7 @@ func isPodPhaseFinished(phase string) bool {
return phase == "Succeeded" || phase == "Failed"
}
func appendPodLabels(ms []*promutils.Labels, gw *groupWatcher, p *Pod, cs []Container, isInit bool) []*promutils.Labels {
func appendPodLabels(ms []*promutil.Labels, gw *groupWatcher, p *Pod, cs []Container, isInit bool) []*promutil.Labels {
for _, c := range cs {
if isContainerTerminated(p, c.Name, isInit) {
// Skip terminated containers
@@ -192,14 +192,14 @@ func appendPodLabels(ms []*promutils.Labels, gw *groupWatcher, p *Pod, cs []Cont
return ms
}
func appendPodLabelsInternal(ms []*promutils.Labels, gw *groupWatcher, p *Pod, c *Container, cp *ContainerPort, isInit bool) []*promutils.Labels {
func appendPodLabelsInternal(ms []*promutil.Labels, gw *groupWatcher, p *Pod, c *Container, cp *ContainerPort, isInit bool) []*promutil.Labels {
addr := p.Status.PodIP
if cp != nil {
addr = discoveryutils.JoinHostPort(addr, cp.ContainerPort)
} else if discoveryutils.IsIPv6Host(addr) {
addr = discoveryutils.EscapeIPv6Host(addr)
}
m := promutils.GetLabels()
m := promutil.GetLabels()
m.Add("__address__", addr)
containerID := getContainerID(p, c.Name, isInit)
@@ -212,7 +212,7 @@ func appendPodLabelsInternal(ms []*promutils.Labels, gw *groupWatcher, p *Pod, c
return append(ms, m)
}
func (p *Pod) appendContainerLabels(m *promutils.Labels, c *Container, cp *ContainerPort, isInit bool) {
func (p *Pod) appendContainerLabels(m *promutil.Labels, c *Container, cp *ContainerPort, isInit bool) {
m.Add("__meta_kubernetes_pod_container_image", c.Image)
m.Add("__meta_kubernetes_pod_container_name", c.Name)
isInitStr := "false"
@@ -227,14 +227,14 @@ func (p *Pod) appendContainerLabels(m *promutils.Labels, c *Container, cp *Conta
}
}
func (p *Pod) appendEndpointLabels(m *promutils.Labels, eps *Endpoints) {
func (p *Pod) appendEndpointLabels(m *promutil.Labels, eps *Endpoints) {
m.Add("__meta_kubernetes_endpoints_name", eps.Metadata.Name)
m.Add("__meta_kubernetes_endpoint_address_target_kind", "Pod")
m.Add("__meta_kubernetes_endpoint_address_target_name", p.Metadata.Name)
eps.Metadata.registerLabelsAndAnnotations("__meta_kubernetes_endpoints", m)
}
func (p *Pod) appendEndpointSliceLabels(m *promutils.Labels, eps *EndpointSlice) {
func (p *Pod) appendEndpointSliceLabels(m *promutil.Labels, eps *EndpointSlice) {
m.Add("__meta_kubernetes_endpointslice_name", eps.Metadata.Name)
m.Add("__meta_kubernetes_endpointslice_address_target_kind", "Pod")
m.Add("__meta_kubernetes_endpointslice_address_target_name", p.Metadata.Name)
@@ -242,7 +242,7 @@ func (p *Pod) appendEndpointSliceLabels(m *promutils.Labels, eps *EndpointSlice)
eps.Metadata.registerLabelsAndAnnotations("__meta_kubernetes_endpointslice", m)
}
func (p *Pod) appendCommonLabels(m *promutils.Labels, gw *groupWatcher) {
func (p *Pod) appendCommonLabels(m *promutil.Labels, gw *groupWatcher) {
if gw.attachNodeMetadata {
m.Add("__meta_kubernetes_node_name", p.Spec.NodeName)
o := gw.getObjectByRoleLocked("node", p.Metadata.Namespace, p.Spec.NodeName)

View File

@@ -4,7 +4,7 @@ import (
"bytes"
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParsePodListFailure(t *testing.T) {
@@ -691,7 +691,7 @@ const testPodsListIPv6AddressNoPorts = `
`
func TestParsePodListSuccess(t *testing.T) {
f := func(response string, expectedLabels []*promutils.Labels) {
f := func(response string, expectedLabels []*promutil.Labels) {
t.Helper()
r := bytes.NewBufferString(response)
objectsByKey, meta, err := parsePodList(r)
@@ -708,8 +708,8 @@ func TestParsePodListSuccess(t *testing.T) {
}
}
f(testPodsList, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
f(testPodsList, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "172.17.0.2:1234",
"__meta_kubernetes_namespace": "kube-system",
@@ -751,8 +751,8 @@ func TestParsePodListSuccess(t *testing.T) {
}),
})
f(testPodsListIPv6Address, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
f(testPodsListIPv6Address, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "[fd01:10:100:0:e38f:6f4b:9c53:9e4e]:1234",
"__meta_kubernetes_namespace": "kube-system",
@@ -793,8 +793,8 @@ func TestParsePodListSuccess(t *testing.T) {
"__meta_kubernetes_pod_annotationpresent_kubernetes_io_config_source": "true",
}),
})
f(testPodsListIPv6AddressNoPorts, []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
f(testPodsListIPv6AddressNoPorts, []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "[fd01:10:100:0:e38f:6f4b:9c53:9e4e]",
"__meta_kubernetes_namespace": "kube-system",

View File

@@ -7,7 +7,7 @@ import (
"strconv"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func (s *Service) key() string {
@@ -73,12 +73,12 @@ type ServicePort struct {
// getTargetLabels returns labels for each port of the given s.
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#service
func (s *Service) getTargetLabels(_ *groupWatcher) []*promutils.Labels {
func (s *Service) getTargetLabels(_ *groupWatcher) []*promutil.Labels {
host := fmt.Sprintf("%s.%s.svc", s.Metadata.Name, s.Metadata.Namespace)
var ms []*promutils.Labels
var ms []*promutil.Labels
for _, sp := range s.Spec.Ports {
addr := discoveryutils.JoinHostPort(host, sp.Port)
m := promutils.GetLabels()
m := promutil.GetLabels()
m.Add("__address__", addr)
m.Add("__meta_kubernetes_service_port_name", sp.Name)
m.Add("__meta_kubernetes_service_port_number", strconv.Itoa(sp.Port))
@@ -89,7 +89,7 @@ func (s *Service) getTargetLabels(_ *groupWatcher) []*promutils.Labels {
return ms
}
func (s *Service) appendCommonLabels(m *promutils.Labels) {
func (s *Service) appendCommonLabels(m *promutil.Labels) {
m.Add("__meta_kubernetes_namespace", s.Metadata.Namespace)
m.Add("__meta_kubernetes_service_name", s.Metadata.Name)
m.Add("__meta_kubernetes_service_type", s.Spec.Type)

View File

@@ -4,7 +4,7 @@ import (
"bytes"
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseServiceListFailure(t *testing.T) {
@@ -99,8 +99,8 @@ func TestParseServiceListSuccess(t *testing.T) {
t.Fatalf("unexpected resource version; got %s; want %s", meta.ResourceVersion, expectedResourceVersion)
}
sortedLabelss := getSortedLabelss(objectsByKey)
expectedLabelss := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabelss := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "kube-dns.kube-system.svc:53",
"__meta_kubernetes_namespace": "kube-system",
"__meta_kubernetes_service_name": "kube-dns",
@@ -124,7 +124,7 @@ func TestParseServiceListSuccess(t *testing.T) {
"__meta_kubernetes_service_annotationpresent_prometheus_io_port": "true",
"__meta_kubernetes_service_annotationpresent_prometheus_io_scrape": "true",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "kube-dns.kube-system.svc:53",
"__meta_kubernetes_namespace": "kube-system",
"__meta_kubernetes_service_name": "kube-dns",
@@ -148,7 +148,7 @@ func TestParseServiceListSuccess(t *testing.T) {
"__meta_kubernetes_service_annotationpresent_prometheus_io_port": "true",
"__meta_kubernetes_service_annotationpresent_prometheus_io_scrape": "true",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "kube-dns.kube-system.svc:9153",
"__meta_kubernetes_namespace": "kube-system",
"__meta_kubernetes_service_name": "kube-dns",

View File

@@ -17,7 +17,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/metrics"
)
@@ -29,7 +29,7 @@ type apiConfig struct {
apiPath string
// labels contains the latest discovered labels.
labels atomic.Pointer[[]*promutils.Labels]
labels atomic.Pointer[[]*promutil.Labels]
cancel context.CancelFunc
wg sync.WaitGroup
@@ -199,7 +199,7 @@ func (cfg *apiConfig) updateTargetsLabels(ctx context.Context) error {
return nil
}
func parseTargetsLabels(data []byte) ([]*promutils.Labels, string, string, error) {
func parseTargetsLabels(data []byte) ([]*promutil.Labels, string, string, error) {
var dResp discoveryResponse
if err := json.Unmarshal(data, &dResp); err != nil {
return nil, "", "", err
@@ -207,11 +207,11 @@ func parseTargetsLabels(data []byte) ([]*promutils.Labels, string, string, error
return dResp.getTargetsLabels(), dResp.VersionInfo, dResp.Nonce, nil
}
func (dr *discoveryResponse) getTargetsLabels() []*promutils.Labels {
var ms []*promutils.Labels
func (dr *discoveryResponse) getTargetsLabels() []*promutil.Labels {
var ms []*promutil.Labels
for _, r := range dr.Resources {
for _, t := range r.Targets {
m := promutils.NewLabels(8 + len(r.Labels) + len(t.Labels))
m := promutil.NewLabels(8 + len(r.Labels) + len(t.Labels))
m.Add("instance", t.Name)
m.Add("__address__", t.Address)
@@ -232,7 +232,7 @@ func (dr *discoveryResponse) getTargetsLabels() []*promutils.Labels {
return ms
}
func addLabels(dst *promutils.Labels, src map[string]string) {
func addLabels(dst *promutil.Labels, src map[string]string) {
bb := bbPool.Get()
b := bb.B
for k, v := range src {

View File

@@ -4,7 +4,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestGetAPIServerPathSuccess(t *testing.T) {
@@ -97,8 +97,8 @@ func TestParseTargetsLabels(t *testing.T) {
t.Fatalf("unexpected error: %s", err)
}
expectedLabelss := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabelss := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "127.0.0.1:5670",
"__meta_kuma_dataplane": "redis",
"__meta_kuma_label_kuma_io_protocol": "tcp",
@@ -109,7 +109,7 @@ func TestParseTargetsLabels(t *testing.T) {
"__scheme__": "http",
"instance": "redis",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "127.0.0.1:5671",
"__meta_kuma_dataplane": "app",
"__meta_kuma_label_kuma_io_protocol": "http",

View File

@@ -6,7 +6,7 @@ import (
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -34,7 +34,7 @@ type SDConfig struct {
}
// GetLabels returns kuma service discovery labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config for kuma_sd: %w", err)

View File

@@ -9,7 +9,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -30,7 +30,7 @@ type SDConfig struct {
var configMap = discoveryutils.NewConfigMap()
// GetLabels returns Marathon labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
ac, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)
@@ -49,16 +49,16 @@ func (sdc *SDConfig) MustStop() {
}
// getAppsLabels takes an array of Marathon apps and converts them into labels.
func getAppsLabels(apps *AppList) []*promutils.Labels {
ms := make([]*promutils.Labels, 0, len(apps.Apps))
func getAppsLabels(apps *AppList) []*promutil.Labels {
ms := make([]*promutil.Labels, 0, len(apps.Apps))
for _, a := range apps.Apps {
ms = append(ms, getAppLabels(&a)...)
}
return ms
}
func getAppLabels(app *app) []*promutils.Labels {
m := promutils.NewLabels(5)
func getAppLabels(app *app) []*promutil.Labels {
m := promutil.NewLabels(5)
m.Add("__meta_marathon_app", app.ID)
m.Add("__meta_marathon_image", app.Container.Docker.Image)
@@ -102,7 +102,7 @@ func getAppLabels(app *app) []*promutils.Labels {
m.Add("__meta_marathon_app_label_"+discoveryutils.SanitizeLabelName(ln), lv)
}
labelss := make([]*promutils.Labels, 0, len(app.Tasks))
labelss := make([]*promutil.Labels, 0, len(app.Tasks))
// Gather info about the app's 'tasks'. Each instance (container) is considered a task
// and can be reachable at one or more host:port endpoints.

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestGetAppLabels(t *testing.T) {
@@ -158,8 +158,8 @@ func TestGetAppLabels(t *testing.T) {
t.Fatalf("unmarshal jsonResponse failed: %s", err)
}
result := getAppsLabels(appList)
expect := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expect := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "pre2:20651",
"__meta_marathon_app": "/app-test",
"__meta_marathon_app_label_HAPROXY_0_HTTP_BACKEND_PROXYPASS_GLUE": " reqirep \"^([^ :]*)\\ {proxypath}/?(.*)\" \"\\1\\ /\\2\"\n",
@@ -172,7 +172,7 @@ func TestGetAppLabels(t *testing.T) {
"__meta_marathon_port_index": "0",
"__meta_marathon_task": "app-test.b44e0f85-a586-11ef-b308-02429c08177d",
"__meta_marathon_port_mapping_label_portMappingsLabel1": "portMappingsValue1",
}), promutils.NewLabelsFromMap(map[string]string{
}), promutil.NewLabelsFromMap(map[string]string{
"__address__": "pre3:20681",
"__meta_marathon_app": "/app-test",
"__meta_marathon_app_label_HAPROXY_0_HTTP_BACKEND_PROXYPASS_GLUE": " reqirep \"^([^ :]*)\\ {proxypath}/?(.*)\" \"\\1\\ /\\2\"\n",
@@ -185,7 +185,7 @@ func TestGetAppLabels(t *testing.T) {
"__meta_marathon_port_index": "0",
"__meta_marathon_task": "app-test.7cbfcce5-a586-11ef-b308-02429c08177d",
"__meta_marathon_port_mapping_label_portMappingsLabel1": "portMappingsValue1",
}), promutils.NewLabelsFromMap(map[string]string{
}), promutil.NewLabelsFromMap(map[string]string{
"__address__": "pre1:20337",
"__meta_marathon_app": "/app-test",
"__meta_marathon_app_label_HAPROXY_0_HTTP_BACKEND_PROXYPASS_GLUE": " reqirep \"^([^ :]*)\\ {proxypath}/?(.*)\" \"\\1\\ /\\2\"\n",
@@ -198,7 +198,7 @@ func TestGetAppLabels(t *testing.T) {
"__meta_marathon_port_index": "0",
"__meta_marathon_task": "app-test.b0a7c3d4-a586-11ef-b308-02429c08177d",
"__meta_marathon_port_mapping_label_portMappingsLabel1": "portMappingsValue1",
}), promutils.NewLabelsFromMap(map[string]string{
}), promutil.NewLabelsFromMap(map[string]string{
"__address__": "pre2:20668",
"__meta_marathon_app": "/app-test",
"__meta_marathon_app_label_HAPROXY_0_HTTP_BACKEND_PROXYPASS_GLUE": " reqirep \"^([^ :]*)\\ {proxypath}/?(.*)\" \"\\1\\ /\\2\"\n",
@@ -211,7 +211,7 @@ func TestGetAppLabels(t *testing.T) {
"__meta_marathon_port_index": "0",
"__meta_marathon_task": "app-test.7c26c12c-a586-11ef-b308-02429c08177d",
"__meta_marathon_port_mapping_label_portMappingsLabel1": "portMappingsValue1",
}), promutils.NewLabelsFromMap(map[string]string{
}), promutil.NewLabelsFromMap(map[string]string{
"__address__": "pre2:20651",
"__meta_marathon_app": "/app-test-for-port-definition",
"__meta_marathon_app_label_HAPROXY_0_HTTP_BACKEND_PROXYPASS_GLUE": " reqirep \"^([^ :]*)\\ {proxypath}/?(.*)\" \"\\1\\ /\\2\"\n",

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -26,7 +26,7 @@ type SDConfig struct {
}
// GetLabels returns Nomad labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)

View File

@@ -6,13 +6,13 @@ import (
"strconv"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// getServiceLabels returns labels for Nomad services with given cfg.
func getServiceLabels(cfg *apiConfig) []*promutils.Labels {
func getServiceLabels(cfg *apiConfig) []*promutil.Labels {
svcs := cfg.nomadWatcher.getServiceSnapshot()
var ms []*promutils.Labels
var ms []*promutil.Labels
for _, s := range svcs {
for i := range s {
ms = s[i].appendTargetLabels(ms, cfg.tagSeparator)
@@ -56,9 +56,9 @@ func parseServices(data []byte) ([]Service, error) {
return sns, nil
}
func (svc *Service) appendTargetLabels(ms []*promutils.Labels, tagSeparator string) []*promutils.Labels {
func (svc *Service) appendTargetLabels(ms []*promutil.Labels, tagSeparator string) []*promutil.Labels {
addr := discoveryutils.JoinHostPort(svc.Address, svc.Port)
m := promutils.NewLabels(16)
m := promutil.NewLabels(16)
m.Add("__address__", addr)
m.Add("__meta_nomad_address", svc.Address)
m.Add("__meta_nomad_dc", svc.Datacenter)

View File

@@ -4,7 +4,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseServicesFailure(t *testing.T) {
@@ -57,8 +57,8 @@ func TestParseServiceNodesSuccess(t *testing.T) {
// Check sn.appendTargetLabels()
tagSeparator := ","
labelss := sn.appendTargetLabels(nil, tagSeparator)
expectedLabelss := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
expectedLabelss := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "192.168.29.76:23761",
"__meta_nomad_dc": "dc1",
"__meta_nomad_node_id": "9e02c85b-db59-45f1-ddee-40d0317bd33d",

View File

@@ -7,7 +7,7 @@ import (
"strconv"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// See https://docs.openstack.org/api-ref/compute/#list-hypervisors-details
@@ -64,11 +64,11 @@ func (cfg *apiConfig) getHypervisors() ([]hypervisor, error) {
}
}
func addHypervisorLabels(hvs []hypervisor, port int) []*promutils.Labels {
var ms []*promutils.Labels
func addHypervisorLabels(hvs []hypervisor, port int) []*promutil.Labels {
var ms []*promutil.Labels
for _, hv := range hvs {
addr := discoveryutils.JoinHostPort(hv.HostIP, port)
m := promutils.NewLabels(8)
m := promutil.NewLabels(8)
m.Add("__address__", addr)
m.Add("__meta_openstack_hypervisor_type", hv.Type)
m.Add("__meta_openstack_hypervisor_status", hv.Status)
@@ -81,7 +81,7 @@ func addHypervisorLabels(hvs []hypervisor, port int) []*promutils.Labels {
return ms
}
func getHypervisorLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
func getHypervisorLabels(cfg *apiConfig) ([]*promutil.Labels, error) {
hvs, err := cfg.getHypervisors()
if err != nil {
return nil, fmt.Errorf("cannot get hypervisors: %w", err)

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestParseHypervisorDetail_Failure(t *testing.T) {
@@ -95,7 +95,7 @@ func TestParseHypervisorDetail_Success(t *testing.T) {
}
func TestAddHypervisorLabels(t *testing.T) {
f := func(hvs []hypervisor, labelssExpected []*promutils.Labels) {
f := func(hvs []hypervisor, labelssExpected []*promutil.Labels) {
t.Helper()
labelss := addHypervisorLabels(hvs, 9100)
@@ -112,8 +112,8 @@ func TestAddHypervisorLabels(t *testing.T) {
HostIP: "1.2.2.2",
},
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "1.2.2.2:9100",
"__meta_openstack_hypervisor_host_ip": "1.2.2.2",
"__meta_openstack_hypervisor_hostname": "fakehost",

View File

@@ -8,7 +8,7 @@ import (
"strconv"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// See https://docs.openstack.org/api-ref/compute/#list-servers
@@ -52,10 +52,10 @@ func parseServersDetail(data []byte) (*serversDetail, error) {
return &srvd, nil
}
func addInstanceLabels(servers []server, port int) []*promutils.Labels {
var ms []*promutils.Labels
func addInstanceLabels(servers []server, port int) []*promutil.Labels {
var ms []*promutil.Labels
for _, server := range servers {
commonLabels := promutils.NewLabels(16)
commonLabels := promutil.NewLabels(16)
commonLabels.Add("__meta_openstack_instance_id", server.ID)
commonLabels.Add("__meta_openstack_instance_status", server.Status)
commonLabels.Add("__meta_openstack_instance_name", server.Name)
@@ -93,7 +93,7 @@ func addInstanceLabels(servers []server, port int) []*promutils.Labels {
continue
}
// copy labels
m := promutils.NewLabels(20)
m := promutil.NewLabels(20)
m.AddFrom(commonLabels)
m.Add("__meta_openstack_address_pool", pool)
m.Add("__meta_openstack_private_ip", ip.Address)
@@ -137,7 +137,7 @@ func (cfg *apiConfig) getServers() ([]server, error) {
}
}
func getInstancesLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
func getInstancesLabels(cfg *apiConfig) ([]*promutil.Labels, error) {
srv, err := cfg.getServers()
if err != nil {
return nil, err

View File

@@ -5,11 +5,11 @@ import (
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func TestAddInstanceLabels(t *testing.T) {
f := func(servers []server, labelssExpected []*promutils.Labels) {
f := func(servers []server, labelssExpected []*promutil.Labels) {
t.Helper()
labelss := addInstanceLabels(servers, 9100)
@@ -42,8 +42,8 @@ func TestAddInstanceLabels(t *testing.T) {
},
},
}
labelssExpected := []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected := []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "192.168.0.1:9100",
"__meta_openstack_address_pool": "test",
"__meta_openstack_instance_flavor": "5",
@@ -92,8 +92,8 @@ func TestAddInstanceLabels(t *testing.T) {
},
},
}
labelssExpected = []*promutils.Labels{
promutils.NewLabelsFromMap(map[string]string{
labelssExpected = []*promutil.Labels{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "10.10.0.1:9100",
"__meta_openstack_address_pool": "internal",
"__meta_openstack_instance_flavor": "5",
@@ -104,7 +104,7 @@ func TestAddInstanceLabels(t *testing.T) {
"__meta_openstack_project_id": "some-tenant-id",
"__meta_openstack_user_id": "some-user-id",
}),
promutils.NewLabelsFromMap(map[string]string{
promutil.NewLabelsFromMap(map[string]string{
"__address__": "192.168.0.1:9100",
"__meta_openstack_address_pool": "test",
"__meta_openstack_instance_flavor": "5",

View File

@@ -6,7 +6,7 @@ import (
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// SDCheckInterval defines interval for targets refresh.
@@ -40,7 +40,7 @@ type SDConfig struct {
}
// GetLabels returns OpenStack labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)

View File

@@ -10,7 +10,7 @@ import (
"strconv"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
// dedicatedServer struct from API.
@@ -32,7 +32,7 @@ type dedicatedServer struct {
}
// getDedicatedServerLabels get labels for dedicated servers.
func getDedicatedServerLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
func getDedicatedServerLabels(cfg *apiConfig) ([]*promutil.Labels, error) {
dedicatedServerList, err := getDedicatedServerList(cfg)
if err != nil {
return nil, err
@@ -49,7 +49,7 @@ func getDedicatedServerLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
dedicatedServerDetailList = append(dedicatedServerDetailList, *dedicatedServer)
}
ms := make([]*promutils.Labels, 0, len(dedicatedServerDetailList))
ms := make([]*promutil.Labels, 0, len(dedicatedServerDetailList))
for _, server := range dedicatedServerDetailList {
// convert IPs into string and select default IP.
var ipv4, ipv6 string
@@ -66,7 +66,7 @@ func getDedicatedServerLabels(cfg *apiConfig) ([]*promutils.Labels, error) {
defaultIP = ipv6
}
m := promutils.NewLabels(15)
m := promutil.NewLabels(15)
m.Add("__address__", defaultIP)
m.Add("instance", server.Name)
m.Add("__meta_ovhcloud_dedicated_server_state", server.State)

View File

@@ -9,7 +9,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
)
func Test_getDedicatedServerLabels(t *testing.T) {
@@ -36,7 +36,7 @@ func Test_getDedicatedServerLabels(t *testing.T) {
timeDelta: td,
}
expectLabels := &promutils.Labels{}
expectLabels := &promutil.Labels{}
expectLabels.Add("__address__", "50.75.126.113")
expectLabels.Add("instance", "ns0000000.ip-00-00-000.eu")
expectLabels.Add("__meta_ovhcloud_dedicated_server_state", "ok")
@@ -52,7 +52,7 @@ func Test_getDedicatedServerLabels(t *testing.T) {
expectLabels.Add("__meta_ovhcloud_dedicated_server_name", "ns0000000.ip-00-00-000.eu")
expectLabels.Add("__meta_ovhcloud_dedicated_server_ipv4", "50.75.126.113")
expectLabels.Add("__meta_ovhcloud_dedicated_server_ipv6", "")
expect := []*promutils.Labels{
expect := []*promutil.Labels{
expectLabels,
}

View File

@@ -6,7 +6,7 @@ import (
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
)
@@ -29,7 +29,7 @@ type SDConfig struct {
}
// GetLabels returns labels for OVH Cloud according to service discover config.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)

Some files were not shown because too many files have changed in this diff Show More