Skip to content

Commit 6c48e8f

Browse files
committed
updates
- switch to golang 1.25 - update dependencies - switch from zap logging to slog - added azcli container image Signed-off-by: Markus Blaschke <[email protected]>
1 parent 9ff23ea commit 6c48e8f

File tree

17 files changed

+234
-216
lines changed

17 files changed

+234
-216
lines changed

.github/workflows/build-docker.yaml

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,16 @@ jobs:
1111
lint:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v6
1515

16-
- name: Set Swap Space
17-
uses: pierotofy/set-swap-space@49819abfb41bd9b44fb781159c033dba90353a7c
18-
with:
19-
swap-size-gb: 12
16+
- name: Setup runner
17+
uses: webdevops/setup-runner@main
2018

21-
- uses: actions/setup-go@v5
22-
with:
23-
go-version-file: 'go.mod'
24-
cache-dependency-path: "go.sum"
25-
check-latest: true
19+
- name: Setup go
20+
uses: webdevops/setup-go@main
2621

2722
- name: Run Golangci lint
28-
uses: golangci/golangci-lint-action@v7
23+
uses: golangci/golangci-lint-action@v9
2924
with:
3025
version: latest
3126
args: --print-resources-usage
@@ -41,21 +36,20 @@ jobs:
4136
target: "final-static"
4237
suffix: ""
4338
latest: "auto"
39+
- Dockerfile: Dockerfile
40+
target: "final-azcli"
41+
suffix: "-azcli"
42+
latest: false
4443

4544
runs-on: ubuntu-latest
4645
steps:
47-
- uses: actions/checkout@v4
46+
- uses: actions/checkout@v6
4847

49-
- name: Set Swap Space
50-
uses: pierotofy/set-swap-space@49819abfb41bd9b44fb781159c033dba90353a7c
51-
with:
52-
swap-size-gb: 12
48+
- name: Setup runner
49+
uses: webdevops/setup-runner@main
5350

54-
- uses: actions/setup-go@v5
55-
with:
56-
go-version-file: 'go.mod'
57-
cache-dependency-path: "go.sum"
58-
check-latest: true
51+
- name: Setup go
52+
uses: webdevops/setup-go@main
5953

6054
- name: Docker meta
6155
id: docker_meta

.github/workflows/ci-docker.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: "ci/docker"
22

33
on: [pull_request, workflow_dispatch]
44

5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.ref }}
7+
cancel-in-progress: true
8+
59
jobs:
610
build:
711
uses: ./.github/workflows/build-docker.yaml

.github/workflows/release-assets.yaml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,34 @@ on:
44
release:
55
types: [created]
66

7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: false
10+
11+
env:
12+
RELEASE_TAG: ${{ github.ref_name }}
13+
714
jobs:
8-
release:
15+
build:
16+
name: "${{ matrix.task }}"
917
runs-on: ubuntu-latest
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- task: release-assets
1023
steps:
11-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@v6
1225

13-
- name: Set Swap Space
14-
uses: pierotofy/set-swap-space@49819abfb41bd9b44fb781159c033dba90353a7c
15-
with:
16-
swap-size-gb: 12
26+
- name: Setup runner
27+
uses: webdevops/setup-runner@main
1728

18-
- uses: actions/setup-go@v5
19-
with:
20-
go-version-file: 'go.mod'
21-
cache-dependency-path: "go.sum"
22-
check-latest: true
29+
- name: Setup go
30+
uses: webdevops/setup-go@main
2331

2432
- name: Build
2533
run: |
26-
make release-assets
34+
make "${{ matrix.task }}"
2735
2836
- name: Upload assets to release
2937
uses: svenstaro/upload-release-action@v2
@@ -33,3 +41,4 @@ jobs:
3341
tag: ${{ github.ref }}
3442
overwrite: true
3543
file_glob: true
44+
promote: false

.github/workflows/release-docker.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: "release/docker"
22

33
on:
4+
workflow_dispatch: {}
45
push:
56
branches:
67
- 'main'
@@ -9,6 +10,10 @@ on:
910
tags:
1011
- '*.*.*'
1112

