Skip to content

Commit f897934

Browse files
committed
Merge tag '0.18.1' into merge-to-0.18.1
2 parents e4e66ea + 6e73ff7 commit f897934

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+7190
-835
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: Questions and Answers
4+
url: https://github.com/burningalchemist/sql_exporter/discussions
5+
about: Please ask your questions on installation and usage here.

.github/workflows/build.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ on:
1010

1111
jobs:
1212
build:
13+
if: ${{ !startsWith(github.event.head_commit.message, 'docs:') }}
1314
name: Build
1415
runs-on: ubuntu-latest
1516
steps:
1617
- name: Set up Go 1.x
17-
uses: actions/setup-go@v2
18+
uses: actions/setup-go@v5
1819
with:
19-
go-version: ^1.18
20+
go-version: ^1.24
21+
check-latest: true
2022
id: go
2123
- name: Check out code into the Go module directory
22-
uses: actions/checkout@v2
24+
uses: actions/checkout@v4
2325
- name: Style
2426
run: make style
2527
- name: Vet

.github/workflows/codeql-analysis.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111

1212
jobs:
1313
analyze:
14+
if: |
15+
${{ !startsWith(github.event.head_commit.message, 'docs:') }} ||
16+
${{ !startsWith(github.event.head_commit.message, 'build:') }}
1417
name: Analyze
1518
runs-on: ubuntu-latest
1619

@@ -25,27 +28,27 @@ jobs:
2528

2629
steps:
2730
- name: Checkout repository
28-
uses: actions/checkout@v2
31+
uses: actions/checkout@v4
2932
with:
3033
# We must fetch at least the immediate parents so that if this is
3134
# a pull request then we can checkout the head.
3235
fetch-depth: 2
3336

3437
- name: Set up Go
35-
uses: actions/setup-go@v2
38+
uses: actions/setup-go@v5
3639
with:
37-
go-version: ^1.18
40+
go-version: ^1.20
3841

3942
# Initializes the CodeQL tools for scanning.
4043
- name: Initialize CodeQL
41-
uses: github/codeql-action/init@v2
44+
uses: github/codeql-action/init@v3
4245
with:
4346
languages: ${{ matrix.language }}
4447

4548
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
4649
# If this step fails, then you should remove it and run the build manually (see below)
4750
- name: Autobuild
48-
uses: github/codeql-action/autobuild@v2
51+
uses: github/codeql-action/autobuild@v3
4952

5053
# ℹ️ Command-line programs to run using the OS shell.
5154
# 📚 https://git.io/JvXDl
@@ -59,4 +62,4 @@ jobs:
5962
# make release
6063

