DEVTOOLS-1273 created lint CI

This commit is contained in:
Xavier Foguet 2023-10-17 18:37:45 +02:00
parent 4ec5ab21f4
commit 90d2fdef15
4 changed files with 31 additions and 7 deletions

20
.github/workflows/lint.yaml vendored Normal file
View file

@ -0,0 +1,20 @@
name: Standard Lint
on:
pull_request:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
standard-lint:
uses: Typeform/.github/.github/workflows/go-lint-workflow.yaml@v1
secrets:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }}
with:
go-version: 1.20.3

View file

@ -47,8 +47,8 @@ var (
illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
hash = fnv.New64a()
strBuf bytes.Buffer // Used for hashing.
intBuf = make([]byte, 8)
strBuf bytes.Buffer // Used for hashing.
intBuf = make([]byte, 8) //nolint:gomnd
)
func labelNames(labels prometheus.Labels) []string {
@ -94,7 +94,7 @@ func (c *CounterContainer) Get(metricName string, labels prometheus.Labels, help
Help: help,
}, labelNames(labels))
if err := prometheus.Register(counterVec); err != nil {
return nil, err
return nil, fmt.Errorf("failed to register to prometheus:%w", err)
}
c.Elements[metricName] = counterVec
}
@ -544,7 +544,7 @@ func lineToEvents(line string) Events {
return events
}
elements := strings.SplitN(line, ":", 2)
elements := strings.SplitN(line, ":", 2) //nolint:gomnd
if len(elements) < 2 || len(elements[0]) == 0 || !utf8.ValidString(line) {
sampleErrors.WithLabelValues("malformed_line").Inc()
log.Debugln("Bad line from StatsD:", line)
@ -561,8 +561,9 @@ func lineToEvents(line string) Events {
samples:
for _, sample := range samples {
samplesReceived.Inc()
components := strings.Split(sample, "|")
samplingFactor := 1.0
components := strings.Split(sample, "|")
if len(components) < 2 || len(components) > 4 {
sampleErrors.WithLabelValues("malformed_component").Inc()
log.Debugln("Bad component on line:", line)

View file

@ -201,7 +201,9 @@ mappings:
t.Fatalf("Config load error: %s %s", config, err)
}
events := make(chan Events)
defer close(events)
go func() {
ex := NewExporter(testMapper)
ex.Listen(events)

View file

@ -15,6 +15,7 @@ package main
import (
"bufio"
"fmt"
"net"
"net/http"
"os"
@ -125,7 +126,7 @@ func watchConfig(fileName string, mapper *mapper.MetricMapper) {
func dumpFSM(mapper *mapper.MetricMapper, dumpFilename string) error {
f, err := os.Create(dumpFilename)
if err != nil {
return err
return fmt.Errorf("could not create file:%w", err)
}
log.Infoln("Start dumping FSM to", dumpFilename)
w := bufio.NewWriter(f)
@ -168,7 +169,7 @@ func main() {
go serveHTTP(*listenAddress, *metricsEndpoint)
events := make(chan Events, 1024)
events := make(chan Events, 1024) //nolint:gomnd
defer close(events)
if *statsdListenUDP != "" {