-
Notifications
You must be signed in to change notification settings - Fork 5
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
chore: Remove the Metrics name dedup #22
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,32 +55,33 @@ func (c *myCollector) Collect(ch chan<- prometheus.Metric) { | |
} | ||
|
||
func (p *prometheusSink) push(msgPayloads []Payload) error { | ||
keys := make(map[string]bool) | ||
|
||
for _, payload := range msgPayloads { | ||
if _, ok := keys[payload.Name]; !ok { | ||
pusher, err := p.createPusher(fmt.Sprintf("%s_%s_%s", payload.Namespace, payload.Subsystem, payload.Name)) | ||
if err != nil { | ||
return err | ||
} | ||
switch payload.Type { | ||
case "Gauge": | ||
p.logger.Debugf("Creating Collector %s", payload.Name) | ||
pusher = pusher.Collector(&myCollector{ | ||
metric: prometheus.NewDesc(payload.Name, "", nil, payload.Labels), | ||
metricType: prometheus.GaugeValue, | ||
value: payload.Value, | ||
}) | ||
appName := payload.Labels["app"] | ||
p.metrics.IncreaseAnomalyGenerated(payload.Namespace, appName, payload.Name) | ||
keys[payload.Name] = true | ||
} | ||
err = pusher.Push() | ||
if err != nil { | ||
return err | ||
} | ||
p.metrics.IncreaseTotalSuccess() | ||
p.logger.Debugw("Pushing Payload ", zap.Any("payload", payload)) | ||
pusher, err := p.createPusher(fmt.Sprintf("%s_%s_%s", payload.Namespace, payload.Subsystem, payload.Name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to double check: do we need to create a new pusher for each payload item? |
||
if err != nil { | ||
return err | ||
} | ||
switch payload.Type { | ||
case "Gauge": | ||
p.logger.Debugf("Creating Collector %s", payload.Name) | ||
pusher = pusher.Collector(&myCollector{ | ||
metric: prometheus.NewDesc(payload.Name, "", nil, payload.Labels), | ||
metricType: prometheus.GaugeValue, | ||
value: payload.Value, | ||
}) | ||
appName := payload.Labels["app"] | ||
p.metrics.IncreaseAnomalyGenerated(payload.Namespace, appName, payload.Name) | ||
default: | ||
p.logger.Errorw("Unsupported Metrics Type", zap.Any("payload", payload)) | ||
return fmt.Errorf("unsupported Metrics Type") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logically, missing |
||
err = pusher.Push() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to double check: if a pusher needs an explicit close or such call. |
||
if err != nil { | ||
p.logger.Errorw("Failed to push", zap.Any("payload", payload), zap.Error(err)) | ||
return err | ||
} | ||
p.logger.Infow("Successfully pushed", zap.Any("payload", payload)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would this infow() generate too many log lines in regular cases? |
||
p.metrics.IncreaseTotalSuccess() | ||
|
||
} | ||
return nil | ||
|
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.
name level dedub was removed