forked from kuskoman/logstash-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
487 lines (407 loc) · 14.3 KB
/
go-application.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
name: Go application CI/CD
on:
push:
branches:
- master
- v1
tags:
- "*"
pull_request:
branches:
- master
- v1
env:
TAG_NAME: "${GITHUB_REF##*/}"
jobs:
lint:
name: Lint code
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Lint code using golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
- name: Check go mod tidy
run: |
go mod tidy
git diff --exit-code -- go.mod go.sum
lint-scripts:
name: Lint scripts
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run ShellCheck
uses: ludeeus/[email protected]
test:
name: Unit test code
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Test code
run: go test ./... -covermode=atomic -coverprofile=coverage.out
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
verify-helm-readme:
name: Verify that Helm README is up to date
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Node 18
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install README generator
run: make install-helm-readme
- name: Generate README
run: make helm-readme
- name: Verify that there are no changes
run: git diff --exit-code || (echo "README.md is not up to date. Please use helm-readme and commit the changes." && exit 1)
verify-makefile-readme:
name: Verify that Makefile section of README is up to date
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Generate README
run: make update-readme-descriptions
- name: Verify that there are no changes
run: git diff --exit-code || (echo "README.md is not up to date. Please use update-readme-descriptions and commit the changes." && exit 1)
lint-helm-chart:
name: Lint Helm chart
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Helm
uses: azure/setup-helm@v4
with:
version: 3.13.3
- name: Lint Helm chart
working-directory: ./chart
run: helm lint .
template-helm-chart:
name: Verify templating chart with default values
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Helm
uses: azure/setup-helm@v4
with:
version: 3.11.2
- name: Template Helm chart
working-directory: ./chart
run: helm template . > /dev/null
test-integration:
name: Test integration with Prometheus
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Compose
uses: ndeloof/[email protected]
with:
version: v2.15.1
legacy: true
- name: Print compose version
run: docker-compose version
- name: Wait for compose
run: make wait-for-compose
- name: Print compose logs if failed
run: docker-compose logs
if: failure()
- name: Print exporter logs if failed
run: docker-compose logs exporter
if: failure()
- name: Run metrics integration test
run: make verify-metrics
- name: Generate metric names for README
run: ./scripts/add_metrics_to_readme.sh
- name: Verify that there are no changes
run: git diff --exit-code || echo "README.md is not up to date. Please use add_metrics_to_readme.sh and commit the changes."
- name: Shutdown compose
run: docker-compose down -v
build-linux:
name: Build Linux binary
runs-on: ubuntu-20.04
needs: [lint, test]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Build Linux binary
run: make build-linux
env:
VERSION: ${{ github.ref }}
- name: Upload Linux binary
uses: actions/upload-artifact@v4
with:
name: logstash-exporter-linux
path: out/main-linux
build-linux-arm:
name: Build Linux ARM binary
runs-on: ubuntu-20.04
needs: [lint, test]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Build Linux ARM binary
run: make build-linux-arm
env:
VERSION: ${{ github.ref }}
- name: Upload Linux ARM binary
uses: actions/upload-artifact@v4
with:
name: logstash-exporter-linux-arm
path: out/main-linux-arm
build-darwin:
name: Build Mac binary
runs-on: ubuntu-20.04
needs: [lint, test]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Build Mac binary
run: make build-darwin
env:
VERSION: ${{ github.ref }}
- name: Upload Mac binary
uses: actions/upload-artifact@v4
with:
name: logstash-exporter-darwin
path: out/main-darwin
build-windows:
name: Build Windows binary
runs-on: ubuntu-20.04
needs: [lint, test]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: "^1.23"
- name: Build Windows binary
run: make build-windows
env:
VERSION: ${{ github.ref }}
- name: Upload Windows binary
uses: actions/upload-artifact@v4
with:
name: logstash-exporter-windows
path: out/main-windows
build-linux-docker-image:
name: Build Linux Docker image
runs-on: ubuntu-20.04
needs: [build-linux]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build Docker image
run: make build-docker
- name: Package Docker image
run: docker save logstash-exporter:latest | gzip > logstash-exporter.tar.gz
- name: Upload Docker image as an artifact
uses: actions/upload-artifact@v4
with:
name: logstash-exporter-docker-image
path: logstash-exporter.tar.gz
retention-days: 1
- name: Login to GitHub registry
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master'
run: echo ${{ secrets.GH_PAT }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
- name: Login to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ secrets.DOCKER_HUB_PAT }} | docker login -u ${{ github.repository_owner }} --password-stdin
- name: Tag Docker image with master
if: github.ref == 'refs/heads/master'
run: docker tag logstash-exporter:latest ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:master
- name: Tag Docker image with tag to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: docker tag logstash-exporter:latest ${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
- name: Tag Docker image with tag to ghcr.io
if: startsWith(github.ref, 'refs/tags/')
run: docker tag logstash-exporter:latest ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
- name: Push Docker image to GitHub registry
if: github.ref == 'refs/heads/master'
run: docker push ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:master
- name: Push Docker image with tag to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: docker push ${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
- name: Push Docker image with tag to ghcr.io
if: startsWith(github.ref, 'refs/tags/')
run: docker push ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
build-docker-linux-arm-image:
name: Build Linux ARM Docker image
runs-on: ubuntu-20.04
needs: [build-linux]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ secrets.DOCKER_HUB_PAT }} | docker login -u ${{ github.repository_owner }} --password-stdin
- name: Build Docker image
run: "VERSION=${{ env.TAG_NAME }} DOCKER_IMG=${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }} make build-docker-multi"
test-helm-integration:
name: Test integration with Helm chart
runs-on: ubuntu-20.04
needs:
- verify-helm-readme
- lint-helm-chart
- template-helm-chart
- build-linux-docker-image
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Docker image
uses: actions/download-artifact@v4
with:
name: logstash-exporter-docker-image
path: .helm/files
- name: Load Docker image
run: docker load -i .helm/files/logstash-exporter.tar.gz
- name: Install Helm
uses: azure/setup-helm@v4
with:
version: 3.13.3
- name: Include current chart versions
working-directory: .helm/logstash-integration-test-chart
run: helm dependency update
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
cluster_name: kind-chart-testing
- name: Export Docker image to Kind cluster
run: kind load docker-image logstash-exporter:latest --name kind-chart-testing
- name: Template Helm chart
working-directory: .helm/logstash-integration-test-chart
run: helm template .
- name: Install Helm chart
working-directory: .helm/logstash-integration-test-chart
run: helm install --wait --timeout 10m --debug logstash-integration-test-chart .
- name: Print exporter logs
run: kubectl logs -n default -l app=logstash-exporter
if: failure()
create-release:
name: Create GitHub release
runs-on: ubuntu-20.04
permissions:
contents: write
packages: write
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
release_id: ${{ steps.create_release.outputs.id }}
needs:
- build-linux
- build-darwin
- build-windows
- build-linux-arm
- build-linux-docker-image
- build-docker-linux-arm-image
- test-integration
- lint-scripts
- verify-makefile-readme
- test-helm-integration
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Output tag information
run: |
echo "Tag name: ${{ env.TAG_NAME }}"
echo "Tag ref: ${{ github.ref }}"
- name: Generate release notes
run: ./scripts/create_release_notes.sh
- name: Determine if prerelease
id: prerelease
run: |
# if tag name does not start with v, or when the tag name contains -suffix, then it is a prerelease
if [[ "${{ env.TAG_NAME }}" =~ ^v.*$ ]] && [[ "${{ env.TAG_NAME }}" =~ -.*$ ]]; then
echo "::set-output name=is_prerelease::true"
else
echo "::set-output name=is_prerelease::false"
fi
- name: Create GitHub release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body_path: "./release_notes.txt"
draft: false
prerelease: ${{ steps.prerelease.outputs.is_prerelease }}
upload-binaries:
strategy:
matrix:
binary: [linux, darwin, windows, linux-arm]
runs-on: ubuntu-20.04
needs:
- create-release
- build-linux
- build-darwin
- build-windows
- build-linux-arm
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download binary
uses: actions/download-artifact@v4
with:
name: logstash-exporter-${{ matrix.binary }}
- name: Generate sha256 checksum
run: |
CHECKSUM_FILE="main-${{ matrix.binary }}.sha256"
sha256sum main-${{ matrix.binary }} | cut -d ' ' -f1 | tr -d $'\n' > "$CHECKSUM_FILE"
echo -n ' logstash-exporter-${{ matrix.binary }}' >> "$CHECKSUM_FILE"
- name: Upload binary to GitHub release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: main-${{ matrix.binary }}
asset_name: logstash-exporter-${{ matrix.binary }}
asset_content_type: application/octet-stream
- name: Upload sha256 checksum to GitHub release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: main-${{ matrix.binary }}.sha256
asset_name: logstash-exporter-${{ matrix.binary }}.sha256
asset_content_type: text/plain