Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync upstream at b9dd95f499aa2912d9cfbcfddfbdd6bc0a5207a5 #786

Merged
merged 65 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
72d84f5
Merge pull request #14515 from prometheus/revert-13777-remoteread2 (#…
bboreham Jul 31, 2024
f7d316a
Cut release 2.53.2
bboreham Aug 9, 2024
6e971a7
Merge pull request #14645 from prometheus/prep-2.53.2
bboreham Aug 9, 2024
d697719
[BUGFIX] Scraping: allow multiple samples on same series (#14685)
bboreham Aug 19, 2024
d8d52f3
Merge pull request #14740 from prometheus/backport-14685
bboreham Aug 27, 2024
16217a6
Make release 2.53.3 LTS
bboreham Nov 4, 2024
1491d29
Merge pull request #15330 from prometheus/make-release-2.53.3
bboreham Nov 5, 2024
50e83e8
Export 'go_sync_mutex_wait_total_seconds_total' metric
colega Nov 5, 2024
f9bc50b
storage: Implement limit in mergeGenericQuerier
harry671003 Nov 7, 2024
de35a40
[REFACTOR] Small improvement to top-level naming
bboreham Nov 11, 2024
5450e6d
[BUGFIX] TSDB: Apply fixes from loadWAL to loadWBL
bboreham Nov 11, 2024
ebc4575
Fix release date
roidelapluie Nov 12, 2024
70750ac
Merge pull request #15386 from roidelapluie/rel255
bboreham Nov 12, 2024
48abdcd
bugfix: allow quoted exemplar keys in openmetrics text format
tcolgate Nov 1, 2024
0ef0b75
[TESTS] Remote-Write: Fix BenchmarkStartup
bboreham Nov 15, 2024
16a4354
chore(deduper): add compile check that slog.Handler int is satisfied
tjhop Nov 15, 2024
210ef03
Merge branch 'release-2.55' into merge-release-into-main
bboreham Nov 18, 2024
379304f
Merge branch 'release-2.53' into merge-release-into-main
bboreham Nov 18, 2024
4f48e76
chore: fix some function names in comment
huochexizhan Nov 19, 2024
45db236
promql: fix incorrect "native histogram ignored in aggregation" annot…
charleskorn Nov 19, 2024
62e6e55
promql: fix issues with comparison binary operations with `bool` modi…
charleskorn Nov 19, 2024
06d54fc
[PERF] TSDB: Optimize inverse matching (#14144)
aknuds1 Nov 19, 2024
384c595
Merge pull request #14489 from harry671003/implement_metadata_limit
beorn7 Nov 19, 2024
b02805e
Merge pull request #15415 from prometheus/merge-release-into-main
bboreham Nov 19, 2024
0482228
fix count_values for histograms
NeerajGartia21 Nov 19, 2024
5cd9855
tests(promql/testdata): add regression test for and-on (#15425)
krajorama Nov 20, 2024
9c02c26
OTLP receiver: Convert also metric metadata (#15416)
aknuds1 Nov 20, 2024
4ef1170
Merge pull request #15422 from NeerajGartia21/promql-corrections
beorn7 Nov 20, 2024
a6fb16f
PromQL: Convert more native histogram tests to promql-test framework …
NeerajGartia21 Nov 20, 2024
3c22b35
Merge pull request #15339 from colega/export-go-sync-mutex-wait-total…
bboreham Nov 20, 2024
e8003cb
Merge pull request #15417 from huochexizhan/main
beorn7 Nov 20, 2024
ca600cf
Merge pull request #15407 from tjhop/chore/slog-handler-compile-check
beorn7 Nov 20, 2024
d7c8177
docs: update README with v3 tagging update (#15361)
fionaliao Nov 20, 2024
89bbb88
Upgrade to golangci-lint v1.62.0 (#15424)
aknuds1 Nov 20, 2024
cc390aa
MemPostings: allocate ListPostings once in PFLM (#15427)
colega Nov 20, 2024
125a908
promqltest: Complete the tests for info annotations (#15429)
beorn7 Nov 21, 2024
c2e28f2
rules.NewGroup: Fix when no logger is passed (#15356)
aknuds1 Nov 21, 2024
abfc314
apply DRY on clamp (#15441)
NeerajGartia21 Nov 24, 2024
63d87a6
docs: fix typo (#15436)
simonpasquier Nov 24, 2024
e664c16
api: fix typo in list rules API response (#15400)
rapphil Nov 24, 2024
40c3ba9
fix promtool analyze block shows metric name with 0 cardinality (#15438)
yeya24 Nov 24, 2024
fc5b7dc
chore(deps): bump the k8s-io group with 3 updates (#15283)
dependabot[bot] Nov 24, 2024
e243ed6
chore(deps): bump github.com/fsnotify/fsnotify from 1.7.0 to 1.8.0 (#…
dependabot[bot] Nov 24, 2024
dd1d707
Merge pull request #15371 from bboreham/main-naming
bboreham Nov 24, 2024
872e2db
Implement json encoder/decoder for regexp (#15383)
yeya24 Nov 24, 2024
41f051e
Small improvement in handling cases without count
krajorama Nov 25, 2024
a48d059
nhcb: optimize, do not recalculate suffixes multiple times
krajorama Nov 25, 2024
7996a13
Merge pull request #15403 from bboreham/fix-rw-benchmark-startup
bboreham Nov 25, 2024
dd0252a
Merge pull request #15380 from bboreham/improve-loadwbl
bboreham Nov 25, 2024
a778a58
chore(deps-dev): bump rollup from 4.21.2 to 4.27.4 in /web/ui
dependabot[bot] Nov 26, 2024
1939123
chore(deps): bump braces from 3.0.2 to 3.0.3 in /web/ui/react-app (#1…
dependabot[bot] Nov 26, 2024
1bd16db
chore(deps): bump body-parser and express in /web/ui/react-app (#15460)
dependabot[bot] Nov 26, 2024
8e7e7a0
chore(deps): bump micromatch from 4.0.5 to 4.0.8 in /web/ui/react-app…
dependabot[bot] Nov 26, 2024
c08edd3
chore(deps-dev): bump rollup from 2.79.1 to 2.79.2 in /web/ui/react-a…
dependabot[bot] Nov 26, 2024
11d9da1
Merge pull request #15260 from tcolgate/quoteexemplarkeys
bwplotka Nov 26, 2024
c3cc25f
document scraping change introduced in 2.52.0 (#15148)
zuozp8 Nov 26, 2024
d535d50
[DOCS] Improve description of WAL record format (#14936)
dc-orz Nov 26, 2024
eb9ce70
Set hasCount after setting count to be consistent
krajorama Nov 26, 2024
975d5d7
Merge pull request #15459 from prometheus/dependabot/npm_and_yarn/web…
juliusv Nov 26, 2024
e01c5ce
notifier: fix increment of metric prometheus_notifications_errors_total
beorn7 Nov 20, 2024
9aa6e04
MemPostings: allocate ListPostings once in PFALV (#15465)
colega Nov 26, 2024
619e7aa
Merge pull request #15453 from prometheus/nhcb-scrape-optimize2
bwplotka Nov 26, 2024
6f1f0aa
Revert "chore(deps): bump github.com/fsnotify/fsnotify from 1.7.0 to …
aknuds1 Nov 26, 2024
b9dd95f
Merge pull request #15428 from prometheus/beorn7/metrics
beorn7 Nov 26, 2024
c0981c6
Merge branch 'merge-source' into krajo/merge-upstream
krajorama Dec 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
with:
args: --verbose
# Make sure to sync this with Makefile.common and scripts/golangci-lint.yml.
version: v1.61.0
version: v1.62.0
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## unreleased

* [CHANGE] Notifier: Increment the prometheus_notifications_errors_total metric by the number of affected alerts rather than by one per batch of affected alerts. #15428
* [ENHANCEMENT] OTLP receiver: Convert also metric metadata. #15416

## 3.0.0 / 2024-11-14

This release includes new features such as a brand new UI and UTF-8 support enabled by default. As this marks the first new major version in seven years, several breaking changes are introduced. The breaking changes are mainly around the removal of deprecated feature flags and CLI arguments, and the full list can be found below. For users that want to upgrade we recommend to read through our [migration guide](https://prometheus.io/docs/prometheus/3.0/migration/).
Expand Down Expand Up @@ -72,7 +75,18 @@ This release includes new features such as a brand new UI and UTF-8 support enab
* [BUGFIX] Autoreload: Reload invalid yaml files. #14947
* [BUGFIX] Scrape: Do not override target parameter labels with config params. #11029

## 2.55.1 / 2024-01-04
## 2.53.3 / 2024-11-04

* [BUGFIX] Scraping: allow multiple samples on same series, with explicit timestamps. #14685, #14740

## 2.53.2 / 2024-08-09

Fix a bug where Prometheus would crash with a segmentation fault if a remote-read
request accessed a block on disk at about the same time as TSDB created a new block.

[BUGFIX] Remote-Read: Resolve occasional segmentation fault on query. #14515,#14523

## 2.55.1 / 2024-11-04

* [BUGFIX] `round()` function did not remove `__name__` label. #15250

Expand Down Expand Up @@ -112,7 +126,7 @@ This release includes new features such as a brand new UI and UTF-8 support enab

## 2.54.1 / 2024-08-27

* [BUGFIX] Scraping: allow multiple samples on same series, with explicit timestamps. #14685
* [BUGFIX] Scraping: allow multiple samples on same series, with explicit timestamps (mixing samples of the same series with and without timestamps is still rejected). #14685
* [BUGFIX] Docker SD: fix crash in `match_first_network` mode when container is reconnected to a new network. #14654
* [BUGFIX] PromQL: fix experimental native histograms getting corrupted due to vector selector bug in range queries. #14538
* [BUGFIX] PromQL: fix experimental native histogram counter reset detection on stale samples. #14514
Expand Down Expand Up @@ -194,6 +208,7 @@ This release changes the default for GOGC, the Go runtime control for the trade-
## 2.52.0 / 2024-05-07

* [CHANGE] TSDB: Fix the predicate checking for blocks which are beyond the retention period to include the ones right at the retention boundary. #9633
* [CHANGE] Scrape: Multiple samples (even with different timestamps) are treated as duplicates during one scrape.
* [FEATURE] Kubernetes SD: Add a new metric `prometheus_sd_kubernetes_failures_total` to track failed requests to Kubernetes API. #13554
* [FEATURE] Kubernetes SD: Add node and zone metadata labels when using the endpointslice role. #13935
* [FEATURE] Azure SD/Remote Write: Allow usage of Azure authorization SDK. #13099
Expand Down
2 changes: 1 addition & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
SKIP_GOLANGCI_LINT :=
GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.61.0
GOLANGCI_LINT_VERSION ?= v1.62.0
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
# windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,19 @@ This is experimental.
### Prometheus code base

In order to comply with [go mod](https://go.dev/ref/mod#versions) rules,
Prometheus release number do not exactly match Go module releases. For the
Prometheus v2.y.z releases, we are publishing equivalent v0.y.z tags.
Prometheus release number do not exactly match Go module releases.

For the
Prometheus v3.y.z releases, we are publishing equivalent v0.3y.z tags. The y in v0.3y.z is always padded to two digits, with a leading zero if needed.

Therefore, a user that would want to use Prometheus v3.0.0 as a library could do:

```shell
go get github.com/prometheus/prometheus@v0.300.0
```

For the
Prometheus v2.y.z releases, we published the equivalent v0.y.z tags.

Therefore, a user that would want to use Prometheus v2.35.0 as a library could do:

Expand All @@ -177,7 +188,7 @@ For more information on building, running, and developing on the React-based UI,

## More information

* Godoc documentation is available via [pkg.go.dev](https://pkg.go.dev/github.com/prometheus/prometheus). Due to peculiarities of Go Modules, v2.x.y will be displayed as v0.x.y.
* Godoc documentation is available via [pkg.go.dev](https://pkg.go.dev/github.com/prometheus/prometheus). Due to peculiarities of Go Modules, v3.y.z will be displayed as v0.3y.z (the y in v0.3y.z is always padded to two digits, with a leading zero if needed), while v2.y.z will be displayed as v0.y.z.
* See the [Community page](https://prometheus.io/community) for how to reach the Prometheus developers and users on various communication channels.

## Contributing
Expand Down
12 changes: 8 additions & 4 deletions cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os"
"os/signal"
"path/filepath"
goregexp "regexp" //nolint:depguard // The Prometheus client library requires us to pass a regexp from this package.
"runtime"
"runtime/debug"
"strconv"
Expand Down Expand Up @@ -296,6 +297,7 @@ func main() {
collectors.WithGoCollectorRuntimeMetrics(
collectors.MetricsGC,
collectors.MetricsScheduler,
collectors.GoRuntimeMetricsRule{Matcher: goregexp.MustCompile(`^/sync/mutex/wait/total:seconds$`)},
),
),
)
Expand Down Expand Up @@ -1368,10 +1370,12 @@ func main() {
},
)
}
if err := g.Run(); err != nil {
logger.Error("Error running goroutines from run.Group", "err", err)
os.Exit(1)
}
func() { // This function exists so the top of the stack is named 'main.main.funcxxx' and not 'oklog'.
if err := g.Run(); err != nil {
logger.Error("Fatal error", "err", err)
os.Exit(1)
}
}()
logger.Info("See you next time!")
}

Expand Down
7 changes: 5 additions & 2 deletions cmd/promtool/tsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,10 @@ func analyzeBlock(ctx context.Context, path, blockID string, limit int, runExten
if err != nil {
return err
}
postings = index.Intersect(postings, index.NewListPostings(refs))
// Only intersect postings if matchers are specified.
if len(matchers) > 0 {
postings = index.Intersect(postings, index.NewListPostings(refs))
}
count := 0
for postings.Next() {
count++
Expand Down Expand Up @@ -733,7 +736,7 @@ func dumpSamples(ctx context.Context, dbDir, sandboxDirRoot string, mint, maxt i
for _, mset := range matcherSets {
sets = append(sets, q.Select(ctx, true, nil, mset...))
}
ss = storage.NewMergeSeriesSet(sets, storage.ChainedSeriesMerge)
ss = storage.NewMergeSeriesSet(sets, 0, storage.ChainedSeriesMerge)
} else {
ss = q.Select(ctx, false, nil, matcherSets[0]...)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ global:
[ keep_dropped_targets: <int> | default = 0 ]

# Specifies the validation scheme for metric and label names. Either blank or
# "utf8" for for full UTF-8 support, or "legacy" for letters, numbers, colons,
# "utf8" for full UTF-8 support, or "legacy" for letters, numbers, colons,
# and underscores.
[ metric_name_validation_scheme <string> | default "utf8" ]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func TestMarshalStoreSamplesRequest(t *testing.T) {
Value: 3.1415,
Tags: tagsFromMetric(metric),
}
expectedJSON := []byte(`{"metric":"test_.metric","timestamp":4711,"value":3.1415,"tags":{"many_chars":"abc_21ABC_.012-3_2145_C3_B667_7E89./","testlabel":"test_.value"}}`)
expectedJSON := `{"metric":"test_.metric","timestamp":4711,"value":3.1415,"tags":{"many_chars":"abc_21ABC_.012-3_2145_C3_B667_7E89./","testlabel":"test_.value"}}`

resultingJSON, err := json.Marshal(request)
require.NoError(t, err, "Marshal(request) resulted in err.")
require.Equal(t, expectedJSON, resultingJSON)
require.JSONEq(t, expectedJSON, string(resultingJSON))

var unmarshaledRequest StoreSamplesRequest
err = json.Unmarshal(expectedJSON, &unmarshaledRequest)
err = json.Unmarshal([]byte(expectedJSON), &unmarshaledRequest)
require.NoError(t, err, "Unmarshal(expectedJSON, &unmarshaledRequest) resulted in err.")
require.Equal(t, request, unmarshaledRequest)
}
4 changes: 2 additions & 2 deletions documentation/prometheus-mixin/alerts.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
severity: 'warning',
},
annotations: {
summary: 'Prometheus has encountered more than 1% errors sending alerts to a specific Alertmanager.',
description: '{{ printf "%%.1f" $value }}%% errors while sending alerts from Prometheus %(prometheusName)s to Alertmanager {{$labels.alertmanager}}.' % $._config,
summary: 'More than 1% of alerts sent by Prometheus to a specific Alertmanager were affected by errors.',
description: '{{ printf "%%.1f" $value }}%% of alerts sent by Prometheus %(prometheusName)s to Alertmanager {{$labels.alertmanager}} were affected by errors.' % $._config,
},
},
{
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ require (
google.golang.org/protobuf v1.35.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.31.1
k8s.io/apimachinery v0.31.1
k8s.io/client-go v0.31.1
k8s.io/api v0.31.2
k8s.io/apimachinery v0.31.2
k8s.io/client-go v0.31.2
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.130.1
)
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -741,12 +741,12 @@ gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.31.1 h1:Xe1hX/fPW3PXYYv8BlozYqw63ytA92snr96zMW9gWTU=
k8s.io/api v0.31.1/go.mod h1:sbN1g6eY6XVLeqNsZGLnI5FwVseTrZX7Fv3O26rhAaI=
k8s.io/apimachinery v0.31.1 h1:mhcUBbj7KUjaVhyXILglcVjuS4nYXiwC+KKFBgIVy7U=
k8s.io/apimachinery v0.31.1/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/client-go v0.31.1 h1:f0ugtWSbWpxHR7sjVpQwuvw9a3ZKLXX0u0itkFXufb0=
k8s.io/client-go v0.31.1/go.mod h1:sKI8871MJN2OyeqRlmA4W4KM9KBdBUpDLu/43eGemCg=
k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0=
k8s.io/api v0.31.2/go.mod h1:bWmGvrGPssSK1ljmLzd3pwCQ9MgoTsRCuK35u6SygUk=
k8s.io/apimachinery v0.31.2 h1:i4vUt2hPK56W6mlT7Ry+AO8eEsyxMD1U44NR22CLTYw=
k8s.io/apimachinery v0.31.2/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/client-go v0.31.2 h1:Y2F4dxU5d3AQj+ybwSMqQnpZH9F30//1ObxOKlTI9yc=
k8s.io/client-go v0.31.2/go.mod h1:NPa74jSVR/+eez2dFsEIHNa+3o09vtNaWwWwb1qSxSs=
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
Expand Down
8 changes: 4 additions & 4 deletions model/labels/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ func TestMarshaling(t *testing.T) {
expectedJSON := "{\"aaa\":\"111\",\"bbb\":\"2222\",\"ccc\":\"33333\"}"
b, err := json.Marshal(lbls)
require.NoError(t, err)
require.Equal(t, expectedJSON, string(b))
require.JSONEq(t, expectedJSON, string(b))

var gotJ Labels
err = json.Unmarshal(b, &gotJ)
Expand All @@ -964,7 +964,7 @@ func TestMarshaling(t *testing.T) {
expectedYAML := "aaa: \"111\"\nbbb: \"2222\"\nccc: \"33333\"\n"
b, err = yaml.Marshal(lbls)
require.NoError(t, err)
require.Equal(t, expectedYAML, string(b))
require.YAMLEq(t, expectedYAML, string(b))

var gotY Labels
err = yaml.Unmarshal(b, &gotY)
Expand All @@ -980,7 +980,7 @@ func TestMarshaling(t *testing.T) {
b, err = json.Marshal(f)
require.NoError(t, err)
expectedJSONFromStruct := "{\"a_labels\":" + expectedJSON + "}"
require.Equal(t, expectedJSONFromStruct, string(b))
require.JSONEq(t, expectedJSONFromStruct, string(b))

var gotFJ foo
err = json.Unmarshal(b, &gotFJ)
Expand All @@ -990,7 +990,7 @@ func TestMarshaling(t *testing.T) {
b, err = yaml.Marshal(f)
require.NoError(t, err)
expectedYAMLFromStruct := "a_labels:\n aaa: \"111\"\n bbb: \"2222\"\n ccc: \"33333\"\n"
require.Equal(t, expectedYAMLFromStruct, string(b))
require.YAMLEq(t, expectedYAMLFromStruct, string(b))

var gotFY foo
err = yaml.Unmarshal(b, &gotFY)
Expand Down
34 changes: 27 additions & 7 deletions model/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package relabel
import (
"crypto/md5"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"strconv"
Expand Down Expand Up @@ -84,20 +85,20 @@ func (a *Action) UnmarshalYAML(unmarshal func(interface{}) error) error {
type Config struct {
// A list of labels from which values are taken and concatenated
// with the configured separator in order.
SourceLabels model.LabelNames `yaml:"source_labels,flow,omitempty"`
SourceLabels model.LabelNames `yaml:"source_labels,flow,omitempty" json:"sourceLabels,omitempty"`
// Separator is the string between concatenated values from the source labels.
Separator string `yaml:"separator,omitempty"`
Separator string `yaml:"separator,omitempty" json:"separator,omitempty"`
// Regex against which the concatenation is matched.
Regex Regexp `yaml:"regex,omitempty"`
Regex Regexp `yaml:"regex,omitempty" json:"regex,omitempty"`
// Modulus to take of the hash of concatenated values from the source labels.
Modulus uint64 `yaml:"modulus,omitempty"`
Modulus uint64 `yaml:"modulus,omitempty" json:"modulus,omitempty"`
// TargetLabel is the label to which the resulting string is written in a replacement.
// Regexp interpolation is allowed for the replace action.
TargetLabel string `yaml:"target_label,omitempty"`
TargetLabel string `yaml:"target_label,omitempty" json:"targetLabel,omitempty"`
// Replacement is the regex replacement pattern to be used.
Replacement string `yaml:"replacement,omitempty"`
Replacement string `yaml:"replacement,omitempty" json:"replacement,omitempty"`
// Action is the action to be performed for the relabeling.
Action Action `yaml:"action,omitempty"`
Action Action `yaml:"action,omitempty" json:"action,omitempty"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
Expand Down Expand Up @@ -207,6 +208,25 @@ func (re Regexp) MarshalYAML() (interface{}, error) {
return nil, nil
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (re *Regexp) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
r, err := NewRegexp(s)
if err != nil {
return err
}
*re = r
return nil
}

// MarshalJSON implements the json.Marshaler interface.
func (re Regexp) MarshalJSON() ([]byte, error) {
return json.Marshal(re.String())
}

// IsZero implements the yaml.IsZeroer interface.
func (re Regexp) IsZero() bool {
return re.Regexp == DefaultRelabelConfig.Regex.Regexp
Expand Down
33 changes: 33 additions & 0 deletions model/relabel/relabel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package relabel

import (
"encoding/json"
"strconv"
"testing"

Expand Down Expand Up @@ -964,3 +965,35 @@ func TestRegexp_ShouldMarshalAndUnmarshalZeroValue(t *testing.T) {
require.NoError(t, err)
require.Nil(t, unmarshalled.Regexp)
}

func TestRegexp_JSONUnmarshalThenMarshal(t *testing.T) {
tests := []struct {
name string
input string
}{
{
name: "Empty regex",
input: `{"regex":""}`,
},
{
name: "string literal",
input: `{"regex":"foo"}`,
},
{
name: "regex",
input: `{"regex":".*foo.*"}`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var unmarshalled Config
err := json.Unmarshal([]byte(test.input), &unmarshalled)
require.NoError(t, err)

marshalled, err := json.Marshal(&unmarshalled)
require.NoError(t, err)

require.Equal(t, test.input, string(marshalled))
})
}
}
Loading
Loading