Skip to content

Commit

Permalink
ci: Enable linting of code in examples/ (#4880)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- The HotROD source code was never formatted or linted because
golangci-lint was automatically excluding /examples/

## Description of the changes
- Disable linter's default skip dirs (which include /examples/)
- Fix linter errors

---------

Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro authored Oct 22, 2023
1 parent 3b47d6b commit 74f3488
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 19 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ linters-settings:
run:
go: "1.20"
timeout: 20m
skip-dirs-use-default: false
skip-dirs:
- mocks
- thrift-0.9.2
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2023 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0

SHELL := /bin/bash
JAEGER_IMPORT_PATH = github.com/jaegertracing/jaeger
STORAGE_PKGS = ./plugin/storage/integration/...
Expand All @@ -15,7 +18,6 @@ ALL_SRC = $(shell find . -name '*.go' \
-not -name 'model.pb.go' \
-not -name 'model_test.pb.go' \
-not -name 'storage_test.pb.go' \
-not -path './examples/*' \
-not -path './vendor/*' \
-not -path '*/mocks/*' \
-not -path '*/*-gen/*' \
Expand Down Expand Up @@ -175,7 +177,6 @@ lint:
./scripts/import-order-cleanup.sh stdout > $(IMPORT_LOG)
@[ ! -s "$(FMT_LOG)" -a ! -s "$(IMPORT_LOG)" ] || (echo "License check or import ordering failures, run 'make fmt'" | cat - $(FMT_LOG) $(IMPORT_LOG) && false)
./scripts/check-semconv-version.sh

./scripts/check-go-version.sh

.PHONY: build-examples
Expand Down
1 change: 1 addition & 0 deletions examples/hotrod/cmd/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
1 change: 0 additions & 1 deletion examples/hotrod/cmd/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var frontendCmd = &cobra.Command{
Short: "Starts Frontend service",
Long: `Starts Frontend service.`,
RunE: func(cmd *cobra.Command, args []string) error {

options.FrontendHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(frontendPort))
options.DriverHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(driverPort))
options.CustomerHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(customerPort))
Expand Down
1 change: 1 addition & 0 deletions examples/hotrod/pkg/delay/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
1 change: 1 addition & 0 deletions examples/hotrod/pkg/httperr/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
1 change: 1 addition & 0 deletions examples/hotrod/pkg/log/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
1 change: 1 addition & 0 deletions examples/hotrod/pkg/pool/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
1 change: 1 addition & 0 deletions examples/hotrod/pkg/tracing/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
9 changes: 5 additions & 4 deletions examples/hotrod/pkg/tracing/rpcmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ type Metrics struct {
}

func (m *Metrics) recordHTTPStatusCode(statusCode int64) {
if statusCode >= 200 && statusCode < 300 {
switch {
case statusCode >= 200 && statusCode < 300:
m.HTTPStatusCode2xx.Inc(1)
} else if statusCode >= 300 && statusCode < 400 {
case statusCode >= 300 && statusCode < 400:
m.HTTPStatusCode3xx.Inc(1)
} else if statusCode >= 400 && statusCode < 500 {
case statusCode >= 400 && statusCode < 500:
m.HTTPStatusCode4xx.Inc(1)
} else if statusCode >= 500 && statusCode < 600 {
case statusCode >= 500 && statusCode < 600:
m.HTTPStatusCode5xx.Inc(1)
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestObserver(t *testing.T) {
span.SetName(testCase.opNameOverride)
}
if testCase.err {
span.SetStatus(codes.Error, "An error occured")
span.SetStatus(codes.Error, "An error occurred")
}
span.End(finishOptions)
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestTags(t *testing.T) {
)
span.SetAttributes(testCase.attr)
if testCase.err {
span.SetStatus(codes.Error, "An error occured")
span.SetStatus(codes.Error, "An error occurred")
}
span.End()
testTracer.metrics.AssertCounterMetrics(t, testCase.metrics...)
Expand Down
1 change: 1 addition & 0 deletions examples/hotrod/services/config/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
1 change: 1 addition & 0 deletions examples/hotrod/services/customer/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
8 changes: 7 additions & 1 deletion examples/hotrod/services/customer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"net/http"
"strconv"
"time"

"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
Expand Down Expand Up @@ -54,7 +55,12 @@ func NewServer(hostPort string, otelExporter string, metricsFactory metrics.Fact
func (s *Server) Run() error {
mux := s.createServeMux()
s.logger.Bg().Info("Starting", zap.String("address", "http://"+s.hostPort))
return http.ListenAndServe(s.hostPort, mux)
server := &http.Server{
Addr: s.hostPort,
Handler: mux,
ReadHeaderTimeout: 3 * time.Second,
}
return server.ListenAndServe()
}

func (s *Server) createServeMux() http.Handler {
Expand Down
1 change: 1 addition & 0 deletions examples/hotrod/services/driver/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
29 changes: 24 additions & 5 deletions examples/hotrod/services/driver/driver.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/hotrod/services/frontend/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
8 changes: 7 additions & 1 deletion examples/hotrod/services/frontend/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"path"
"strconv"
"time"

"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -75,7 +76,12 @@ func NewServer(options ConfigOptions, tracer trace.TracerProvider, logger log.Fa
func (s *Server) Run() error {
mux := s.createServeMux()
s.logger.Bg().Info("Starting", zap.String("address", "http://"+path.Join(s.hostPort, s.basepath)))
return http.ListenAndServe(s.hostPort, mux)
server := &http.Server{
Addr: s.hostPort,
Handler: mux,
ReadHeaderTimeout: 3 * time.Second,
}
return server.ListenAndServe()
}

func (s *Server) createServeMux() http.Handler {
Expand Down
1 change: 1 addition & 0 deletions examples/hotrod/services/route/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
7 changes: 6 additions & 1 deletion examples/hotrod/services/route/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ func NewServer(hostPort string, tracer trace.TracerProvider, logger log.Factory)
func (s *Server) Run() error {
mux := s.createServeMux()
s.logger.Bg().Info("Starting", zap.String("address", "http://"+s.hostPort))
return http.ListenAndServe(s.hostPort, mux)
server := &http.Server{
Addr: s.hostPort,
Handler: mux,
ReadHeaderTimeout: 3 * time.Second,
}
return server.ListenAndServe()
}

func (s *Server) createServeMux() http.Handler {
Expand Down
6 changes: 4 additions & 2 deletions examples/hotrod/services/route/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
"github.com/jaegertracing/jaeger/examples/hotrod/pkg/tracing"
)

var routeCalcByCustomer = expvar.NewMap("route.calc.by.customer.sec")
var routeCalcBySession = expvar.NewMap("route.calc.by.session.sec")
var (
routeCalcByCustomer = expvar.NewMap("route.calc.by.customer.sec")
routeCalcBySession = expvar.NewMap("route.calc.by.session.sec")
)

var stats = []struct {
expvar *expvar.Map
Expand Down

0 comments on commit 74f3488

Please sign in to comment.