Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move to go 1.23 #141

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.21', '1.22']
go: ['1.23']

steps:
- uses: actions/checkout@v3
Expand All @@ -27,7 +27,7 @@ jobs:
- name: check clean vendors
run: go mod vendor
- name: Report coverage
if: ${{ matrix.go == '1.22' }}
if: ${{ matrix.go == '1.23' }}
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request_e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: set up go 1.x
uses: actions/setup-go@v3
with:
go-version: '1.22'
go-version: '1.23'
- name: checkout
uses: actions/checkout@v3
- name: get kernel version
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.22']
go: ['1.23']
steps:
- name: install make
run: sudo apt-get install make
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.22']
go: ['1.23']
steps:
- name: install make
run: sudo apt-get install make
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push_image_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.22']
go: ['1.23']
steps:
- name: install make
run: sudo apt-get install make
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.22']
go: ['1.23']
steps:
- name: checkout
uses: actions/checkout@v3
Expand Down
12 changes: 7 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ linters:
- cyclop
- errname
- exhaustive
- exportloopref
- copyloopvar
- gocritic
- gofmt
- gosimple
Expand All @@ -16,15 +16,17 @@ linters:
- stylecheck
- typecheck
- unused
run:
go: "1.22"
linters-settings:
stylecheck:
go: "1.22"
gocritic:
enabled-checks:
- hugeParam
- rangeExprCopy
- rangeValCopy
- indexAlloc
- deprecatedComment
settings:
ifElseChain:
minThreshold: 3
cyclop:
max-complexity: 150 # TODO: reduce that to 20
max-complexity: 150 # TODO: reduce that to 20
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ARG TARGETARCH=amd64

# Build the manager binary
FROM docker.io/library/golang:1.22 as builder
FROM docker.io/library/golang:1.23 as builder

ARG TARGETARCH
ARG LDFLAGS
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.downstream
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ARG TARGETARCH=amd64
ARG COMMIT

# Build the manager binary
FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:v1.22.5-202407301806.g4c8b32d.el9 as builder
FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:v1.23 as builder

ARG TARGETARCH
ARG TARGETPLATFORM
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ifneq ($(CLEAN_BUILD),)
LDFLAGS ?= -X 'main.buildVersion=${VERSION}-${BUILD_SHA}' -X 'main.buildDate=${BUILD_DATE}'
endif

GOLANGCI_LINT_VERSION = v1.54.2
GOLANGCI_LINT_VERSION = v1.61.0
YQ_VERSION = v4.43.1

# build a single arch target provided as argument
Expand Down
70 changes: 40 additions & 30 deletions cmd/flow_capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,38 @@ var (
)

func runFlowCapture(_ *cobra.Command, _ []string) {
go scanner()
go func() {
if !scanner() {
return
}
// scanner returns on exit request
os.Exit(0)
}()

captureType = "Flow"
wg := sync.WaitGroup{}
wg.Add(len(ports))
for i := range ports {
go func(idx int) {
defer wg.Done()
runFlowCaptureOnAddr(ports[idx], nodes[idx])
err := runFlowCaptureOnAddr(ports[idx], nodes[idx])
if err != nil {
// Only fatal errors are returned here
log.Fatal(err)
}
}(i)
}
wg.Wait()
}

