Skip to content

Commit acbb478

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 7c9ed48 commit acbb478

27 files changed

+445
-380
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-devops-exporter/azure-devops-exporter .
2829
RUN ["./azure-devops-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-devops-exporter"]
40+
3041
#############################################
3142
# Final-static
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: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,58 @@ Usage:
2424
azure-devops-exporter [OPTIONS]
2525
2626
Application Options:
27-
--log.debug debug mode [$LOG_DEBUG]
28-
--log.devel development mode [$LOG_DEVEL]
29-
--log.json Switch log output to json format [$LOG_JSON]
30-
--scrape.time= Default scrape time (time.duration) (default: 30m) [$SCRAPE_TIME]
31-
--scrape.time.projects= Scrape time for project metrics (time.duration) [$SCRAPE_TIME_PROJECTS]
32-
--scrape.time.repository= Scrape time for repository metrics (time.duration) [$SCRAPE_TIME_REPOSITORY]
33-
--scrape.time.build= Scrape time for build metrics (time.duration) [$SCRAPE_TIME_BUILD]
34-
--scrape.time.release= Scrape time for release metrics (time.duration) [$SCRAPE_TIME_RELEASE]
35-
--scrape.time.deployment= Scrape time for deployment metrics (time.duration) [$SCRAPE_TIME_DEPLOYMENT]
36-
--scrape.time.pullrequest= Scrape time for pullrequest metrics (time.duration) [$SCRAPE_TIME_PULLREQUEST]
37-
--scrape.time.stats= Scrape time for stats metrics (time.duration) [$SCRAPE_TIME_STATS]
38-
--scrape.time.resourceusage= Scrape time for resourceusage metrics (time.duration) [$SCRAPE_TIME_RESOURCEUSAGE]
39-
--scrape.time.query= Scrape time for query results (time.duration) [$SCRAPE_TIME_QUERY]
40-
--scrape.time.live= Scrape time for live metrics (time.duration) (default: 30s) [$SCRAPE_TIME_LIVE]
41-
--stats.summary.maxage= Stats Summary metrics max age (time.duration) [$STATS_SUMMARY_MAX_AGE]
42-
--azure.tenant-id= Azure tenant ID for Service Principal authentication [$AZURE_TENANT_ID]
43-
--azure.client-id= Client ID for Service Principal authentication [$AZURE_CLIENT_ID]
44-
--azure.client-secret= Client secret for Service Principal authentication [$AZURE_CLIENT_SECRET]
45-
--azuredevops.url= Azure DevOps URL (empty if hosted by Microsoft) [$AZURE_DEVOPS_URL]
46-
--azuredevops.access-token= Azure DevOps access token [$AZURE_DEVOPS_ACCESS_TOKEN]
47-
--azuredevops.access-token-file= Azure DevOps access token (from file) [$AZURE_DEVOPS_ACCESS_TOKEN_FILE]
48-
--azuredevops.organisation= Azure DevOps organization [$AZURE_DEVOPS_ORGANISATION]
49-
--azuredevops.apiversion= Azure DevOps API version (default: 5.1) [$AZURE_DEVOPS_APIVERSION]
50-
--azuredevops.agentpool= Enable scrape metrics for agent pool (IDs) [$AZURE_DEVOPS_AGENTPOOL]
51-
--whitelist.project= Filter projects (UUIDs) [$AZURE_DEVOPS_FILTER_PROJECT]
52-
--blacklist.project= Filter projects (UUIDs) [$AZURE_DEVOPS_BLACKLIST_PROJECT]
53-
--timeline.state= Filter timeline states (completed, inProgress, pending) (default: completed) [$AZURE_DEVOPS_FILTER_TIMELINE_STATE]
54-
--builds.all.project= Fetch all builds from projects (UUIDs or names) [$AZURE_DEVOPS_FETCH_ALL_BUILDS_FILTER_PROJECT]
55-
--list.query= Pairs of query and project UUIDs in the form: '<queryId>@<projectId>' [$AZURE_DEVOPS_QUERIES]
56-
--tags.schema= Tags to be extracted from builds in the format 'tagName:type' with following types: number, info, bool [$AZURE_DEVOPS_TAG_SCHEMA]
57-
--tags.build.definition= Build definition ids to query tags (IDs) [$AZURE_DEVOPS_TAG_BUILD_DEFINITION]
58-
--cache.path= Cache path (to folder, file://path... or azblob://storageaccount.blob.core.windows.net/containername or
59-
k8scm://{namespace}/{configmap}}) [$CACHE_PATH]
60-
--request.concurrency= Number of concurrent requests against dev.azure.com (default: 10) [$REQUEST_CONCURRENCY]
61-
--request.retries= Number of retried requests against dev.azure.com (default: 3) [$REQUEST_RETRIES]
62-
--servicediscovery.refresh= Refresh duration for servicediscovery (time.duration) (default: 30m) [$SERVICEDISCOVERY_REFRESH]
63-
--limit.project= Limit number of projects (default: 100) [$LIMIT_PROJECT]
64-
--limit.builds-per-project= Limit builds per project (default: 100) [$LIMIT_BUILDS_PER_PROJECT]
65-
--limit.builds-per-definition= Limit builds per definition (default: 10) [$LIMIT_BUILDS_PER_DEFINITION]
66-
--limit.releases-per-project= Limit releases per project (default: 100) [$LIMIT_RELEASES_PER_PROJECT]
67-
--limit.releases-per-definition= Limit releases per definition (default: 100) [$LIMIT_RELEASES_PER_DEFINITION]
68-
--limit.deployments-per-definition= Limit deployments per definition (default: 100) [$LIMIT_DEPLOYMENTS_PER_DEFINITION]
69-
--limit.releasedefinitions-per-project= Limit builds per definition (default: 100) [$LIMIT_RELEASEDEFINITION_PER_PROJECT]
70-
--limit.build-history-duration= Time (time.Duration) how long the exporter should look back for builds (default: 48h) [$LIMIT_BUILD_HISTORY_DURATION]
71-
--limit.release-history-duration= Time (time.Duration) how long the exporter should look back for releases (default: 48h) [$LIMIT_RELEASE_HISTORY_DURATION]
72-
--server.bind= Server address (default: :8080) [$SERVER_BIND]
73-
--server.timeout.read= Server read timeout (default: 5s) [$SERVER_TIMEOUT_READ]
74-
--server.timeout.write= Server write timeout (default: 10s) [$SERVER_TIMEOUT_WRITE]
27+
--log.level=[trace|debug|info|warning|error] Log level (default: info) [$LOG_LEVEL]
28+
--log.format=[logfmt|json] Log format (default: logfmt) [$LOG_FORMAT]
29+
--log.source=[|short|file|full] Show source for every log message (useful for debugging and bug reports) [$LOG_SOURCE]
30+
--log.color=[|auto|yes|no] Enable color for logs [$LOG_COLOR]
31+
--log.time Show log time [$LOG_TIME]
32+
--scrape.time= Default scrape time (time.duration) (default: 30m) [$SCRAPE_TIME]
33+
--scrape.time.projects= Scrape time for project metrics (time.duration) [$SCRAPE_TIME_PROJECTS]
34+
--scrape.time.repository= Scrape time for repository metrics (time.duration) [$SCRAPE_TIME_REPOSITORY]
35+
--scrape.time.build= Scrape time for build metrics (time.duration) [$SCRAPE_TIME_BUILD]
36+
--scrape.time.release= Scrape time for release metrics (time.duration) [$SCRAPE_TIME_RELEASE]
37+
--scrape.time.deployment= Scrape time for deployment metrics (time.duration) [$SCRAPE_TIME_DEPLOYMENT]
38+
--scrape.time.pullrequest= Scrape time for pullrequest metrics (time.duration) [$SCRAPE_TIME_PULLREQUEST]
39+
--scrape.time.stats= Scrape time for stats metrics (time.duration) [$SCRAPE_TIME_STATS]
40+
--scrape.time.resourceusage= Scrape time for resourceusage metrics (time.duration) [$SCRAPE_TIME_RESOURCEUSAGE]
41+
--scrape.time.query= Scrape time for query results (time.duration) [$SCRAPE_TIME_QUERY]
42+
--scrape.time.live= Scrape time for live metrics (time.duration) (default: 30s) [$SCRAPE_TIME_LIVE]
43+
--stats.summary.maxage= Stats Summary metrics max age (time.duration) [$STATS_SUMMARY_MAX_AGE]
44+
--azure.tenant-id= Azure tenant ID for Service Principal authentication [$AZURE_TENANT_ID]
45+
--azure.client-id= Client ID for Service Principal authentication [$AZURE_CLIENT_ID]
46+
--azure.client-secret= Client secret for Service Principal authentication [$AZURE_CLIENT_SECRET]
47+
--azuredevops.url= Azure DevOps URL (empty if hosted by Microsoft) [$AZURE_DEVOPS_URL]
48+
--azuredevops.access-token= Azure DevOps access token [$AZURE_DEVOPS_ACCESS_TOKEN]
49+
--azuredevops.access-token-file= Azure DevOps access token (from file) [$AZURE_DEVOPS_ACCESS_TOKEN_FILE]
50+
--azuredevops.organisation= Azure DevOps organization [$AZURE_DEVOPS_ORGANISATION]
51+
--azuredevops.apiversion= Azure DevOps API version (default: 5.1) [$AZURE_DEVOPS_APIVERSION]
52+
--azuredevops.agentpool= Enable scrape metrics for agent pool (IDs) [$AZURE_DEVOPS_AGENTPOOL]
53+
--whitelist.project= Filter projects (UUIDs) [$AZURE_DEVOPS_FILTER_PROJECT]
54+
--blacklist.project= Filter projects (UUIDs) [$AZURE_DEVOPS_BLACKLIST_PROJECT]
55+
--timeline.state= Filter timeline states (completed, inProgress, pending) (default: completed) [$AZURE_DEVOPS_FILTER_TIMELINE_STATE]
56+
--builds.all.project= Fetch all builds from projects (UUIDs or names) [$AZURE_DEVOPS_FETCH_ALL_BUILDS_FILTER_PROJECT]
57+
--list.query= Pairs of query and project UUIDs in the form: '<queryId>@<projectId>' [$AZURE_DEVOPS_QUERIES]
58+
--tags.schema= Tags to be extracted from builds in the format 'tagName:type' with following types: number, info, bool [$AZURE_DEVOPS_TAG_SCHEMA]
59+
--tags.build.definition= Build definition ids to query tags (IDs) [$AZURE_DEVOPS_TAG_BUILD_DEFINITION]
60+
--cache.path= Cache path (to folder, file://path... or azblob://storageaccount.blob.core.windows.net/containername or k8scm://{namespace}/{configmap}}) [$CACHE_PATH]
61+
--request.concurrency= Number of concurrent requests against dev.azure.com (default: 10) [$REQUEST_CONCURRENCY]
62+
--request.retries= Number of retried requests against dev.azure.com (default: 3) [$REQUEST_RETRIES]
63+
--servicediscovery.refresh= Refresh duration for servicediscovery (time.duration) (default: 30m) [$SERVICEDISCOVERY_REFRESH]
64+
--limit.project= Limit number of projects (default: 100) [$LIMIT_PROJECT]
65+
--limit.builds-per-project= Limit builds per project (default: 100) [$LIMIT_BUILDS_PER_PROJECT]
66+
--limit.builds-per-definition= Limit builds per definition (default: 10) [$LIMIT_BUILDS_PER_DEFINITION]
67+
--limit.releases-per-project= Limit releases per project (default: 100) [$LIMIT_RELEASES_PER_PROJECT]
68+
--limit.releases-per-definition= Limit releases per definition (default: 100) [$LIMIT_RELEASES_PER_DEFINITION]
69+
--limit.deployments-per-definition= Limit deployments per definition (default: 100) [$LIMIT_DEPLOYMENTS_PER_DEFINITION]
70+
--limit.releasedefinitions-per-project= Limit builds per definition (default: 100) [$LIMIT_RELEASEDEFINITION_PER_PROJECT]
71+
--limit.build-history-duration= Time (time.Duration) how long the exporter should look back for builds (default: 48h) [$LIMIT_BUILD_HISTORY_DURATION]
72+
--limit.release-history-duration= Time (time.Duration) how long the exporter should look back for releases (default: 48h) [$LIMIT_RELEASE_HISTORY_DURATION]
73+
--server.bind= Server address (default: :8080) [$SERVER_BIND]
74+
--server.timeout.read= Server read timeout (default: 5s) [$SERVER_TIMEOUT_READ]
75+
--server.timeout.write= Server write timeout (default: 10s) [$SERVER_TIMEOUT_WRITE]
7576
7677
Help Options:
77-
-h, --help Show this help message
78+
-h, --help Show this help message
7879
```
7980

8081
Authentication

azure-devops-client/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import (
1414
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
1515
resty "github.com/go-resty/resty/v2"
1616
"github.com/prometheus/client_golang/prometheus"
17-
"go.uber.org/zap"
17+
"github.com/webdevops/go-common/log/slogger"
1818
)
1919

2020
const (
2121
AZURE_DEVOPS_SCOPE = "499b84ac-1321-427f-aa17-267ca6975798/.default"
2222
)
2323

2424
type AzureDevopsClient struct {
25-
logger *zap.SugaredLogger
25+
logger *slogger.Logger
2626

2727
// RequestCount has to be the first words
2828
// in order to be 64-aligned on 32-bit architectures.
@@ -75,7 +75,7 @@ type EntraIdErrorResponse struct {
7575
ErrorDescription *string `json:"error_description"`
7676
}
7777

78-
func NewAzureDevopsClient(logger *zap.SugaredLogger) *AzureDevopsClient {
78+
func NewAzureDevopsClient(logger *slogger.Logger) *AzureDevopsClient {
7979
c := AzureDevopsClient{
8080
logger: logger,
8181
}

0 commit comments

Comments
 (0)