Skip to content

Commit

Permalink
fix golang lint errors in metricsreader test image
Browse files Browse the repository at this point in the history
  • Loading branch information
KauzClay committed Jun 13, 2023
1 parent 34850a5 commit 73c1f11
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions test/test_images/metricsreader/metricsreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
Expand All @@ -35,8 +35,8 @@ import (
)

const (
ACTIVATOR_METRIC_KEY = "activator_tls_connection_count"
QUEUE_METRIC_KEY = "revision_tls_connection_count"
ActivatorMetricKey = "activator_tls_connection_count"
QueueMetricKey = "revision_tls_connection_count"
)

type PostData struct {
Expand All @@ -51,12 +51,12 @@ type MetricsClient struct {
func (mc *MetricsClient) GetMetricsData(source string) (map[string]*io_prometheus_client.MetricFamily, error) {
resp, err := mc.Get(fmt.Sprintf("http://%s/metrics", source))
if err != nil {
return nil, fmt.Errorf("error: couldn't call %s metrics endpoint: %s", source, err)
return nil, fmt.Errorf("error: couldn't call %s metrics endpoint: %w", source, err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error: couldn't read response body from %s metrics endpoint: %s", source, err)
return nil, fmt.Errorf("error: couldn't read response body from %s metrics endpoint: %w", source, err)
}
return parseMetricsData(body)
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func parseMetricsData(d []byte) (map[string]*io_prometheus_client.MetricFamily,
var parser expfmt.TextParser
mf, err := parser.TextToMetricFamilies(bytes.NewReader(d))
if err != nil {
return nil, fmt.Errorf("error: couldn't parse metrics output: %s", err)
return nil, fmt.Errorf("error: couldn't parse metrics output: %w", err)
}
return mf, nil
}
Expand Down Expand Up @@ -128,16 +128,16 @@ func getMetrics(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
}

if m, ok := activatorData[ACTIVATOR_METRIC_KEY]; ok {
results[ACTIVATOR_METRIC_KEY] = int(*m.Metric[0].Counter.Value)
if m, ok := activatorData[ActivatorMetricKey]; ok {
results[ActivatorMetricKey] = int(*m.Metric[0].Counter.Value)
} else {
results[ACTIVATOR_METRIC_KEY] = 0
results[ActivatorMetricKey] = 0
}

if m, ok := queueData[QUEUE_METRIC_KEY]; ok {
results[QUEUE_METRIC_KEY] = int(*m.Metric[0].Counter.Value)
if m, ok := queueData[QueueMetricKey]; ok {
results[QueueMetricKey] = int(*m.Metric[0].Counter.Value)
} else {
results[QUEUE_METRIC_KEY] = 0
results[QueueMetricKey] = 0
}

jsonResponseData, err := json.Marshal(results)
Expand Down

0 comments on commit 73c1f11

Please sign in to comment.