From 6ea93125d53bef600f872c1c0903b11897480ed3 Mon Sep 17 00:00:00 2001 From: andersh Date: Fri, 1 Dec 2023 04:58:14 +0100 Subject: [PATCH 1/5] fix: add ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f3e84b6..423340a 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ build/ .vscode/ .idea/ +config.yaml From 3d0cad1bb0429abcc6f0ac027d49dd6d7ddcf618 Mon Sep 17 00:00:00 2001 From: andersh Date: Fri, 1 Dec 2023 04:58:41 +0100 Subject: [PATCH 2/5] fix: update --- example-config.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/example-config.yaml b/example-config.yaml index 91b8ca8..e18322d 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -30,10 +30,11 @@ streams: regex: "^topology/pod-(?P[1-9][0-9]*)/node-(?P[1-9][0-9]*)/sys/.*" message: name: message - format: "%s [dn: %s]" + format: "%s podid:%s [dn: %s]" # Names are add to the format in the order they are written property_names: - descr + - podid - dn @@ -44,7 +45,8 @@ streams: timestamp: property_name: loginTime drops: - property_name: hashToken + - property_name: hashToken + - property_name: userdom message: name: mesg format: "User %s - status %s IP %s" From 3acaa638916cb7f330a95fef0d13b672afc1206d Mon Sep 17 00:00:00 2001 From: andersh Date: Fri, 1 Dec 2023 05:01:40 +0100 Subject: [PATCH 3/5] fix: add Makefile --- Makefile | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..134a686 --- /dev/null +++ b/Makefile @@ -0,0 +1,64 @@ +VERSION := $(shell git describe --tags) +GIT_HASH := $(shell git rev-parse --short HEAD ) + +GO_VERSION ?= $(shell go version) +GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION)) +LDFLAGS = -ldflags "-X main.Version=${VERSION} -X main.GitHash=${GIT_HASH} -X main.GoVersion=${GO_VERSION_NUMBER}" + +.PHONY: build +build: + CGO_ENABLED=0 go build ${LDFLAGS} -v -o target/aci-streamer . + +.PHONY: build-release +build-release: build-release-amd64 build-release-arm64 + +.PHONY: build-release-amd64 +build-release-amd64: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o=aci-streamer.linux.amd64 . && \ + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build ${LDFLAGS} -o=aci-streamer.windows.amd64.exe . && \ + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o=aci-streamer.darwin.amd64 . + +.PHONY: build-release-arm64 +build-release-arm64: + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ${LDFLAGS} -o=aci-streamer.linux.arm64 . && \ + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build ${LDFLAGS} -o=aci-streamer.darwin.arm64 . + +.PHONY: generate-html-coverage +generate-html-coverage: + go tool cover -html=cover.out -o coverage.html + @printf "Generated coverage html \n" + +.PHONY: print-coverage +print-coverage: + @go tool cover -func cover.out + +.PHONY: test-unittests +test-unittests: + go test -v -race -coverprofile cover.out ./... + +.PHONY: test +test: fmt-check vet test-unittests generate-html-coverage print-coverage + @printf "Successfully run tests \n" + +.PHONY: get-dependencies +get-dependencies: + go get -v -t -d ./... + +.PHONY: vet +vet: + @go vet ./... + @go mod tidy + +test-output: + $(shell echo $$GO_VERSION_NUMBER) + +.PHONY: fmt-fix +fmt-fix: + @go mod download golang.org/x/tools + @go run golang.org/x/tools/cmd/goimports -w -l . + +.PHONY: fmt-check +fmt-check: + @printf "Check formatting... \n" + @go mod download golang.org/x/tools + @if [[ $$( go run golang.org/x/tools/cmd/goimports -l . ) ]]; then printf "Files not properly formatted. Run 'make fmt-fix' \n"; exit 1; else printf "Check formatting finished \n"; fi From 4036738b1ea7576db62f735042ac4b0a3a9a48cd Mon Sep 17 00:00:00 2001 From: andersh Date: Fri, 1 Dec 2023 05:04:39 +0100 Subject: [PATCH 4/5] fix: format imports --- aci-connection.go | 12 +++++++----- streamer.go | 9 +++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/aci-connection.go b/aci-connection.go index fc1922b..c231402 100644 --- a/aci-connection.go +++ b/aci-connection.go @@ -19,23 +19,25 @@ import ( "crypto/tls" "crypto/x509" "fmt" + "strings" + "github.com/gorilla/websocket" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/tidwall/gjson" "github.com/tidwall/sjson" - "strings" - log4go "github.com/jeanphorn/log4go" - log "github.com/sirupsen/logrus" - "github.com/spf13/viper" - "github.com/umisama/go-regexpcache" "io/ioutil" "net/http" "net/http/cookiejar" "net/url" "os" "time" + + log4go "github.com/jeanphorn/log4go" + log "github.com/sirupsen/logrus" + "github.com/spf13/viper" + "github.com/umisama/go-regexpcache" ) // Create a Prometheus counter for number of reads on the websocket diff --git a/streamer.go b/streamer.go index 2c50b2a..f2aa2ba 100644 --- a/streamer.go +++ b/streamer.go @@ -17,16 +17,17 @@ import ( "context" "flag" "fmt" + "net/http" + "os" + "strconv" + "time" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/segmentio/ksuid" log "github.com/sirupsen/logrus" "github.com/spf13/viper" - "net/http" - "os" - "strconv" - "time" ) var version = "undefined" From 8d0c1a45376ba558b22edd33f4bf1228c9cbac58 Mon Sep 17 00:00:00 2001 From: andersh Date: Fri, 1 Dec 2023 05:13:38 +0100 Subject: [PATCH 5/5] fix: cleanup format --- streams.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streams.go b/streams.go index 11d35bd..4cb78ef 100644 --- a/streams.go +++ b/streams.go @@ -14,6 +14,7 @@ package main type Streams map[string]*Stream + type Stream struct { ClassName string `mapstructure:"class_name"` QueryParameter string `mapstructure:"query_parameter"` @@ -29,12 +30,11 @@ type ConfigLabels struct { Regex string `mapstructure:"regex"` } -/* type Timestamp struct { PropertyName string `mapstructure:"property_name"` //Regex string `mapstructure:"regex"` } -*/ + type Property struct { PropertyName string `mapstructure:"property_name"` //Regex string `mapstructure:"regex"`