-
Notifications
You must be signed in to change notification settings - Fork 1
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
[MM-55224] convert plugin config to scraper config #3
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
114fd7d
convert plugin config to scraper config
isacikgoz 7ad949a
run go mod tidy
isacikgoz ac689ab
reflect review comments
isacikgoz fc752eb
add metriccs port
isacikgoz 322c67e
use correct address label
isacikgoz 5e0c29f
fix typo
isacikgoz 06b47ef
disable typecheck from imported modules
isacikgoz 7f27c6b
manually disable typecheck on some directories
isacikgoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/prometheus/prometheus/model/labels" | ||
) | ||
|
||
var ( | ||
sampleMutator func(labels.Labels) labels.Labels //nolint:unused | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/prometheus/common/model" | ||
"github.com/prometheus/prometheus/model/labels" | ||
"github.com/prometheus/prometheus/model/relabel" | ||
"github.com/prometheus/prometheus/scrape" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
func mutateSampleLabels(lset labels.Labels, target *scrape.Target, honor bool, rc []*relabel.Config) labels.Labels { | ||
lb := labels.NewBuilder(lset) | ||
|
||
if honor { | ||
agnivade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
target.LabelsRange(func(l labels.Label) { | ||
if !lset.Has(l.Name) { | ||
lb.Set(l.Name, l.Value) | ||
} | ||
}) | ||
} else { | ||
var conflictingExposedLabels []labels.Label | ||
target.LabelsRange(func(l labels.Label) { | ||
existingValue := lset.Get(l.Name) | ||
if existingValue != "" { | ||
conflictingExposedLabels = append(conflictingExposedLabels, labels.Label{Name: l.Name, Value: existingValue}) | ||
} | ||
// It is now safe to set the target label. | ||
lb.Set(l.Name, l.Value) | ||
}) | ||
|
||
if len(conflictingExposedLabels) > 0 { | ||
resolveConflictingExposedLabels(lb, conflictingExposedLabels) | ||
} | ||
} | ||
|
||
res := lb.Labels() | ||
|
||
if len(rc) > 0 { | ||
res, _ = relabel.Process(res, rc...) | ||
} | ||
|
||
return res | ||
} | ||
|
||
func resolveConflictingExposedLabels(lb *labels.Builder, conflictingExposedLabels []labels.Label) { | ||
agnivade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
slices.SortStableFunc(conflictingExposedLabels, func(a, b labels.Label) bool { | ||
return len(a.Name) < len(b.Name) | ||
}) | ||
|
||
for _, l := range conflictingExposedLabels { | ||
newName := l.Name | ||
for { | ||
newName = model.ExportedLabelPrefix + newName | ||
if lb.Get(newName) == "" { | ||
lb.Set(newName, l.Value) | ||
break | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prometheus/common/model" | ||
"github.com/prometheus/prometheus/model/labels" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestResolveConflictingExposedLabels(t *testing.T) { | ||
lb := labels.NewBuilder(labels.FromMap(map[string]string{ | ||
model.AddressLabel: "test-address", | ||
model.ScrapeIntervalLabel: "1s", | ||
model.ScrapeTimeoutLabel: "5s", | ||
})) | ||
|
||
t.Run("no conflicts", func(t *testing.T) { | ||
lbls := []labels.Label{} | ||
resolveConflictingExposedLabels(lb, lbls) | ||
|
||
require.Equal(t, 3, lb.Labels().Len()) // we defined 3 labels they are not conflicting | ||
}) | ||
|
||
t.Run("conflicting on address label", func(t *testing.T) { | ||
lbls := []labels.Label{ | ||
{Name: model.AddressLabel, Value: "new-address"}, | ||
} | ||
resolveConflictingExposedLabels(lb, lbls) | ||
|
||
require.NotEmpty(t, lb.Get(model.AddressLabel)) | ||
require.NotEmpty(t, lb.Get(model.ExportedLabelPrefix+model.AddressLabel)) | ||
require.Equal(t, "new-address", lb.Get(model.ExportedLabelPrefix+model.AddressLabel)) | ||
}) | ||
|
||
t.Run("not conflicting, does not exist in the label set", func(t *testing.T) { | ||
lbls := []labels.Label{ | ||
{Name: "new-key", Value: "new-address"}, | ||
} | ||
resolveConflictingExposedLabels(lb, lbls) | ||
|
||
require.Empty(t, lb.Get("new-key")) | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also impose a max body size limit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we can do that. Ideally it should be unbounded as we are unaware of possible sample size but for our case we can forecast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have some limit as a config for customers to enforce. We can have some large value as default, but it'd be good to allow customers to set some limit as their preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add that check for the next PR