Skip to content

Commit

Permalink
Merge pull request #23 from ultravioletrs/NOISSUE-metric
Browse files Browse the repository at this point in the history
NOISSUE - Add Metric To Internal Package
  • Loading branch information
darkodraskovic authored Jul 24, 2023
2 parents 3a57c8d + c09383a commit 6cecedd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
20 changes: 3 additions & 17 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ import (
"github.com/ultravioletrs/agent/agent/api"
agentgrpc "github.com/ultravioletrs/agent/agent/api/grpc"
agenthttpapi "github.com/ultravioletrs/agent/agent/api/http"
"github.com/ultravioletrs/agent/internal"
"github.com/ultravioletrs/agent/internal/env"
"google.golang.org/grpc"

kitprometheus "github.com/go-kit/kit/metrics/prometheus"
opentracing "github.com/opentracing/opentracing-go"
stdprometheus "github.com/prometheus/client_golang/prometheus"
jconfig "github.com/uber/jaeger-client-go/config"
)

Expand Down Expand Up @@ -95,21 +94,8 @@ func newService(secret string, logger logger.Logger) agent.Service {
svc := agent.New(secret)

svc = api.LoggingMiddleware(svc, logger)
svc = api.MetricsMiddleware(
svc,
kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: "agent",
Subsystem: "api",
Name: "request_count",
Help: "Number of requests received.",
}, []string{"method"}),
kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{
Namespace: "agent",
Subsystem: "api",
Name: "request_latency_microseconds",
Help: "Total duration of requests in microseconds.",
}, []string{"method"}),
)
counter, latency := internal.MakeMetrics(svcName, "api")
svc = api.MetricsMiddleware(svc, counter, latency)

return svc
}
Expand Down
25 changes: 25 additions & 0 deletions internal/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package internal

import (
kitprometheus "github.com/go-kit/kit/metrics/prometheus"
stdprometheus "github.com/prometheus/client_golang/prometheus"
)

// MakeMetrics returns an instance of metrics.
func MakeMetrics(namespace, subsystem string) (*kitprometheus.Counter, *kitprometheus.Summary) {
counter := kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "request_count",
Help: "Number of requests received.",
}, []string{"method"})
latency := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{
Namespace: namespace,
Subsystem: subsystem,
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
Name: "request_latency_microseconds",
Help: "Total duration of requests in microseconds.",
}, []string{"method"})

return counter, latency
}

0 comments on commit 6cecedd

Please sign in to comment.