13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
1217
jobs:
1318
release:
1419
uses: ./.github/workflows/build-docker.yaml

.github/workflows/schedule-docker.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
schedule:
55
- cron: '45 6 * * 1'
66

7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
711
jobs:
812
schedule:
913
uses: ./.github/workflows/build-docker.yaml

Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#############################################
22
# Build
33
#############################################
4-
FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS build
4+
FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS build
55

66
RUN apk upgrade --no-cache --force
77
RUN apk add --update build-base make git
@@ -15,6 +15,7 @@ RUN go mod download
1515
# Compile
1616
COPY . .
1717
RUN make test
18+
RUN make build # warmup
1819
ARG TARGETOS TARGETARCH
1920
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build
2021

@@ -27,6 +28,16 @@ WORKDIR /app
2728
COPY --from=build /go/src/github.com/webdevops/azure-loganalytics-exporter/azure-loganalytics-exporter .
2829
RUN ["./azure-loganalytics-exporter", "--help"]
2930

31+
#############################################
32+
# final-azcli
33+
#############################################
34+
FROM mcr.microsoft.com/azure-cli AS final-azcli
35+
ENV LOG_JSON=1
36+
WORKDIR /
37+
COPY --from=test /app .
38+
USER 1000:1000
39+
ENTRYPOINT ["/azure-keyvault-exporter"]
40+
3041
#############################################
3142
# Final
3243
#############################################

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
PROJECT_NAME := $(shell basename $(CURDIR))
22
GIT_TAG := $(shell git describe --dirty --tags --always)
33
GIT_COMMIT := $(shell git rev-parse --short HEAD)
4-
LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -extldflags "-static" -s -w
4+
BUILD_DATE := $(shell TZ=UTC date '+%Y-%m-%dT%H:%M:%SZ')
5+
LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -X "main.buildDate=$(BUILD_DATE)" -extldflags "-static" -s -w
6+
BUILDFLAGS := -trimpath
57

68
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
79
GOLANGCI_LINT_BIN := $(FIRST_GOPATH)/bin/golangci-lint
@@ -25,13 +27,13 @@ vendor:
2527

2628
.PHONY: build-all
2729
build-all:
28-
GOOS=linux GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME)' .
29-
GOOS=darwin GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).darwin' .
30-
GOOS=windows GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).exe' .
30+
GOOS=linux GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' $(BUILDFLAGS) -o '$(PROJECT_NAME)' .
31+
GOOS=darwin GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' $(BUILDFLAGS) -o '$(PROJECT_NAME).darwin' .
32+
GOOS=windows GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' $(BUILDFLAGS) -o '$(PROJECT_NAME).exe' .
3133

3234
.PHONY: build
3335
build:
34-
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o $(PROJECT_NAME) .
36+
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' $(BUILDFLAGS) -o $(PROJECT_NAME) .
3537

