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

[receiver/prometheus] syncTargetAllocator now detects regex changes in relabel config #32127

Merged
merged 73 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
d1de8b3
Adding more validation
rashmichandrashekar Aug 28, 2021
35f4b63
auth test
rashmichandrashekar Aug 31, 2021
d3b0ccd
adding more tests
rashmichandrashekar Aug 31, 2021
f631611
kubernetes sd test
rashmichandrashekar Aug 31, 2021
11e35c0
adding more tests
rashmichandrashekar Aug 31, 2021
0a886f4
Merge pull request #1 from rashmichandrashekar/rashmi/promreceiver-co…
rashmichandrashekar Aug 31, 2021
9d9a83c
addressing PR comments
rashmichandrashekar Sep 8, 2021
fe3b4f2
Merge pull request #2 from rashmichandrashekar/rashmi/pr-comments
rashmichandrashekar Sep 8, 2021
a2fa93e
Merge pull request #3 from rashmichandrashekar/rashmi/promreceiver-co…
rashmichandrashekar Sep 8, 2021
f5e999d
fixing PR comment related to returning error when file doesnt exist i…
rashmichandrashekar Sep 8, 2021
424be70
Merge pull request #4 from rashmichandrashekar/rashmi/pr-comments
rashmichandrashekar Sep 8, 2021
fd262e9
Merge pull request #5 from rashmichandrashekar/rashmi/pr-comments
rashmichandrashekar Sep 8, 2021
fff66e3
Fixing lint errors
rashmichandrashekar Sep 9, 2021
f47c4ff
Merge pull request #6 from rashmichandrashekar/rashmi/pr-comments
rashmichandrashekar Sep 9, 2021
affec96
Merge pull request #7 from rashmichandrashekar/rashmi/promreceiver-co…
rashmichandrashekar Sep 9, 2021
eebe192
merging with remote
rashmichandrashekar Oct 5, 2021
a4080d8
Merge branch 'main' of https://github.com/rashmichandrashekar/opentel…
rashmichandrashekar Oct 5, 2021
f17fbd0
Merge remote-tracking branch 'upstream/main'
rashmichandrashekar Jan 2, 2024
1483b3b
Merge remote-tracking branch 'upstream/main'
rashmichandrashekar Jan 19, 2024
fc5687c
Merge remote-tracking branch 'upstream/main'
rashmichandrashekar Mar 27, 2024
eb84345
changes to new branch
rashmichandrashekar Mar 27, 2024
b81f716
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 2, 2024
e144c70
adding go mod and go sum
rashmichandrashekar Apr 2, 2024
a341238
go mod tidy
rashmichandrashekar Apr 2, 2024
9b3e031
adding missing go mod and sum entries
rashmichandrashekar Apr 2, 2024
2af9cbe
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 2, 2024
3a0079b
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 2, 2024
1b89f83
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 2, 2024
d341e4f
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 3, 2024
9a53706
adding library
rashmichandrashekar Apr 19, 2024
c6741cd
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 19, 2024
9ae5028
merging with main
rashmichandrashekar Apr 19, 2024
ad9481f
updating go mod
rashmichandrashekar Apr 19, 2024
45be98b
resolving conflicts
rashmichandrashekar Apr 19, 2024
bd5d110
moving to internal
rashmichandrashekar Apr 19, 2024
9e1f7ca
adding rt pkg
rashmichandrashekar Apr 19, 2024
8c59017
Updating go mods and sums
rashmichandrashekar Apr 19, 2024
7265d9d
removing comments
rashmichandrashekar Apr 19, 2024
566607c
fixing license
rashmichandrashekar Apr 19, 2024
e422260
adding otel license
rashmichandrashekar Apr 19, 2024
14008da
fixing lint errors
rashmichandrashekar Apr 19, 2024
c8a05b8
making more secure
rashmichandrashekar Apr 19, 2024
ac00f1e
Merge branch 'rashmi/hash-fix-2' of https://github.com/rashmichandras…
rashmichandrashekar Apr 19, 2024
ba06a4c
cleaning up
rashmichandrashekar Apr 19, 2024
f6614c2
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 19, 2024
f91cbb9
go fmt
rashmichandrashekar Apr 20, 2024
c691c2b
go fmt
rashmichandrashekar Apr 20, 2024
e610046
Merge branch 'rashmi/hash-fix-2' of github.com:rashmichandrashekar/op…
rashmichandrashekar Apr 20, 2024
72fecb5
fix go version
rashmichandrashekar Apr 20, 2024
9215009
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 20, 2024
11dbc8d
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 21, 2024
c24114d
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 22, 2024
07f7d29
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 22, 2024
80eb11f
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 22, 2024
83b4953
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 25, 2024
acf2014
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Apr 29, 2024
61687b6
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar May 2, 2024
3c36028
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar May 4, 2024
f710b26
removing structhash
rashmichandrashekar Jun 19, 2024
7bc97bb
addressing comment to sort job keys
rashmichandrashekar Jun 30, 2024
c4b65e8
adding mod
rashmichandrashekar Jun 30, 2024
550b0cf
merging with main
rashmichandrashekar Jun 30, 2024
1ecbce7
fixing hash
rashmichandrashekar Jul 6, 2024
31f7545
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Jul 7, 2024
119a1ac
adding test
rashmichandrashekar Jul 7, 2024
b852a93
Merge branch 'rashmi/hash-fix-2' of https://github.com/rashmichandras…
rashmichandrashekar Jul 7, 2024
0684887
fixing protocol
rashmichandrashekar Jul 7, 2024
998a7cc
removing wait
rashmichandrashekar Jul 7, 2024
639a2ad
removing wait
rashmichandrashekar Jul 8, 2024
5d8fe5d
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Jul 9, 2024
df760b0
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Jul 9, 2024
3037589
Merge branch 'main' into rashmi/hash-fix-2
rashmichandrashekar Jul 10, 2024
b95cc82
Merge branch 'main' into rashmi/hash-fix-2
dashpole Jul 10, 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
6 changes: 6 additions & 0 deletions .chloggen/fix_promTAHashComputation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
change_type: 'bug_fix'
component: 'prometheusreceiver'
note: Fix hash computation to include non exported fields like regex in scrape configuration for TargetAllocator
issues: [29313]
subtext:
change_logs: []
1 change: 0 additions & 1 deletion cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ require (
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion cmd/oteltestbedcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ require (
github.com/miekg/dns v1.1.59 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions cmd/oteltestbedcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions connector/datadogconnector/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ require (
github.com/miekg/dns v1.1.59 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions exporter/datadogexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions exporter/datadogexporter/integrationtest/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion exporter/prometheusexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ require (
github.com/miekg/dns v1.1.59 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions exporter/prometheusexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion receiver/prometheusreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/go-kit/log v0.2.1
github.com/gogo/protobuf v1.3.2
github.com/golang/snappy v0.0.4
github.com/mitchellh/hashstructure/v2 v2.0.2
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusremotewriteexporter v0.104.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.104.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.104.0
Expand Down
2 changes: 0 additions & 2 deletions receiver/prometheusreceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 30 additions & 2 deletions receiver/prometheusreceiver/metrics_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import (
"context"
"errors"
"fmt"
"hash/fnv"
"io"
"net/http"
"net/url"
"os"
"reflect"
"regexp"
"sort"
"sync"
"time"
"unsafe"

"github.com/go-kit/log"
"github.com/mitchellh/hashstructure/v2"
"github.com/prometheus/client_golang/prometheus"
commonconfig "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
Expand Down Expand Up @@ -145,6 +146,33 @@ func (r *pReceiver) startTargetAllocator(allocConf *TargetAllocator, baseCfg *Pr
return nil
}

// Calculate a hash for a scrape config map.
// This is done by marshaling to YAML because it's the most straightforward and doesn't run into problems with unexported fields.
func getScrapeConfigHash(jobToScrapeConfig map[string]*config.ScrapeConfig) (uint64, error) {
var err error
hash := fnv.New64()
yamlEncoder := yaml.NewEncoder(hash)

jobKeys := make([]string, 0, len(jobToScrapeConfig))
for jobName := range jobToScrapeConfig {
jobKeys = append(jobKeys, jobName)
}
sort.Strings(jobKeys)

for _, jobName := range jobKeys {
_, err = hash.Write([]byte(jobName))
if err != nil {
return 0, err
}
err = yamlEncoder.Encode(jobToScrapeConfig[jobName])
if err != nil {
return 0, err
}
}
yamlEncoder.Close()
return hash.Sum64(), err
}

// syncTargetAllocator request jobs from targetAllocator and update underlying receiver, if the response does not match the provided compareHash.
// baseDiscoveryCfg can be used to provide additional ScrapeConfigs which will be added to the retrieved jobs.
func (r *pReceiver) syncTargetAllocator(compareHash uint64, allocConf *TargetAllocator, baseCfg *PromConfig) (uint64, error) {
Expand All @@ -155,7 +183,7 @@ func (r *pReceiver) syncTargetAllocator(compareHash uint64, allocConf *TargetAll
return 0, err
}

hash, err := hashstructure.Hash(scrapeConfigsResponse, hashstructure.FormatV2, nil)
hash, err := getScrapeConfigHash(scrapeConfigsResponse)
if err != nil {
r.settings.Logger.Error("Failed to hash job list", zap.Error(err))
return 0, err
Expand Down
Loading
Loading