Skip to content

Commit

Permalink
backend: update golangci-lint to v1.63.4, enable linters and fix errors
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Hahling <robin.hahling@gw-computing.net>
  • Loading branch information
rolinh committed Feb 5, 2025
1 parent f22bad2 commit 20a47b0
Show file tree
Hide file tree
Showing 32 changed files with 179 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86
with:
working-directory: ./backend
version: v1.59.0
version: v1.63.4
args: --config=.golangci.yml --verbose --out-${NO_FUTURE}format colored-line-number
skip-cache: true
- name: Setup Node.js
Expand Down
15 changes: 13 additions & 2 deletions backend/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Also https://github.com/cilium/cilium/blob/master/.golangci.yaml as a
# reference.
run:
go: '1.22'
go: '1.23'
timeout: 3m
linters:
disable-all: true
Expand All @@ -12,36 +12,47 @@ linters:
- bidichk
- bodyclose
- contextcheck
- copyloopvar
- decorder
- dupword
- durationcheck
- err113
- errchkjson
- errname
- exptostd
- gocheckcompilerdirectives
- gocritic
- gofmt
- goimports
- goprintffuncname
- gosec
- gosec
- gosimple
- govet
- ineffassign
- interfacebloat
- intrange
- makezero
- mirror
- misspell
- nakedret
- nilerr
- noctx
- nosprintfhostport
- perfsprint
- predeclared
- protogetter
- reassign
- revive
- sloglint
- staticcheck
- tenv
- testifylint
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- usetesting
- wastedassign
linters-settings:
gocritic:
Expand Down
65 changes: 33 additions & 32 deletions backend/domain/flow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package flow

