Skip to content
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

Metrics are always enabled #54

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading