Skip to content

Commit 4bc3ff3

Browse files
authored
(feat) Improved project CI (#11)
* Rename project name references * Switch Docker registry to a new one * Remove goreleaser format deprecation * Improved CI tests, some refactoring
1 parent 6a0269d commit 4bc3ff3

File tree

7 files changed

+40
-34
lines changed

7 files changed

+40
-34
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ jobs:
5353
context: .
5454
file: Dockerfile.release
5555
push: true
56-
tags: mgsousa/prom-exporter:latest,mgsousa/prom-exporter:${{ steps.prepare.outputs.tag_name }}
56+
tags: mgsousa/json-stats-exporter:${{ steps.prepare.outputs.tag_name }},mgsousa/json-stats-exporter:latest

.github/workflows/test.yml

+16-14
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212

13+
services:
14+
http-service:
15+
image: hashicorp/http-echo:latest
16+
env:
17+
ECHO_TEXT: '{"stats":{"events":{"active":0,"added":0,"done":0},"harvester":{"closed":0,"open_files":0,"running":0,"skipped":0,"started":0},"input":{"log":{"files":{"renamed":0,"truncated":0}}}},"processor":{"rate_limit":{"1":{"dropped":0}}},"writes":{"fail":0,"success":0,"total":0},"system":{"cpu":{"cores":4},"load":{"1":0.45,"15":0.21,"5":0.26,"norm":{"1":0.105,"15":0.05,"5":0.065}}}}'
18+
ports:
19+
- 5678:5678
20+
1321
steps:
1422
- name: Checkout
1523
uses: actions/checkout@v4
1624
with:
1725
fetch-depth: 0
1826

19-
- name: Set up Go
20-
uses: actions/setup-go@master
21-
with:
22-
go-version: 1.21.x
23-
2427
- name: Set up Docker Buildx
2528
uses: docker/setup-buildx-action@v3
2629

@@ -30,14 +33,13 @@ jobs:
3033
with:
3134
context: .
3235
load: true
33-
tags: prom-exporter:test
36+
tags: json-stats-exporter:test
3437

35-
- name: Test Execution
38+
- name: Run Service
3639
run: |
37-
timeout 10s docker run --rm prom-exporter:test \
38-
-listen-address ":9201" \
39-
-service-name "test" -service-uri "test" -service-port "5066" -service-metrics-path "stats" || code=$?
40-
if [[ $code -ne 124 ]]; then
41-
echo "Exporter stopped with ${code}. It was expected to run forever."
42-
exit 1;
43-
fi
40+
docker run --net=host --rm json-stats-exporter:test \
41+
-listen-address ":9201" -service-name "test" \
42+
-service-uri "localhost" -service-port "5678" &
43+
44+
sleep 10
45+
curl -sS --fail-with-body --retry 5 localhost:9201/metrics

.goreleaser.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
project_name: prom-exporter
1+
version: 2
2+
project_name: json-stats-exporter
23

34
builds:
45
- env:
@@ -13,7 +14,7 @@ builds:
1314
ldflags:
1415
- -s -w
1516
archives:
16-
- format: binary
17+
- formats: binary
1718
checksum:
1819
disable: true
1920
snapshot:

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ FROM scratch
1414

1515
WORKDIR /app
1616

17-
COPY --from=build /app/dist/prom-exporter_linux_amd64_v1/* ./prom-exporter
17+
COPY --from=build /app/dist/json-stats-exporter_linux_amd64_v1/* ./json-stats-exporter
1818

19-
ENTRYPOINT [ "./prom-exporter" ]
19+
ENTRYPOINT [ "./json-stats-exporter" ]

Dockerfile.release

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ FROM scratch
22

33
WORKDIR /app
44

5-
COPY ./dist/prom-exporter_linux_amd64_v1/prom-exporter ./
5+
COPY ./dist/json-stats-exporter_linux_amd64_v1/json-stats-exporter ./
66

7-
ENTRYPOINT [ "./prom-exporter" ]
7+
ENTRYPOINT [ "./json-stats-exporter" ]

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
BINARY = prom-exporter
1+
BINARY = json-stats-exporter
22
ACT_URL = https://raw.githubusercontent.com/nektos/act/master/install.sh
33

44
ACT := $(shell command -v act)
@@ -8,14 +8,17 @@ ACT := $(shell command -v act)
88
test: test_sec test_ci
99

1010
act:
11-
@[ ! -x "$(ACT)" ] && (curl --proto '=https' --tlsv1.2 -sSf $(ACT_URL) | sudo bash && sudo install ./bin/act /usr/local/bin/) || true
11+
@curl --proto '=https' --tlsv1.2 -sSf $(ACT_URL) | bash
1212

1313
test_ci: act
1414
@act push --rm -j "test"
1515

1616
test_sec: act
1717
@act push --rm -j "security"
1818

19+
benchmark:
20+
@go test -v ./... -bench=^BenchmarkBuild
21+
1922
docker_build:
2023
@docker build --no-cache -t $(BINARY) .
2124

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# <img src="https://static-00.iconduck.com/assets.00/prometheus-icon-511x512-1vmxbcxr.png" width="50"/> Auto Prometheus Exporter
2-
[![Release](https://github.com/MGSousa/prom-exporter/actions/workflows/release.yml/badge.svg)](https://github.com/MGSousa/prom-exporter/actions/workflows/release.yml)
3-
[![Docker Version](https://img.shields.io/docker/v/mgsousa/prom-exporter.svg)](https://hub.docker.com/r/MGSousa/prom-exporter/)
4-
[![Docker Pulls](https://img.shields.io/docker/pulls/mgsousa/prom-exporter.svg)](https://hub.docker.com/r/MGSousa/prom-exporter/)
1+
# <img src="https://static-00.iconduck.com/assets.00/prometheus-icon-511x512-1vmxbcxr.png" width="50"/> JSON Stats Exporter
52

6-
Prometheus exporter that fetches and auto-resolves JSON data from selected services by converting metrics/stats in Prometheus format, being ready to be scrapped.
3+
[![CI](https://github.com/MGSousa/json-stats-exporter/actions/workflows/release.yml/badge.svg)](https://github.com/MGSousa/json-stats-exporter/actions/workflows/release.yml)
4+
[![Version](https://img.shields.io/github/release/MGSousa/json-stats-exporter.svg?style=flat)]()
5+
6+
Prometheus exporter that scrapes and parses JSON statistics from selected services by converting metrics/stats in Prometheus format, being ready to be scrapped.
77

88
Compatible with Elastic Beats plugins (Filebeat, Auditbeat, Packetbeat, Metricbeat, etc.) and any other tool with HTTP endpoint output in JSON.
99

@@ -12,24 +12,24 @@ Compatible with Elastic Beats plugins (Filebeat, Auditbeat, Packetbeat, Metricbe
1212
- specify version
1313
```sh
1414
VERSION=1.0.0
15-
wget -nv https://github.com/MGSousa/prom-exporter/releases/download/v$VERSION/prom-exporter_${VERSION}_$(uname | awk '{print tolower($0)}')_amd64 -O prom-exporter && chmod +x prom-exporter
15+
wget -nv https://github.com/MGSousa/json-stats-exporter/releases/download/v$VERSION/json-stats-exporter_${VERSION}_$(uname | awk '{print tolower($0)}')_amd64 -O json-stats-exporter && chmod +x json-stats-exporter
1616
```
1717

1818
- or fetch the latest release
1919
```sh
20-
curl -fsL "https://api.github.com/repos/MGSousa/prom-exporter/releases/latest" |\
20+
curl -fsL "https://api.github.com/repos/MGSousa/json-stats-exporter/releases/latest" |\
2121
jq -r ".assets[] | select(.name|contains(\"$(uname | awk '{print tolower($0)}')\")) | .url" |\
22-
wget --header="Accept: application/octet-stream" -O prom-exporter -nv -i - && chmod +x prom-exporter
22+
wget --header="Accept: application/octet-stream" -O json-stats-exporter -nv -i - && chmod +x json-stats-exporter
2323
```
2424
### Windows
2525
```sh
26-
curl -o prom-exporter.exe https://github.com/MGSousa/prom-exporter/releases/download/v1.0.0/prom-exporter_1.0.0_windows_amd64.exe
26+
curl -o json-stats-exporter.exe https://github.com/MGSousa/json-stats-exporter/releases/download/v1.0.0/json-stats-exporter_1.0.0_windows_amd64.exe
2727
```
2828

2929
## Usage
3030
- About args
3131
```sh
32-
Usage of ./prom-exporter:
32+
Usage of ./json-stats-exporter:
3333
-debug
3434
Enable debug mode.
3535
-listen-address string
@@ -114,7 +114,7 @@ services:
114114
```
115115
- Run it via executable
116116
```sh
117-
./prom-exporter -service-name "SERVICE_NAME" -service-uri "REMOTE_HOST" -service-port REMOTE_PORT -service-metrics-path "REMOTE_PATH"
117+
./json-stats-exporter -service-name "SERVICE_NAME" -service-uri "REMOTE_HOST" -service-port REMOTE_PORT -service-metrics-path "REMOTE_PATH"
118118
```
119119

120120
## TODO

0 commit comments

Comments
 (0)