6164
- name: Perform CodeQL Analysis
62-
uses: github/codeql-action/analyze@v2
65+
uses: github/codeql-action/analyze@v3
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Helm
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
env:
10+
HELM_VERSION: 3.12.1
11+
PYTHON_VERSION: 3.9
12+
TARGET_BRANCH: chart-testing-target-branch
13+
TARGET_REMOTE: test
14+
jobs:
15+
helm-jobs:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- name: Set up Helm
23+
uses: azure/setup-helm@v4
24+
with:
25+
version: "v${{ env.HELM_VERSION }}"
26+
- uses: actions/setup-python@v5
27+
with:
28+
python-version: ${{ env.PYTHON_VERSION }}
29+
check-latest: true
30+
# ---------------------------------------------------------------
31+
# -- Instead of comparing to the master branch, I'm getting
32+
# -- the commit hash set in the previous step from a
33+
# -- currently released chart. If it doesn't exists, then
34+
# -- I assume that chart is not released and compare to the
35+
# -- previous commit
36+
# --
37+
# -- Also, I'm setting the RepoURL here. Since we plan to support
38+
# -- the official chart in this git repository, the helm
39+
# -- repository is expected to belong to this repo as well.
40+
# ---------------------------------------------------------------
41+
- name: Retrieve the latest commit sha from the helm chart
42+
run: |
43+
HELM_REPO_URL="https://${GITHUB_REPOSITORY_OWNER}.github.io/${GITHUB_REPOSITORY#*/}"
44+
if helm repo add sql-exporter $HELM_REPO_URL
45+
then
46+
helm repo update
47+
echo "TARGET_COMMIT=$(helm show chart sql-exporter/sql-exporter | yq '.annotations.git/commit-sha')" >> "${GITHUB_ENV}"
48+
else
49+
echo "TARGET_COMMIT=$(git show HEAD^1 --pretty=format:%H --no-patch)" >> "${GITHUB_ENV}"
50+
fi
51+
# ---------------------------------------------------------------
52+
# -- As I could find CT doesn't support testing against commits
53+
# -- directly, so I'm creating a new fake remote from a commit
54+
# -- and testing the chart against it. This workaround doesn't
55+
# -- support maintainers validation, but we have it disabled
56+
# -- anyway
57+
# ---------------------------------------------------------------
58+
- name: Prepare a dummy remote to test the chart
59+
run: |
60+
DUMMY_REMOTE=$(mktemp -d)
61+
git init "${DUMMY_REMOTE}"
62+
git remote add "${TARGET_REMOTE}" "${DUMMY_REMOTE}"
63+
git checkout -b "${TARGET_BRANCH}" "${TARGET_COMMIT}"
64+
git push --set-upstream "${TARGET_REMOTE}" "${TARGET_BRANCH}"
65+
git checkout "${GITHUB_SHA}"
66+
- name: Set up chart-testing
67+
uses: helm/chart-testing-action@v2.6.0
68+
- name: Run chart-testing (list-changed)
69+
id: list-changed
70+
run: |
71+
changed=$(ct list-changed --chart-dirs . --target-branch "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}")
72+
if [[ -n "$changed" ]]; then
73+
echo "changed=true" >> "$GITHUB_OUTPUT"
74+
fi
75+
- name: Run chart-testing (lint)
76+
if: steps.list-changed.outputs.changed == 'true'
77+
run: ct lint --target-branch "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}" --validate-maintainers=false --chart-dirs .
78+
- name: Setup helmfile
79+
if: steps.list-changed.outputs.changed == 'true'
80+
uses: mamezou-tech/setup-helmfile@v2.0.0
81+
- name: Create kind cluster
82+
if: steps.list-changed.outputs.changed == 'true'
83+
uses: helm/kind-action@v1.9.0
84+
- name: Init postgres server
85+
if: steps.list-changed.outputs.changed == 'true'
86+
run: |
87+
helmfile -f helm/ci/helmfile.yaml sync
88+
- name: Run chart-testing (install)
89+
if: steps.list-changed.outputs.changed == 'true'
90+
run: ct install --target-branch "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}" --chart-dirs .
91+
- name: Run chart-testing (upgrade)
92+
if: steps.list-changed.outputs.changed == 'true'
93+
run: ct install --target-branch "${TARGET_BRANCH}" --remote "${TARGET_REMOTE}" --chart-dirs . --upgrade
94+
- name: Configure Git
95+
run: |
96+
git config user.name "$GITHUB_ACTOR"
97+
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
98+
# ---------------------------------------------------------------
99+
# -- On each run we're setting an annotation with the current
100+
# -- commit hash, so in case it's released, we will see it
101+
# -- running `$ helm show sql-exporter/sql-exporter`
102+
# ---------------------------------------------------------------
103+
- name: Set the git sha annotations in the helm chart
104+
run: yq -i ".annotations.git/commit-sha = \"${GITHUB_SHA}\"" ./helm/Chart.yaml
105+
106+
- name: Release charts
107+
if: ${{ github.event.repository.default_branch && github.event_name == 'push' }}
108+
uses: helm/chart-releaser-action@main
109+
with:
110+
charts_dir: .
111+
mark_as_latest: false
112+
packages_with_index: true
113+
env:
114+
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
115+
CR_RELEASE_NAME_TEMPLATE: "chart-{{ .Name }}-{{ .Version }}"

.github/workflows/release.yml

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ jobs:
1414
VERSION: ${{ github.ref_name }}
1515
steps:
1616
- name: Set up Go 1.x
17-
uses: actions/setup-go@v2
17+
uses: actions/setup-go@v5
1818
with:
19-
go-version: ^1.18
19+
go-version: ^1.24
20+
check-latest: true
2021
- name: Check out code into the Go module directory
21-
uses: actions/checkout@v2
22+
uses: actions/checkout@v4
2223

2324
- name: Promu - Crossbuild
2425
run: make crossbuild
@@ -43,7 +44,52 @@ jobs:
4344
run: make crossbuild-checksum
4445