import (
"fmt"
"strconv"

pbFlow "github.com/cilium/cilium/api/v1/flow"
"github.com/cilium/hubble-ui/backend/domain/service"
Expand Down Expand Up @@ -44,7 +45,7 @@ func (f *Flow) BuildServices() (*service.Service, *service.Service) {

func (f *Flow) BuildSenderService() *service.Service {
svc := service.FromEndpointProtoAndDNS(
f.ref, f.ref.Source, f.ref.SourceNames,
f.ref, f.ref.GetSource(), f.ref.GetSourceNames(),
)

svc.SetIsSender(true)
Expand All @@ -54,7 +55,7 @@ func (f *Flow) BuildSenderService() *service.Service {

func (f *Flow) BuildReceiverService() *service.Service {
svc := service.FromEndpointProtoAndDNS(
f.ref, f.ref.Destination, f.ref.DestinationNames,
f.ref, f.ref.GetDestination(), f.ref.GetDestinationNames(),
)

svc.SetIsReceiver(true)
Expand All @@ -63,11 +64,11 @@ func (f *Flow) BuildReceiverService() *service.Service {
}

func (f *Flow) TCP() *pbFlow.TCP {
if f.ref.L4 == nil {
if f.ref.GetL4() == nil {
return nil
}

tcp, ok := f.ref.L4.Protocol.(*pbFlow.Layer4_TCP)
tcp, ok := f.ref.GetL4().GetProtocol().(*pbFlow.Layer4_TCP)
if !ok {
return nil
}
Expand All @@ -76,11 +77,11 @@ func (f *Flow) TCP() *pbFlow.TCP {
}

func (f *Flow) UDP() *pbFlow.UDP {
if f.ref.L4 == nil {
if f.ref.GetL4() == nil {
return nil
}

udp, ok := f.ref.L4.Protocol.(*pbFlow.Layer4_UDP)
udp, ok := f.ref.GetL4().GetProtocol().(*pbFlow.Layer4_UDP)
if !ok {
return nil
}
Expand All @@ -89,11 +90,11 @@ func (f *Flow) UDP() *pbFlow.UDP {
}

func (f *Flow) ICMPv4() *pbFlow.Layer4_ICMPv4 {
if f.ref.L4 == nil {
if f.ref.GetL4() == nil {
return nil
}

icmp, ok := f.ref.L4.Protocol.(*pbFlow.Layer4_ICMPv4)
icmp, ok := f.ref.GetL4().GetProtocol().(*pbFlow.Layer4_ICMPv4)
if !ok {
return nil
}
Expand All @@ -102,11 +103,11 @@ func (f *Flow) ICMPv4() *pbFlow.Layer4_ICMPv4 {
}

func (f *Flow) ICMPv6() *pbFlow.Layer4_ICMPv6 {
if f.ref.L4 == nil {
if f.ref.GetL4() == nil {
return nil
}

icmp, ok := f.ref.L4.Protocol.(*pbFlow.Layer4_ICMPv6)
icmp, ok := f.ref.GetL4().GetProtocol().(*pbFlow.Layer4_ICMPv6)
if !ok {
return nil
}
Expand Down Expand Up @@ -156,55 +157,55 @@ func (f *Flow) SourcePort() *uint32 {
func (f *Flow) String() string {
srcPort, dstPort := "-", "-"
if f.SourcePort() != nil {
srcPort = fmt.Sprintf("%d", *f.SourcePort())
srcPort = strconv.FormatUint(uint64(*f.SourcePort()), 10)
}

if f.DestinationPort() != nil {
dstPort = fmt.Sprintf("%d", *f.DestinationPort())
dstPort = strconv.FormatUint(uint64(*f.DestinationPort()), 10)
}

sourceEpDesc := "nil"
if f.ref.Source != nil {
if f.ref.GetSource() != nil {
sourceEpDesc = fmt.Sprintf(
"ID: %d, Identity: %d, ns: %s, podname: %s, labels: %v",
f.ref.Source.ID,
f.ref.Source.Identity,
f.ref.Source.Namespace,
f.ref.Source.PodName,
f.ref.Source.Labels,
f.ref.GetSource().GetID(),
f.ref.GetSource().GetIdentity(),
f.ref.GetSource().GetNamespace(),
f.ref.GetSource().GetPodName(),
f.ref.GetSource().GetLabels(),
)
}

sourceSvc := f.ref.SourceService
sourceSvc := f.ref.GetSourceService()
sourceSvcDesc := "nil"
if sourceSvc != nil {
sourceSvcDesc = fmt.Sprintf(
"ns: %s, name: %s",
sourceSvc.Namespace,
sourceSvc.Name,
sourceSvc.GetNamespace(),
sourceSvc.GetName(),
)
}

destinationEp := f.ref.Destination
destinationEp := f.ref.GetDestination()
destinationEpDesc := "nil"
if destinationEp != nil {
destinationEpDesc = fmt.Sprintf(
"ID: %d, Identity: %d, ns: %s, podname: %s, labels: %v",
destinationEp.ID,
destinationEp.Identity,
destinationEp.Namespace,
destinationEp.PodName,
destinationEp.Labels,
destinationEp.GetID(),
destinationEp.GetIdentity(),
destinationEp.GetNamespace(),
destinationEp.GetPodName(),
destinationEp.GetLabels(),
)
}

destinationSvc := f.ref.DestinationService
destinationSvc := f.ref.GetDestinationService()
destinationSvcDesc := "nil"
if destinationSvc != nil {
destinationSvcDesc = fmt.Sprintf(
"ns: %s, name: %s",
destinationSvc.Namespace,
destinationSvc.Name,
destinationSvc.GetNamespace(),
destinationSvc.GetName(),
)
}

Expand All @@ -222,11 +223,11 @@ func (f *Flow) String() string {
f.ProtocolString(),
sourceEpDesc,
sourceSvcDesc,
f.ref.SourceNames,
f.ref.GetSourceNames(),
srcPort,
destinationEpDesc,
destinationSvcDesc,
f.ref.DestinationNames,
f.ref.GetDestinationNames(),
dstPort,
)
}
Expand Down
2 changes: 1 addition & 1 deletion backend/domain/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@ func getServiceId(
return fmt.Sprintf("%s-%s", dnsNames[0], sideStr)
}

return fmt.Sprintf("world-%s", sideStr)
return "world-" + sideStr
}
2 changes: 1 addition & 1 deletion backend/internal/api_helpers/server-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func ServerStatusNotification(

func flowsStatusFromSS(ss *observer.ServerStatusResponse) *ui.FlowStats {
perSecond := 0.0
if uptime := time.Duration(ss.GetUptimeNs()).Seconds(); uptime > 0 {
if uptime := time.Duration(ss.GetUptimeNs()).Seconds(); uptime > 0 { //nolint:gosec
perSecond = float64(ss.GetSeenFlows()) / uptime
}

Expand Down
2 changes: 1 addition & 1 deletion backend/internal/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func New(
func (srv *APIServer) Listen() error {
port := srv.port
addr := fmt.Sprintf("0.0.0.0:%d", port)
rootRoute := fmt.Sprintf("%s/:RouteName", srv.rootRoute)
rootRoute := srv.rootRoute + "/:RouteName"

mux := httprouter.New()
mux.Handler(http.MethodPost, rootRoute, srv.router)
Expand Down
8 changes: 4 additions & 4 deletions backend/internal/customprotocol/customprotocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func TestConsumeHandlerUpdates(t *testing.T) {

d, ok := current.(*StringAndNum)
if !ok {
return fmt.Errorf("wrong handler data")
return errors.New("wrong handler data")
}

if d.Num == 2 {
Expand Down Expand Up @@ -566,7 +566,7 @@ func TestConsumeHandlerUpdates(t *testing.T) {
case hd := <-ch.HandlerDataUpdated():
d, ok := hd.(*StringAndNum)
if !ok {
return fmt.Errorf("handler data is not a string")
return errors.New("handler data is not a string")
}

if d.Num != i {
Expand Down Expand Up @@ -739,7 +739,7 @@ func streamErrAfterResponse(ch *channel.Channel) error {
}

func streamFiveNumbers(ch *channel.Channel) error {
for i := 0; i < 5; i++ {
for i := range 5 {
body := []byte(fmt.Sprintf("number: %d", i+1))

if err := ch.Send(body); err != nil {
Expand Down Expand Up @@ -809,7 +809,7 @@ func streamSteppedRate(ch *channel.Channel) error {

parts := strings.Split(string(firstMsg.BodyBytes()), " ")
if len(parts) != 4 {
return fmt.Errorf("stepped rate handler need 4 components")
return errors.New("stepped rate handler need 4 components")
}

nOne, err := strconv.ParseUint(parts[0], 10, 64)
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/customprotocol/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func FromError(err error) *cppb.Error {
if grpcStatus, ok := status.FromError(err); ok {
return &cppb.Error{
Kind: cppb.Error_Grpc,
Code: int32(grpcStatus.Code()),
Code: uint32(grpcStatus.Code()),
Message: grpcStatus.Message(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/customprotocol/message/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (b MessageBuilder) WithNotReady(nr bool) MessageBuilder {
}

func (b MessageBuilder) WithPollDelay(d time.Duration) MessageBuilder {
b.p.Meta.PollDelayMs = uint64(d.Milliseconds())
b.p.Meta.PollDelayMs = d.Milliseconds()
return b
}

Expand Down
2 changes: 1 addition & 1 deletion backend/internal/customprotocol/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (m *Message) IsEmpty() bool {
return m.Proto.GetMeta().GetIsEmpty()
}

func (m *Message) PollDelayMs() uint64 {
func (m *Message) PollDelayMs() int64 {
return m.Proto.GetMeta().GetPollDelayMs()
}

Expand Down
4 changes: 2 additions & 2 deletions backend/internal/customprotocol/message/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ func (m *Messages) PeekIncoming() *Message {
return *msg
}

func (m *Messages) OutgoingsSize() uint {
func (m *Messages) OutgoingsSize() int {
return m.outgoings.Size()
}

func (m *Messages) IncomingsSize() uint {
func (m *Messages) IncomingsSize() int {
return m.incomings.Size()
}
6 changes: 3 additions & 3 deletions backend/internal/customprotocol/router/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func (b CPBuilder) WithChannelIdBytesNumber(n int) CPBuilder {
return b
}

func (b CPBuilder) WithClientPollDelays(min, max time.Duration) CPBuilder {
func (b CPBuilder) WithClientPollDelays(low, high time.Duration) CPBuilder {
b.timingsBuilder = b.timingsBuilder.
WithMinClientPollDelay(min).
WithMaxClientPollDelay(max)
WithMinClientPollDelay(low).
WithMaxClientPollDelay(high)

return b
}
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/customprotocol/timings/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (ct *ChannelTimings) CountOutgoingPayload() {
}

// NOTE: This function is assumed to be called after outgoing message is popped
func (ct *ChannelTimings) ClientPollDelay(noutgoings uint) time.Duration {
func (ct *ChannelTimings) ClientPollDelay(noutgoings int) time.Duration {
// NOTE: If there is pending outgoing message, the client should poll
// as fast as possible
if noutgoings > 0 {
Expand Down
6 changes: 3 additions & 3 deletions backend/internal/flow_stream/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func ExtractFlowsRequest(
// https://github.com/cilium/hubble/issues/363
var (
getFlowsSinceTime time.Time
getFlowsLastNumber int
getFlowsLastNumber uint64
err error
isGetSinceSet bool
isGetLastSet bool
Expand All @@ -65,11 +65,11 @@ func ExtractFlowsRequest(
if !isGetLastSet {
request.Number = 10000
} else {
if getFlowsLastNumber, err = strconv.Atoi(getFlowsLast); err != nil {
if getFlowsLastNumber, err = strconv.ParseUint(getFlowsLast, 10, 64); err != nil {
log.Errorf(msg.GetFlowsLastParseError, err)
request.Number = 10000
} else {
request.Number = uint64(getFlowsLastNumber)
request.Number = getFlowsLastNumber
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/internal/mock/sources/sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func testNsName(i int) string {
func prepareNSEvents(start, _num int) []*common.NSEvent {
evts := []*common.NSEvent{}

for i := 0; i < _num; i += 1 {
for i := range _num {
evts = append(
evts,
factories.CreateNSEvent(events.Added, testNsName(start+i)),
Expand Down
Loading

0 comments on commit 20a47b0

Please sign in to comment.