Skip to content

Commit

Permalink
feature: add prometheus lab
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Ou authored and alice890308 committed Mar 5, 2024
1 parent 4698cac commit 74e0490
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions pkg/otelkit/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type PrometheusServiceMeterConfig struct {
type PrometheusServiceMeter struct {
metric.Meter

server *http.Server
requestCounter syncint64.Counter
requestErrorCounter syncint64.Counter
server *http.Server
requestCounter syncint64.Counter
// TODO
responseTimeHistogram syncint64.Histogram
}

Expand All @@ -54,10 +54,8 @@ func (m *PrometheusServiceMeter) UnaryServerInterceptor() func(ctx context.Conte

resp, err := handler(ctx, req)

// error count request
if err != nil {
m.requestErrorCounter.Add(ctx, 1, attributes...)
}
// update error request counter when error occurs
// TODO

// measure response time
responseTime := time.Since(start)
Expand Down Expand Up @@ -88,20 +86,18 @@ func NewPrometheusServiceMeter(ctx context.Context, conf *PrometheusServiceMeter
logger.Fatal("failed to create requests counter", zap.Error(err))
}

requestErrorCounter, err := meter.SyncInt64().Counter("error_request", instrument.WithDescription("count number of error requests"))
if err != nil {
logger.Fatal("failed to create error requests counter", zap.Error(err))
}
// initiate error request counter
// TODO

responseTimeHistogram, err := meter.SyncInt64().Histogram("response_time", instrument.WithDescription("measure response time"))
if err != nil {
logger.Fatal("failed to create response time histogram", zap.Error(err))
}

return &PrometheusServiceMeter{
server: server,
requestCounter: requestCounter,
requestErrorCounter: requestErrorCounter,
server: server,
requestCounter: requestCounter,
// TODO
responseTimeHistogram: responseTimeHistogram,
}
}
Expand Down

0 comments on commit 74e0490

Please sign in to comment.