4546
- name: Upload artifacts
46-
uses: softprops/action-gh-release@v1
47+
uses: softprops/action-gh-release@v2.2.2
4748
with:
4849
files: |
4950
.tarballs/*
51+
docker:
52+
name: Push Docker image to Docker Hub
53+
runs-on: ubuntu-latest
54+
needs: build
55+
steps:
56+
- name: Check out the repo
57+
uses: actions/checkout@v4
58+
59+
- name: Get Go version from the '.promu.yml' config
60+
id: promu-go-version
61+
run: printf "version=%s" "$(yq '.go.version' .promu.yml)" >> $GITHUB_OUTPUT
62+
63+
- name: Set up QEMU
64+
uses: docker/setup-qemu-action@v3
65+
66+
- name: Set up Docker Buildx
67+
uses: docker/setup-buildx-action@v3
68+
69+
- name: Log in to Docker Hub
70+
uses: docker/login-action@v3
71+
with:
72+
username: ${{ secrets.DOCKER_USERNAME }}
73+
password: ${{ secrets.DOCKER_TOKEN }}
74+
75+
- name: Extract metadata (tags, labels) for Docker
76+
id: meta
77+
uses: docker/metadata-action@v5
78+
with:
79+
images: burningalchemist/sql_exporter
80+
tags: |
81+
type=semver,pattern={{version}}
82+
type=semver,pattern={{major}}.{{minor}}
83+
84+
- name: Build and push Docker image
85+
uses: docker/build-push-action@v5
86+
with:
87+
context: .
88+
file: Dockerfile.multi-arch
89+
push: true
90+
tags: ${{ steps.meta.outputs.tags }}
91+
labels: ${{ steps.meta.outputs.labels }}
92+
platforms: linux/amd64,linux/arm64
93+
provenance: false
94+
build-args: |
95+
GOVERSION=${{ steps.promu-go-version.outputs.version }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/.project
22
/.settings
33
.idea/
4+
/.vscode
45
/sql_exporter
56
/sql_exporter.yml
67
test_configs/
8+
.idea/*

.promu.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
go:
22
cgo: false
3-
version: 1.19
3+
version: 1.24
44
repository:
55
path: github.com/burningalchemist/sql_exporter
66
build:
@@ -14,6 +14,8 @@ build:
1414
-X github.com/prometheus/common/version.Branch={{.Branch}}
1515
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
1616
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
17+
-s
18+
-w
1719
tarball:
1820
files:
1921
- LICENSE
@@ -27,3 +29,4 @@ crossbuild:
2729
- windows/amd64
2830
- linux/armv7
2931
- linux/arm64
32+
- darwin/arm64

Dockerfile.multi-arch

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARG GOVERSION=latest
2+
3+
FROM --platform=$BUILDPLATFORM quay.io/prometheus/golang-builder:${GOVERSION}-main AS builder
4+
5+
# Get sql_exporter
6+
ADD . /go/src/github.com/burningalchemist/sql_exporter
7+
WORKDIR /go/src/github.com/burningalchemist/sql_exporter
8+
9+
# Do makefile
10+
ARG TARGETOS
11+
ARG TARGETARCH
12+
13+
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make
14+
15+
# Make image and copy build sql_exporter
16+
FROM --platform=$TARGETPLATFORM quay.io/prometheus/busybox:latest
17+
LABEL maintainer="The Prometheus Authors <prometheus-developers@googlegroups.com>"
18+
COPY --from=builder /go/src/github.com/burningalchemist/sql_exporter/sql_exporter /bin/sql_exporter
19+
20+
EXPOSE 9399
21+
USER nobody
22+
ENTRYPOINT [ "/bin/sql_exporter" ]

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MIT License
22

3+
Copyright (c) 2020 Sergei Zyubin
34
Copyright (c) 2017 Alin Sinpalean
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy

Makefile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
# To distinguish between native Windows and Windows Subsystem for Linux (WSL),
15+
# we have to check how PATH is separated. For WSL and Unix-based systems it's
16+
# a colon; for native Windows it's a semicolon.
17+
ifeq '$(findstring ;,$(PATH))' ';'
18+
GOPATH = $(firstword $(subst ;, ,$(shell $(GO) env GOPATH)))
19+
PREFIX = $(shell cd)
20+
endif
21+
1422
GO := go
15-
GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
23+
GOPATH ?= $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
1624
PROMU := $(GOPATH)/bin/promu
25+
PROMU_VERSION := v0.17.0
1726
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
1827

1928
PREFIX ?= $(shell pwd)
@@ -30,7 +39,7 @@ style:
3039

3140
test:
3241
@echo ">> running tests"
33-
@$(GO) test -short -race $(pkgs)
42+
@$(GO) test -short $(pkgs)
3443

3544
format:
3645
@echo ">> formatting code"
@@ -73,10 +82,17 @@ docker:
7382
@echo ">> building docker image"
7483
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
7584

85+
# Override for native Windows, where the path separator is a semicolon.
86+
ifeq '$(findstring ;,$(PATH))' ';'
87+
promu:
88+
@set GOOS=windows
89+
@set GOARCH=$(subst AMD64,amd64,$(patsubst i%86,386,$(shell echo %PROCESSOR_ARCHITECTURE%)))
90+
@$(GO) install github.com/prometheus/promu@$(PROMU_VERSION)
91+
else
7692
promu:
7793
@GOOS=$(shell uname -s | tr A-Z a-z) \
7894
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
79-
$(GO) install github.com/prometheus/promu@v0.13.0
80-
95+
$(GO) install github.com/prometheus/promu@$(PROMU_VERSION)
96+
endif
8197

8298
.PHONY: all style format build test vet tarball docker promu

0 commit comments

Comments
 (0)