Skip to content

Commit

Permalink
Remove tenant id from metrics
Browse files Browse the repository at this point in the history
The tenantid is no longer a label on latency metrics.

Additionally corrected the generated mocks for azbus.

AB#8906
  • Loading branch information
Paul Hewlett authored and eccles committed May 7, 2024
1 parent 2c5ead5 commit d602252
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 49 deletions.
31 changes: 20 additions & 11 deletions azbus/mocks/Handler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions azbus/mocks/MsgReceiver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 25 additions & 8 deletions azbus/mocks/MsgSender.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 2 additions & 16 deletions metrics/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"net/http"
"strings"
"time"

"github.com/datatrails/go-datatrails-common/tenantid"
)

// Tailored Prometheus metrics
Expand Down Expand Up @@ -53,21 +51,9 @@ func (m *Metrics) NewLatencyMetricsHandler(h http.Handler) http.Handler {

latency := time.Since(start).Seconds()

header := lrw.Header()

// generate post-process metrics here...

// tenantID
// TODO: when we put the tenant ID in the JWT we can get rid of these
// odd header arrangements
var tenant string
tenantID := tenantid.GetTenantIDFromHeader(header)
if tenantID != "" {
log.Debugf("tenant ID %s", tenantID)
tenant = strings.TrimPrefix(tenantID, tenantid.Prefix)
tenantid.DeleteTenantIDFromHeader(header)
}
observer.ObserveRequestsCount(fields, r.Method, tenant)
observer.ObserveRequestsLatency(latency, fields, r.Method, tenant)
observer.ObserveRequestsCount(fields, r.Method)
observer.ObserveRequestsLatency(latency, fields, r.Method)
})
}
14 changes: 7 additions & 7 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func CosmosChargeMetric() *prometheus.GaugeVec {
return prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "archivist_cosmos_charge",
Help: "Cosmos charge by tenant, method and resource.",
Help: "Cosmos charge by method and resource.",
},
[]string{"tenant", "method", "resource"},
[]string{"method", "resource"},
)
}

Expand All @@ -29,9 +29,9 @@ func CosmosDurationMetric() *prometheus.GaugeVec {
return prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "archivist_cosmos_duration",
Help: "Cosmos duration by tenant, method and resource.",
Help: "Cosmos duration by method and resource.",
},
[]string{"tenant", "method", "resource"},
[]string{"method", "resource"},
)
}

Expand All @@ -40,9 +40,9 @@ func RequestsCounterMetric() *prometheus.CounterVec {
return prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "archivist_requests_total",
Help: "Total number of requests by method, tenant, service and resource.",
Help: "Total number of requests by method, service and resource.",
},
[]string{"method", "tenant", "service", "resource"},
[]string{"method", "service", "resource"},
)
}

Expand All @@ -57,7 +57,7 @@ func RequestsLatencyMetric() *prometheus.HistogramVec {
Help: "Histogram of time to reply to request.",
Buckets: []float64{.005, .01, .02, .04, .08, .16, .32},
},
[]string{"method", "tenant", "service", "resource"},
[]string{"method", "service", "resource"},
)
}

Expand Down
12 changes: 6 additions & 6 deletions metrics/observers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ func NewLatencyObservers(m *Metrics) LatencyObservers {
return o
}

func (o *LatencyObservers) ObserveRequestsCount(fields []string, method string, tenant string) {
func (o *LatencyObservers) ObserveRequestsCount(fields []string, method string) {

for _, label := range o.labels {
if len(fields) > label.offset && fields[label.offset] == label.label {
o.log.Infof("Count %s: %s, %s", label.label, method, tenant)
o.requestsCounter.WithLabelValues(method, tenant, o.serviceName, label.label).Inc()
o.log.Infof("Count %s: %s", label.label, method)
o.requestsCounter.WithLabelValues(method, o.serviceName, label.label).Inc()
return
}
}
}

func (o *LatencyObservers) ObserveRequestsLatency(elapsed float64, fields []string, method string, tenant string) {
func (o *LatencyObservers) ObserveRequestsLatency(elapsed float64, fields []string, method string) {

for _, label := range o.labels {
if len(fields) > label.offset && fields[label.offset] == label.label {
o.log.Infof("Latency %v %s: %s, %s", elapsed, label.label, method, tenant)
o.requestsLatency.WithLabelValues(method, tenant, o.serviceName, label.label).Observe(elapsed)
o.log.Infof("Latency %v %s: %s", elapsed, label.label, method)
o.requestsLatency.WithLabelValues(method, o.serviceName, label.label).Observe(elapsed)
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion startup/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Run(serviceName string, run Runner) {
}
err := run(serviceName, log)
if err != nil {
log.Infof("Error terminating: %v", err)
log.Infof("Error at startup: %v", err)
exitCode = 1
}
return exitCode
Expand Down

0 comments on commit d602252

Please sign in to comment.