3638
.PHONY: image
3739
image: image

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@ Usage:
1717
azure-loganalytics-exporter [OPTIONS]
1818
1919
Application Options:
20-
--log.debug debug mode [$LOG_DEBUG]
21-
--log.devel development mode [$LOG_DEVEL]
22-
--log.json Switch log output to json format [$LOG_JSON]
23-
--azure.environment= Azure environment name (default: AZUREPUBLICCLOUD) [$AZURE_ENVIRONMENT]
24-
--azure.servicediscovery.cache= Duration for caching Azure ServiceDiscovery of workspaces to reduce API calls (time.Duration)
25-
(default: 30m) [$AZURE_SERVICEDISCOVERY_CACHE]
26-
--azure.resource-tag= Azure Resource tags (space delimiter) (default: owner) [$AZURE_RESOURCE_TAG]
27-
--loganalytics.workspace= Loganalytics workspace IDs [$LOGANALYTICS_WORKSPACE]
28-
--loganalytics.concurrency= Specifies how many workspaces should be queried concurrently (default: 5) [$LOGANALYTICS_CONCURRENCY]
29-
-c, --config= Config path [$CONFIG]
30-
--server.bind= Server address (default: :8080) [$SERVER_BIND]
31-
--server.timeout.read= Server read timeout (default: 5s) [$SERVER_TIMEOUT_READ]
32-
--server.timeout.write= Server write timeout (default: 10s) [$SERVER_TIMEOUT_WRITE]
20+
--log.level=[trace|debug|info|warning|error] Log level (default: info) [$LOG_LEVEL]
21+
--log.format=[logfmt|json] Log format (default: logfmt) [$LOG_FORMAT]
22+
--log.source=[|short|file|full] Show source for every log message (useful for debugging and bug reports) [$LOG_SOURCE]
23+
--log.color=[|auto|yes|no] Enable color for logs [$LOG_COLOR]
24+
--log.time Show log time [$LOG_TIME]
25+
--azure.environment= Azure environment name (default: AZUREPUBLICCLOUD) [$AZURE_ENVIRONMENT]
26+
--azure.servicediscovery.cache= Duration for caching Azure ServiceDiscovery of workspaces to reduce API calls (time.Duration) (default: 30m) [$AZURE_SERVICEDISCOVERY_CACHE]
27+
--azure.resource-tag= Azure Resource tags (space delimiter) (default: owner) [$AZURE_RESOURCE_TAG]
28+
--loganalytics.workspace= Loganalytics workspace IDs [$LOGANALYTICS_WORKSPACE]
29+
--loganalytics.concurrency= Specifies how many workspaces should be queried concurrently (default: 5) [$LOGANALYTICS_CONCURRENCY]
30+
-c, --config= Config path [$CONFIG]
31+
--server.bind= Server address (default: :8080) [$SERVER_BIND]
32+
--server.timeout.read= Server read timeout (default: 5s) [$SERVER_TIMEOUT_READ]
33+
--server.timeout.write= Server write timeout (default: 10s) [$SERVER_TIMEOUT_WRITE]
3334
3435
Help Options:
35-
-h, --help Show this help message
36+
-h, --help Show this help message
3637
```
3738

3839
for Azure API authentication (using ENV vars) see https://docs.microsoft.com/en-us/azure/developer/go/azure-sdk-authentication

common.logger.go

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,27 @@
11
package main
22

33
import (
4-
"go.uber.org/zap"
5-
"go.uber.org/zap/zapcore"
4+
"os"
5+
6+
"github.com/webdevops/go-common/log/slogger"
67
)
78

89
var (
9-
logger *zap.SugaredLogger
10+
logger *slogger.Logger
1011
)
1112

12-
func initLogger() *zap.SugaredLogger {
13-
var config zap.Config
14-
if Opts.Logger.Development {
15-
config = zap.NewDevelopmentConfig()
16-
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
17-
} else {
18-
config = zap.NewProductionConfig()
19-
}
20-
21-
config.Encoding = "console"
22-
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
23-
24-
// debug level
25-
if Opts.Logger.Debug {
26-
config.Level = zap.NewAtomicLevelAt(zapcore.DebugLevel)
27-
}
28-
29-
// json log format
30-
if Opts.Logger.Json {
31-
config.Encoding = "json"
32-
33-
// if running in containers, logs already enriched with timestamp by the container runtime
34-
config.EncoderConfig.TimeKey = ""
35-
}
36-
37-
// build logger
38-
log, err := config.Build()
39-
if err != nil {
40-
panic(err)
13+
func initLogger() *slogger.Logger {
14+
loggerOpts := []slogger.LoggerOptionFunc{
15+
slogger.WithLevelText(Opts.Logger.Level),
16+
slogger.WithFormat(slogger.FormatMode(Opts.Logger.Format)),
17+
slogger.WithSourceMode(slogger.SourceMode(Opts.Logger.Source)),
18+
slogger.WithTime(Opts.Logger.Time),
19+
slogger.WithColor(slogger.ColorMode(Opts.Logger.Color)),
4120
}
4221

43-
logger = log.Sugar()
22+
logger = slogger.NewCliLogger(
23+
os.Stderr, loggerOpts...,
24+
)
4425

4526
return logger
4627
}

common.system.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import (
55
)
66

77
func initSystem() {
8-
system.AutoProcMemLimit(logger)
8+
system.AutoProcMemLimit(logger.Logger)
99
}

0 commit comments

Comments
 (0)