Skip to content

Commit

Permalink
Metrics are always enabled (#54)
Browse files Browse the repository at this point in the history
Remove metrics.NewFromEnv that uses env variables.

AB#9124
  • Loading branch information
eccles authored Mar 20, 2024
1 parent b89ff10 commit 5309618
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 40 deletions.
38 changes: 11 additions & 27 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

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

const (
Expand Down Expand Up @@ -98,33 +96,19 @@ func WithLabel(label string, offset int) MetricsOption {
}
}

func New(log Logger, serviceName string, opts ...MetricsOption) *Metrics {
m := Metrics{
log: log,
serviceName: strings.ToLower(serviceName),
registry: prometheus.NewRegistry(),
labels: []latencyObserveOffset{},
}
for _, opt := range opts {
opt(&m)
}
return &m
func New(log Logger, serviceName string, port string, opts ...MetricsOption) *Metrics {
var m Metrics
return new_(&m, log, serviceName, port, opts...)
}

func NewFromEnvironment(log Logger, serviceName string, opts ...MetricsOption) *Metrics {
useMetrics := environment.GetTruthyOrFatal("USE_METRICS")
var port string
if useMetrics {
port = environment.GetOrFatal("METRICS_PORT")
}
var m *Metrics
if port != "" {
m = New(
log,
serviceName,
opts...,
)
m.port = port
func new_(m *Metrics, log Logger, serviceName string, port string, opts ...MetricsOption) *Metrics {
m.log = log
m.serviceName = strings.ToLower(serviceName)
m.registry = prometheus.NewRegistry()
m.labels = []latencyObserveOffset{}
m.port = port
for _, opt := range opts {
opt(m)
}
return m
}
Expand Down
13 changes: 0 additions & 13 deletions startup/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@ func WithListeners(listeners ...Listener) ListenersOption {
}
}

// WithOptionalListeners add multiple listeners. Nil listeners will
// be ignored.
func WithOptionalListeners(listeners ...Listener) ListenersOption {
return func(l *Listeners) {
for i := 0; i < len(listeners); i++ {
listener := listeners[i]
if listener != nil && !reflect.ValueOf(listener).IsNil() {
l.listeners = append(l.listeners, listener)
}
}
}
}

func NewListeners(log Logger, name string, opts ...ListenersOption) Listeners {
l := Listeners{name: strings.ToLower(name)}
for _, opt := range opts {
Expand Down

0 comments on commit 5309618

Please sign in to comment.