func runFlowCaptureOnAddr(port int, filename string) {
func runFlowCaptureOnAddr(port int, filename string) error {
if len(filename) > 0 {
log.Infof("Starting Flow Capture for %s...", filename)
} else {
log.Infof("Starting Flow Capture...")
filename = strings.Replace(
filename = strings.ReplaceAll(
currentTime().UTC().Format(time.RFC3339),
":", "", -1) // get rid of offensive colons
":", "") // get rid of offensive colons
}

var f *os.File
Expand All @@ -105,8 +115,7 @@ func runFlowCaptureOnAddr(port int, filename string) {
flowPackets := make(chan *genericmap.Flow, 100)
collector, err := grpc.StartCollector(port, flowPackets)
if err != nil {
log.Error("StartCollector failed:", err.Error())
log.Fatal(err)
return fmt.Errorf("StartCollector failed: %w", err)
}
log.Trace("Started collector")
collectorStarted = true
Expand All @@ -128,7 +137,7 @@ func runFlowCaptureOnAddr(port int, filename string) {

if stopReceived {
log.Trace("Stop received")
return
return nil
}
// parse and display flow async
go parseGenericMapAndDisplay(fp.GenericMap.Value)
Expand All @@ -145,18 +154,18 @@ func runFlowCaptureOnAddr(port int, filename string) {
// append new line between each record to read file easilly
bytes, err := f.Write(append(fp.GenericMap.Value, []byte(",\n")...))
if err != nil {
log.Fatal(err)
return err
}
if !captureStarted {
log.Trace("Wrote flows to json")
}

// terminate capture if max bytes reached
totalBytes = totalBytes + int64(bytes)
totalBytes += int64(bytes)
if totalBytes > maxBytes {
if exit := onLimitReached(); exit {
log.Infof("Capture reached %s, exiting now...", sizestr.ToString(maxBytes))
return
return nil
}
}

Expand All @@ -166,12 +175,13 @@ func runFlowCaptureOnAddr(port int, filename string) {
if int(duration) > int(maxTime) {
if exit := onLimitReached(); exit {
log.Infof("Capture reached %s, exiting now...", maxTime)
return
return nil
}
}

captureStarted = true
}
return nil
}

func parseGenericMapAndDisplay(bytes []byte) {
Expand Down Expand Up @@ -202,7 +212,7 @@ func manageFlowsDisplay(genericMap config.GenericMap) {
if len(regexes) > 0 {
// regexes may change during the render so we make a copy first
rCopy := make([]string, len(regexes))
copy(rCopy[:], regexes)
copy(rCopy, regexes)
filtered := []config.GenericMap{}
for _, flow := range lastFlows {
match := true
Expand Down Expand Up @@ -380,10 +390,10 @@ func cycleOption(selection []string, exclusiveOptions []string, options []string
return selection
}

func scanner() {
func scanner() bool {
jotak marked this conversation as resolved.
Show resolved Hide resolved
if err := keyboard.Open(); err != nil {
keyboardError = fmt.Sprintf("Keyboard not supported %v", err)
return
return false
}
defer func() {
_ = keyboard.Close()
Expand All @@ -394,26 +404,26 @@ func scanner() {
if err != nil {
panic(err)
}
if key == keyboard.KeyCtrlC || stopReceived {
switch {
case key == keyboard.KeyCtrlC, stopReceived:
log.Info("Ctrl-C pressed, exiting program.")

// exit program
os.Exit(0)
} else if key == keyboard.KeyArrowUp {
flowsToShow = flowsToShow + 1
} else if key == keyboard.KeyArrowDown {
return true
case key == keyboard.KeyArrowUp:
flowsToShow++
case key == keyboard.KeyArrowDown:
if flowsToShow > 10 {
flowsToShow = flowsToShow - 1
flowsToShow--
}
} else if key == keyboard.KeyArrowRight {
case key == keyboard.KeyArrowRight:
display = cycleOption(display, exclusiveDisplays, displays, 1)
} else if key == keyboard.KeyArrowLeft {
case key == keyboard.KeyArrowLeft:
display = cycleOption(display, exclusiveDisplays, displays, -1)
} else if key == keyboard.KeyPgup {
case key == keyboard.KeyPgup:
enrichment = cycleOption(enrichment, exclusiveEnrichments, enrichments, 1)
} else if key == keyboard.KeyPgdn {
case key == keyboard.KeyPgdn:
enrichment = cycleOption(enrichment, exclusiveEnrichments, enrichments, -1)
} else if key == keyboard.KeyBackspace || key == keyboard.KeyBackspace2 {
case key == keyboard.KeyBackspace || key == keyboard.KeyBackspace2:
if len(regexes) > 0 {
lastIndex := len(regexes) - 1
if len(regexes[lastIndex]) > 0 {
Expand All @@ -422,14 +432,14 @@ func scanner() {
regexes = regexes[:lastIndex]
}
}
} else if key == keyboard.KeyEnter {
case key == keyboard.KeyEnter:
regexes = append(regexes, "")
} else {
default:
if len(regexes) == 0 {
regexes = []string{string(char)}
} else {
lastIndex := len(regexes) - 1
regexes[lastIndex] = regexes[lastIndex] + string(char)
regexes[lastIndex] += string(char)
}
}
lastRefresh = startupTime
Expand Down
4 changes: 2 additions & 2 deletions cmd/flow_capture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func TestFlowTableMultipleFlows(t *testing.T) {
buf.Reset()

// update time and bytes for next flow
flowTime = flowTime + 1000
bytes = bytes + 1000
flowTime += 1000
bytes += 1000

// add flow to table
parseGenericMapAndDisplay([]byte(fmt.Sprintf(`{
Expand Down
18 changes: 10 additions & 8 deletions cmd/flow_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ func insertFlowToDB(db *sql.DB, buf []byte) error {
}
// Insert message into database
var flowSQL string
if flow["PktDropPackets"] != 0 && flow["DnsId"] != 0 {
switch {
case flow["PktDropPackets"] != 0 && flow["DnsId"] != 0:
flowSQL =
`INSERT INTO flow(DnsErrno, Dscp, DstAddr, DstPort, Interface, Proto, SrcAddr, SrcPort, Bytes, Packets, PktDropLatestDropCause, PktDropBytes, PktDropPackets, DnsId, DnsFlagsResponseCode, DnsLatencyMs, TimeFlowRttNs) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
} else if flow["PktDropPackets"] != 0 {
case flow["PktDropPackets"] != 0:
flowSQL =
`INSERT INTO flow(DnsErrno, Dscp, DstAddr, DstPort, Interface, Proto, SrcAddr, SrcPort, Bytes, Packets, PktDropLatestDropCause, PktDropBytes, PktDropPackets, TimeFlowRttNs) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
} else if flow["DnsId"] != 0 {
case flow["DnsId"] != 0:
flowSQL =
`INSERT INTO flow(DnsErrno, Dscp, DstAddr, DstPort, Interface, Proto, SrcAddr, SrcPort, Bytes, Packets, DnsId, DnsFlagsResponseCode, DnsLatencyMs, TimeFlowRttNs) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
} else {
default:
flowSQL =
`INSERT INTO flow(DnsErrno, Dscp, DstAddr, DstPort, Interface, Proto, SrcAddr, SrcPort, Bytes, Packets, TimeFlowRttNs) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
}
Expand All @@ -116,26 +117,27 @@ func insertFlowToDB(db *sql.DB, buf []byte) error {
return fmt.Errorf("error preparing SQL: %v", err.Error())
}

if flow["PktDropLatestDropCause"] != 0 && flow["DnsId"] != 0 {
switch {
case flow["PktDropLatestDropCause"] != 0 && flow["DnsId"] != 0:
_, err = statement.Exec(
flow["DNSErrno"], flow["Dscp"], flow["DstAddr"], flow["DstPort"], flow["Interface"],
flow["Proto"], flow["SrcAddr"], flow["SrcPort"], flow["Bytes"], flow["Packets"],
flow["PktDropLatestDropCause"], flow["PktDropBytes"], flow["PktDropPackets"],
flow["DnsId"], flow["DnsFlagsResponseCode"], flow["DnsLatencyMs"],
flow["TimeFlowRttNs"])
} else if flow["PktDropLatestDropCause"] != 0 {
case flow["PktDropLatestDropCause"] != 0:
_, err = statement.Exec(
flow["DNSErrno"], flow["Dscp"], flow["DstAddr"], flow["DstPort"], flow["Interface"],
flow["Proto"], flow["SrcAddr"], flow["SrcPort"], flow["Bytes"], flow["Packets"],
flow["PktDropLatestDropCause"], flow["PktDropBytes"], flow["PktDropPackets"],
flow["TimeFlowRttNs"])
} else if flow["DnsId"] != 0 {
case flow["DnsId"] != 0:
_, err = statement.Exec(
flow["DNSErrno"], flow["Dscp"], flow["DstAddr"], flow["DstPort"], flow["Interface"],
flow["Proto"], flow["SrcAddr"], flow["SrcPort"], flow["Bytes"], flow["Packets"],
flow["DnsId"], flow["DnsFlagsResponseCode"], flow["DnsLatencyMs"],
flow["TimeFlowRttNs"])
} else {
default:
_, err = statement.Exec(
flow["DNSErrno"], flow["Dscp"], flow["DstAddr"], flow["DstPort"], flow["Interface"],
flow["Proto"], flow["SrcAddr"], flow["SrcPort"], flow["Bytes"], flow["Packets"],
Expand Down
Loading
Loading