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

Support extra custom query parameters in requests to Prometheus backend #6360

Merged

Conversation

akstron
Copy link
Contributor

@akstron akstron commented Dec 14, 2024

Which problem is this PR solving?

Description of the changes

  • Wrapped the client in promClient to decorate url with additional parameters

How was this change tested?

  • TestCreatePromClientWithAdditionalParameters

Checklist

Signed-off-by: Alok Kumar Singh <dev.alok.singh123@gmail.com>
@akstron akstron requested a review from a team as a code owner December 14, 2024 14:24
@akstron akstron requested a review from albertteoh December 14, 2024 14:24
@dosubot dosubot bot added the enhancement label Dec 14, 2024
Copy link

codecov bot commented Dec 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.22%. Comparing base (78f5a41) to head (be61244).
Report is 40 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6360      +/-   ##
==========================================
+ Coverage   96.14%   96.22%   +0.08%     
==========================================
  Files         357      361       +4     
  Lines       20547    20623      +76     
==========================================
+ Hits        19755    19845      +90     
+ Misses        605      595      -10     
+ Partials      187      183       -4     
Flag Coverage Δ
badger_v1 8.96% <ø> (+0.18%) ⬆️
badger_v2 1.62% <0.00%> (+0.01%) ⬆️
cassandra-4.x-v1-manual 14.93% <ø> (+0.30%) ⬆️
cassandra-4.x-v2-auto 1.57% <0.00%> (+0.01%) ⬆️
cassandra-4.x-v2-manual 1.57% <0.00%> (+0.01%) ⬆️
cassandra-5.x-v1-manual 14.93% <ø> (+0.30%) ⬆️
cassandra-5.x-v2-auto 1.57% <0.00%> (+0.01%) ⬆️
cassandra-5.x-v2-manual 1.57% <0.00%> (+0.01%) ⬆️
elasticsearch-6.x-v1 18.62% <ø> (+0.28%) ⬆️
elasticsearch-7.x-v1 18.70% <ø> (+0.29%) ⬆️
elasticsearch-8.x-v1 18.86% <ø> (+0.28%) ⬆️
elasticsearch-8.x-v2 1.62% <0.00%> (+0.02%) ⬆️
grpc_v1 10.61% <ø> (+0.39%) ⬆️
grpc_v2 7.92% <0.00%> (+0.12%) ⬆️
kafka-v1 9.29% <ø> (+0.82%) ⬆️
kafka-v2 1.62% <0.00%> (+0.01%) ⬆️
memory_v2 1.62% <0.00%> (+0.01%) ⬆️
opensearch-1.x-v1 18.75% <ø> (+0.28%) ⬆️
opensearch-2.x-v1 18.74% <ø> (+0.27%) ⬆️
opensearch-2.x-v2 1.62% <0.00%> (+0.01%) ⬆️
tailsampling-processor 0.45% <0.00%> (+<0.01%) ⬆️
unittests 95.11% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Alok Kumar Singh <dev.alok.singh123@gmail.com>
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

LatencyUnit string `mapstructure:"latency_unit"`
NormalizeCalls bool `mapstructure:"normalize_calls"`
NormalizeDuration bool `mapstructure:"normalize_duration"`
AdditionalParameters map[string]string `mapstructure:"additional_parameters"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AdditionalParameters map[string]string `mapstructure:"additional_parameters"`
ExtraQueryParams map[string]string `mapstructure:"extra_query_parameters"`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a comment describing the purpose

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


promClient struct {
api.Client
params map[string]string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
params map[string]string
extraParams map[string]string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


// NewMetricsReader returns a new MetricsReader.
func NewMetricsReader(cfg config.Configuration, logger *zap.Logger, tracer trace.TracerProvider) (*MetricsReader, error) {
logger.Info("Creating metrics reader", zap.Any("configuration", cfg))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a good idea to log configuration as it may contain credentials

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was already present before I refactored it. Removed it as suggested.

LatencyUnit: defaultLatencyUnit,
NormalizeCalls: defaultNormalizeCalls,
NormalizeDuration: defaultNormalizeCalls,
AdditionalParameters: nil,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil is the default value, no effect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks. Removed it, as nil should be the default value.

Signed-off-by: Alok Kumar Singh <dev.alok.singh123@gmail.com>
@akstron akstron changed the title Add Prometheus Client Allowing Additional Parameter Add Prometheus Client Allowing Extra Query Parameters Dec 15, 2024
pkg/prometheus/config/config.go Outdated Show resolved Hide resolved

query := u.Query()
for k, v := range p.extraParams {
query.Set(k, v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why Set and not Add? We are not asked to replace params, only append them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Changed it to Add and updated test accordingly.


func createPromClient(logger *zap.Logger, cfg config.Configuration) (api.Client, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need logger here, and neither does getHTTPRoundTripper

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored to remove logger from both. Thanks


logger := zap.NewNop()
cfg := config.Configuration{
ServerURL: "http://localhost:1234",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ServerURL: "http://localhost:1234",
ServerURL: "http://localhost:1234?param1=value0",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

akstron and others added 2 commits December 16, 2024 09:18
Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
Signed-off-by: Alok Kumar Singh <62210712+akstron@users.noreply.github.com>
Signed-off-by: Alok Kumar Singh <dev.alok.singh123@gmail.com>
@akstron akstron force-pushed the prometheus-additional-query-parameter branch from 90b055f to 046b1b1 Compare December 16, 2024 13:23
Signed-off-by: Alok Kumar Singh <dev.alok.singh123@gmail.com>
pkg/prometheus/config/config.go Outdated Show resolved Hide resolved
Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
Signed-off-by: Alok Kumar Singh <62210712+akstron@users.noreply.github.com>
@yurishkuro yurishkuro changed the title Add Prometheus Client Allowing Extra Query Parameters Support extra custom query parameters in requests to Prometheus backend Dec 19, 2024
@yurishkuro yurishkuro merged commit 86f2305 into jaegertracing:main Dec 19, 2024
54 checks passed
@yurishkuro
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: spm additional query parameter required for prometheus
2 participants