Skip to content

feat: use named loggers in coderd #8148

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

Merged
merged 8 commits into from
Jun 22, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
prometheusmetrics error
  • Loading branch information
mtojek committed Jun 22, 2023
commit 54d554632881c7c0e7331c0017351621f2fd089b
19 changes: 11 additions & 8 deletions coderd/prometheusmetrics/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const (
)

const (
logPrefix = "prometheusmetrics: "
logPrefixErr = "prometheusmetrics error: "

sizeCollectCh = 10
sizeUpdateCh = 1024

Expand Down Expand Up @@ -141,7 +144,7 @@ func (ma *MetricsAggregator) Run(ctx context.Context) func() {
for {
select {
case req := <-ma.updateCh:
ma.log.Debug(ctx, "metrics aggregator: update metrics")
ma.log.Debug(ctx, logPrefix+"update metrics")

timer := prometheus.NewTimer(ma.updateHistogram)
UpdateLoop:
Expand All @@ -167,21 +170,21 @@ func (ma *MetricsAggregator) Run(ctx context.Context) func() {

timer.ObserveDuration()
case outputCh := <-ma.collectCh:
ma.log.Debug(ctx, "metrics aggregator: collect metrics")
ma.log.Debug(ctx, logPrefix+"collect metrics")

output := make([]prometheus.Metric, 0, len(ma.queue))
for _, m := range ma.queue {
promMetric, err := m.asPrometheus()
if err != nil {
ma.log.Error(ctx, "can't convert Prometheus value type", slog.F("name", m.Name), slog.F("type", m.Type), slog.F("value", m.Value), slog.Error(err))
ma.log.Error(ctx, logPrefixErr+"can't convert Prometheus value type", slog.F("name", m.Name), slog.F("type", m.Type), slog.F("value", m.Value), slog.Error(err))
continue
}
output = append(output, promMetric)
}
outputCh <- output
close(outputCh)
case <-cleanupTicker.C:
ma.log.Debug(ctx, "metrics aggregator: clean expired metrics")
ma.log.Debug(ctx, logPrefix+"clean expired metrics")

timer := prometheus.NewTimer(ma.cleanupHistogram)

Expand Down Expand Up @@ -209,7 +212,7 @@ func (ma *MetricsAggregator) Run(ctx context.Context) func() {
cleanupTicker.Reset(ma.metricsCleanupInterval)

case <-ctx.Done():
ma.log.Debug(ctx, "metrics aggregator: is stopped")
ma.log.Debug(ctx, logPrefix+"metrics aggregator is stopped")
return
}
}
Expand All @@ -233,7 +236,7 @@ func (ma *MetricsAggregator) Collect(ch chan<- prometheus.Metric) {
select {
case ma.collectCh <- output:
default:
ma.log.Error(context.Background(), "metrics aggregator: collect queue is full")
ma.log.Error(context.Background(), logPrefixErr+"collect queue is full")
return
}

Expand All @@ -255,9 +258,9 @@ func (ma *MetricsAggregator) Update(ctx context.Context, username, workspaceName
timestamp: time.Now(),
}:
case <-ctx.Done():
ma.log.Debug(ctx, "metrics aggregator: update request is canceled")
ma.log.Debug(ctx, logPrefix+"update request is canceled")
default:
ma.log.Error(ctx, "metrics aggregator: update queue is full")
ma.log.Error(ctx, logPrefixErr+"update queue is full")
}
}

Expand Down