Skip to content

Commit

Permalink
chore: fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Oct 2, 2023
1 parent 85a8783 commit 9d227e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
14 changes: 6 additions & 8 deletions checks/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func getOrAddPrometheusMetric(name, metricType string, labelNames []string) (pro
return collector, prometheus.Register(collector)
}

func getWithEnvironment(ctx *context.Context, r *pkg.CheckResult) (*context.Context, error) {
func getWithEnvironment(ctx *context.Context, r *pkg.CheckResult) *context.Context {
templateInput := map[string]any{
"result": r.Data,
"canary": map[string]any{
Expand All @@ -58,7 +58,7 @@ func getWithEnvironment(ctx *context.Context, r *pkg.CheckResult) (*context.Cont
"duration": time.Millisecond * time.Duration(r.GetDuration()),
},
}
return ctx.New(templateInput), nil
return ctx.New(templateInput)
}

func getLabels(ctx *context.Context, metric external.Metrics) (map[string]string, []string, error) {
Expand Down Expand Up @@ -104,11 +104,9 @@ func exportCheckMetrics(ctx *context.Context, results pkg.Results) {
continue
}

ctx = getWithEnvironment(ctx, r)

var err error
if ctx, err = getWithEnvironment(ctx, r); err != nil {
r.ErrorMessage(err)
continue
}
var labels map[string]string
var labelNames []string
if labels, labelNames, err = getLabels(ctx, spec); err != nil {
Expand All @@ -123,7 +121,7 @@ func exportCheckMetrics(ctx *context.Context, results pkg.Results) {
}

var val float64
if val, err = getMetricValue(ctx, spec, r); err != nil {
if val, err = getMetricValue(ctx, spec); err != nil {
r.ErrorMessage(err)
continue
}
Expand All @@ -147,7 +145,7 @@ func exportCheckMetrics(ctx *context.Context, results pkg.Results) {
}
}

func getMetricValue(ctx *context.Context, spec external.Metrics, r *pkg.CheckResult) (float64, error) {
func getMetricValue(ctx *context.Context, spec external.Metrics) (float64, error) {
tplValue := v1.Template{Expression: spec.Value}

valRaw, err := template(ctx, tplValue)
Expand Down
13 changes: 12 additions & 1 deletion pkg/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,18 @@ type Metric struct {
}

func (m Metric) String() string {
return fmt.Sprintf("%s=%d", m.Name, int(m.Value))
labels := ""
if len(m.Labels) > 0 {
labels = "{"
for k, v := range m.Labels {
if labels != "{" {
labels += ", "
}
labels += fmt.Sprintf("%s=%s", k, v)
}
labels += "}"
}
return fmt.Sprintf("%s%s=%d", m.Name, labels, int(m.Value))
}

func (e Endpoint) GetEndpoint() string {
Expand Down

0 comments on commit 9d227e9

Please sign in to comment.