diff --git a/agent/agent.go b/agent/agent.go index 8e8211a..65d0f3c 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -236,7 +236,7 @@ func waitForHealthy() { return } ticker := time.NewTicker(time.Duration(*healthCheckFreq) * time.Second) - for _ = range ticker.C { + for range ticker.C { if healthCheck() == nil { ticker.Stop() return @@ -258,7 +258,7 @@ func runHealthChecks() { // immediately. ticker := time.NewTicker(time.Duration(*healthCheckFreq) * time.Second) badHealthChecks := 0 - for _ = range ticker.C { + for range ticker.C { if healthCheck() != nil { badHealthChecks++ } else { diff --git a/agent/banner/banner.go b/agent/banner/banner.go index a3068eb..cfa18ec 100644 --- a/agent/banner/banner.go +++ b/agent/banner/banner.go @@ -140,9 +140,9 @@ func (w *bannerResponseWriter) getFavIconLink() (string, error) { } var favIconLinkBuf bytes.Buffer templateVals := &struct { - FavIconUrl string + FavIconURL string }{ - FavIconUrl: w.favIconURL, + FavIconURL: w.favIconURL, } if err := favIconLinkTmpl.Execute(&favIconLinkBuf, templateVals); err != nil { return "", err @@ -185,9 +185,9 @@ func (w *bannerResponseWriter) WriteHeader(statusCode int) { w.wrapped.WriteHeader(statusCode) w.writeBytes = true return - } else { - w.Header().Del(contentEncodingHeader) } + w.Header().Del(contentEncodingHeader) + favIconLink, err := w.getFavIconLink() if err != nil { sc := http.StatusInternalServerError diff --git a/agent/metrics/metrics.go b/agent/metrics/metrics.go index ccadce9..2f840e0 100644 --- a/agent/metrics/metrics.go +++ b/agent/metrics/metrics.go @@ -48,6 +48,7 @@ type metricClient interface { CreateTimeSeries(ctx context.Context, req *monitoringpb.CreateTimeSeriesRequest, opts ...gax.CallOption) error } +// MetricHandler handles metrics collections/writes to cloud monarch type MetricHandler struct { mu sync.Mutex projectID string @@ -147,7 +148,7 @@ func parseGCEResourceLabels(resourceKeyValues string) (*map[string]string, error "zone": "", } err := parseResourceLabels(resourceKeyValues, &flags) - for key, _ := range res { + for key := range res { flagKey := responseCountResourceKeyToFlagName[key] flagValue := flags[flagKey] if flagValue == "" { @@ -178,6 +179,7 @@ func parseResourceLabels(resourceKeyValues string, labels *map[string]string) er return nil } +// GetResponseCountMetricType constructs and returns a string representing the response_count metric type func (h *MetricHandler) GetResponseCountMetricType() string { if h == nil { return "" diff --git a/agent/utils/utils.go b/agent/utils/utils.go index a0b5583..2d5c077 100644 --- a/agent/utils/utils.go +++ b/agent/utils/utils.go @@ -127,10 +127,10 @@ func parseRequestIDs(response *http.Response, metricHandler *metrics.MetricHandl } responseBytes, err := ioutil.ReadAll(responseBody) if err != nil { - return nil, fmt.Errorf("Failed to read the forwarded request: %q\n", err.Error()) + return nil, fmt.Errorf("failed to read the forwarded request: %q", err.Error()) } if response.StatusCode != http.StatusOK { - return nil, fmt.Errorf("Failed to list pending requests: %d, %q", response.StatusCode, responseBytes) + return nil, fmt.Errorf("failed to list pending requests: %d, %q", response.StatusCode, responseBytes) } if len(responseBytes) <= 0 { return []string{}, nil @@ -138,7 +138,7 @@ func parseRequestIDs(response *http.Response, metricHandler *metrics.MetricHandl var requests []string if err := json.Unmarshal(responseBytes, &requests); err != nil { - return nil, fmt.Errorf("Failed to parse the requests: %q\n", err.Error()) + return nil, fmt.Errorf("failed to parse the requests: %q", err.Error()) } return requests, nil } diff --git a/agent/websockets/shim.go b/agent/websockets/shim.go index d4b5bd1..3f78814 100644 --- a/agent/websockets/shim.go +++ b/agent/websockets/shim.go @@ -253,6 +253,7 @@ func (sb *shimmedBody) Close() error { return sb.closer.Close() } +// ShimBody returns a function that injects code into a *http.Response Body func ShimBody(shimPath string) (func(resp *http.Response) error, error) { var templateBuf bytes.Buffer if err := shimTmpl.Execute(&templateBuf, &struct{ ShimPath string }{ShimPath: shimPath}); err != nil { diff --git a/testing/runlocal/main.go b/testing/runlocal/main.go index e2978fd..d584d26 100644 --- a/testing/runlocal/main.go +++ b/testing/runlocal/main.go @@ -57,6 +57,7 @@ var ( respTmpl = template.Must(template.New("response").Parse(responseTemplate)) ) +// RunLocalProxy runs a proxy locally func RunLocalProxy(ctx context.Context) (int, error) { // This assumes that "Make build" has been run proxyArgs := fmt.Sprintf("${GOPATH}/bin/inverting-proxy --port=%d", *port)