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

chore: Remove the Metrics name dedup #22

Merged
merged 3 commits into from
Mar 28, 2023
Merged
Changes from all commits
Commits
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
49 changes: 25 additions & 24 deletions prometheus-pusher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor Author

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

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))
Copy link

Choose a reason for hiding this comment

The 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")
}
Copy link
Member

Choose a reason for hiding this comment

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

Logically, missing default?

err = pusher.Push()
Copy link

Choose a reason for hiding this comment

The 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))
Copy link

Choose a reason for hiding this comment

The 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
Expand Down