Skip to content

Commit

Permalink
chore: docs & error formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Bressi <[email protected]>
  • Loading branch information
puffitos committed Jan 12, 2024
1 parent 584bbae commit c4776d1
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 74 deletions.
98 changes: 49 additions & 49 deletions chart/README.md

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ func run() func(cmd *cobra.Command, args []string) error {
log.Info("Running sparrow")
if err = s.Run(ctx); err != nil {
err = fmt.Errorf("error while running sparrow: %w", err)
// by this time all shutdown routines should have been called
// so we can exit here
return err
}

Expand Down
6 changes: 3 additions & 3 deletions internal/helper/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestRetry(t *testing.T) {
if effectorFuncCallCounter > 1 {
return nil
}
return fmt.Errorf("Ups sth wrong")
return fmt.Errorf("ups sth wrong")
},
rc: RetryConfig{
Count: 2,
Expand All @@ -81,7 +81,7 @@ func TestRetry(t *testing.T) {
args: args{
effector: func(ctx context.Context) error {
effectorFuncCallCounter++
return fmt.Errorf("Ups sth wrong")
return fmt.Errorf("ups sth wrong")
},
rc: RetryConfig{
Count: 2,
Expand All @@ -98,7 +98,7 @@ func TestRetry(t *testing.T) {
effector: func(ctx context.Context) error {
effectorFuncCallCounter++
cancel()
return errors.New("Ups")
return errors.New("ups")
},
rc: RetryConfig{
Count: 2,
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/routingtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"sync"
)

// creates a simple routing tree, so checks can easily create and remove handlers
// RoutingTree creates a simple routing tree, so checks can easily create and remove handlers
// Maps the method to the path and the handler
type RoutingTree struct {
tree map[string]map[string]http.HandlerFunc
Expand Down
10 changes: 8 additions & 2 deletions pkg/checks/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package checks
import (
"context"
"fmt"
"io"
"net/http"
"sync"
"time"
Expand Down Expand Up @@ -243,12 +244,17 @@ func getHealth(ctx context.Context, url string) error {
return err
}

res, err := client.Do(req)
res, err := client.Do(req) //nolint:bodyclose
if err != nil {
log.Error("Http get request failed", "error", err.Error())
return err
}
defer res.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
log.Error("Failed to close response body", "error", err.Error())
}
}(res.Body)

if res.StatusCode != http.StatusOK {
log.Error("Http get request failed", "status", res.Status)
Expand Down
2 changes: 1 addition & 1 deletion pkg/checks/oapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/getkin/kin-openapi/openapi3gen"
)

// Takes in check perfdata and returns an openapi3.SchemaRef of a result wrapping the perfData
// OpenapiFromPerfData takes in check perfdata and returns an openapi3.SchemaRef of a result wrapping the perfData
// this is a workaround, since the openapi3gen.NewSchemaRefForValue function does not work with any types
func OpenapiFromPerfData[T any](data T) (*openapi3.SchemaRef, error) {
checkSchema, err := openapi3gen.NewSchemaRefForValue(Result{}, openapi3.Schemas{})
Expand Down
12 changes: 6 additions & 6 deletions pkg/config/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ func (hl *HttpLoader) Run(ctx context.Context) error {
}

// GetRuntimeConfig gets the remote runtime configuration
func (gl *HttpLoader) GetRuntimeConfig(ctx context.Context) (*RuntimeConfig, error) {
log := logger.FromContext(ctx).With("url", gl.cfg.Loader.Http.Url)
func (hl *HttpLoader) GetRuntimeConfig(ctx context.Context) (*RuntimeConfig, error) {
log := logger.FromContext(ctx).With("url", hl.cfg.Loader.Http.Url)

req, err := http.NewRequestWithContext(ctx, http.MethodGet, gl.cfg.Loader.Http.Url, http.NoBody)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, hl.cfg.Loader.Http.Url, http.NoBody)
if err != nil {
log.Error("Could not create http GET request", "error", err.Error())
return nil, err
}
if gl.cfg.Loader.Http.Token != "" {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", gl.cfg.Loader.Http.Token))
if hl.cfg.Loader.Http.Token != "" {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", hl.cfg.Loader.Http.Token))
}

res, err := gl.client.Do(req) //nolint:bodyclose
res, err := hl.client.Do(req) //nolint:bodyclose
if err != nil {
log.Error("Http get request failed", "error", err.Error())
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (i *InMemory) Get(check string) (checks.Result, bool) {
return *result, true
}

// Returns a copy of the map
// List returns a copy of the map
func (i *InMemory) List() map[string]checks.Result {
results := make(map[string]checks.Result)
i.data.Range(func(key, value any) bool {
Expand Down
7 changes: 2 additions & 5 deletions pkg/sparrow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ const (
readHeaderTimeout = time.Second * 5
)

var (
ErrServeApi = errors.New("failed to serve api")
ErrCreateOpenapiSchema = errors.New("failed to get schema for check")
)
var ErrCreateOpenapiSchema = errors.New("failed to get schema for check")

func (s *Sparrow) register(ctx context.Context) {
s.router.Use(logger.Middleware(ctx))
Expand Down Expand Up @@ -101,7 +98,7 @@ func (s *Sparrow) api(ctx context.Context) error {
}
}

// Shutdown gracefully shuts down the api server
// shutdownAPI gracefully shuts down the api server
// Returns an error if an error is present in the context
// or if the server cannot be shut down
func (s *Sparrow) shutdownAPI(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sparrow/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type PrometheusMetrics struct {
registry *prometheus.Registry
}

// InitMetrics initializes the metrics and returns the PrometheusMetrics
// NewMetrics initializes the metrics and returns the PrometheusMetrics
func NewMetrics() Metrics {
registry := prometheus.NewRegistry()

Expand Down
2 changes: 1 addition & 1 deletion pkg/sparrow/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestSparrow_Run(t *testing.T) {
},
}

c.Loader.File.Path = ("../config/testdata/config.yaml")
c.Loader.File.Path = "../config/testdata/config.yaml"

// start sparrow
s := New(c)
Expand Down
4 changes: 2 additions & 2 deletions scripts/gen-docs/gen-docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func execute() {
rootCmd.AddCommand(NewCmdGenDocs())

if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Expand All @@ -68,7 +68,7 @@ func runGenDocs(path *string) func(cmd *cobra.Command, args []string) error {
c.DisableAutoGenTag = true
return func(cmd *cobra.Command, args []string) error {
if err := doc.GenMarkdownTree(c, *path); err != nil {
return fmt.Errorf("Failed to generate docs: %w", err)
return fmt.Errorf("failed to generate docs: %w", err)
}
return nil
}
Expand Down

0 comments on commit c4776d1

Please sign in to comment.