Skip to content

Commit

Permalink
Go 1.22 update (#111)
Browse files Browse the repository at this point in the history
* Bump GO to 1.22

* Extending firewall metrics with rule names

* Adding account specific rule to firewall metrics

* Add Cloudflare Logpush metrics for account and zone

* Selector is included in labels

Bump chart version

* Add Account Label to Metrics

This commit adds the Account label to the metrics label list. The Account label
provides additional context to the metrics, allowing for better categorization
and analysis of data. This change enhances the accuracy and granularity of the
metrics collected.

- Added Account label to metrics
- Improved data categorization and analysis

Signed-off-by: Denys Lemeshko <[email protected]>

Fix missing label

* Add account to labels on logpush events, bump golangci

fix golang-ci lint action

some golangci-lint fixes

* Use cobra and viper as maintained alternatives to namsral/flag library. Add basic tests just make sure you provide .env file with right variables.

---------

Co-authored-by: Oleksii Serhiienko <[email protected]>
Co-authored-by: Bhushan Thakur <[email protected]>
Co-authored-by: Mark Pierce <[email protected]>
Co-authored-by: Denys Lemeshko <[email protected]>
  • Loading branch information
5 people authored May 13, 2024
1 parent f612a39 commit 7f97eee
Show file tree
Hide file tree
Showing 27 changed files with 860 additions and 199 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig is awesome: http://EditorConfig.org

root = true

[*]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8

[*.{yml, yaml}]
indent_size = 2

[*.go]
indent_style = tab

[Makefile]
indent_style = tab
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ updates:
interval: "weekly"
reviewers:
- "Shopify/infrasec"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
2 changes: 1 addition & 1 deletion .github/workflows/docker-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
push: true

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
run: echo ${{ steps.docker_build.outputs.digest }}
1 change: 0 additions & 1 deletion .github/workflows/docker-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,3 @@ jobs:

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

2 changes: 1 addition & 1 deletion .github/workflows/go-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: "./dist/*"
args: "./dist/*"
7 changes: 5 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: golangci-lint
uses: golangci/golangci-lint-action@v2 # https://github.com/marketplace/actions/run-golangci-lint
uses: golangci/golangci-lint-action@v6 # https://github.com/marketplace/actions/run-golangci-lint
with:
version: v1.43
version: latest
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
python-version: 3.7

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.0.1
uses: helm/chart-testing-action@v2.6.1

- name: Run chart-testing (list-changed)
id: list-changed
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@ jobs:
git config user.email "[email protected]"
# See https://github.com/helm/chart-releaser-action/issues/6
# - name: Install Helm
# run: |
# curl -fsSLo get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
# chmod 700 get_helm.sh
# ./get_helm.sh

- name: Install Helm
run: |
curl -fsSLo get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
uses: azure/[email protected]
with:
version: 3.14.0

- name: Add dependency chart repos
run: |
helm repo add stable https://charts.helm.sh/stable
helm repo add incubator https://charts.helm.sh/incubator
- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.0.0
uses: helm/chart-releaser-action@v1.6.0
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ vendor/
*.swp

.idea/
.env
venom*
22 changes: 19 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
linters:
disable:
- errcheck
enable:
- megacheck
- gofmt
#- gosimple
- staticcheck
- govet
- revive # replacement for golint

- asciicheck
- errorlint
- gofmt
- goimports
- gosec
# - gocritic
- importas
# - prealloc
- revive
- misspell
- stylecheck
- unconvert
- unused
- whitespace

linters-settings:
gofmt:
Expand Down
13 changes: 10 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: check-merge-conflict
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: destroyed-symlinks
- id: detect-private-key
- id: check-ast
- id: check-case-conflict
- id: debug-statements

- repo: https://github.com/golangci/golangci-lint
rev: v1.43.0
rev: v1.58.0
hooks:
- id: golangci-lint
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COPY go.mod go.mod
COPY go.sum go.sum

RUN go get -d -v
RUN CGO_ENABLED=0 GOOS=linux go build -o cloudflare_exporter .
RUN CGO_ENABLED=0 GOOS=linux go build --ldflags '-w -s -extldflags "-static"' -o cloudflare_exporter .

FROM alpine:3.18

Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.PHONY: build
build:
CGO_ENABLED=0 go build -o cloudflare_exporter .
build: lint
CGO_ENABLED=0 go build --ldflags '-w -s -extldflags "-static"' -o cloudflare_exporter .
lint:
golangci-lint run
clean:
rm cloudflare_exporter venom*.log basic_tests.* pprof_cpu*
test:
./run_e2e.sh
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Required authentication scopes:
- `Account.Account Analytics:Read` is required for Worker metrics
- `Account Settings:Read` is required for Worker metrics (for listing accessible accounts, scraping all available
Workers included in authentication scope)
- `Firewall Services:Read` is required to fetch zone rule name for `cloudflare_zone_firewall_events_count` metric
- `Account. Account Rulesets:Read` is required to fetch account rule name for `cloudflare_zone_firewall_events_count` metric

To authenticate this way, only set `CF_API_TOKEN` (omit `CF_API_EMAIL` and `CF_API_KEY`)

Expand Down Expand Up @@ -100,6 +102,8 @@ Note: `ZONE_<name>` configuration is not supported as flag.
# HELP cloudflare_zone_uniques_total Uniques per zone
# HELP cloudflare_zone_pool_health_status Reports the health of a pool, 1 for healthy, 0 for unhealthy
# HELP cloudflare_zone_pool_requests_total Requests per pool
# HELP cloudflare_logpush_failed_jobs_account_count Number of failed logpush jobs on the account level
# HELP cloudflare_logpush_failed_jobs_zone_count Number of failed logpush jobs on the zone level
```

## Helm chart repository
Expand Down
37 changes: 37 additions & 0 deletions chart_schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: str()
home: str(required=False)
version: str()
apiVersion: str()
appVersion: any(str(), num(), required=False)
description: str(required=False)
keywords: list(str(), required=False)
sources: list(str(), required=False)
maintainers: list(include('maintainer'), required=False)
dependencies: list(include('dependency'), required=False)
icon: str(required=False)
engine: str(required=False)
condition: str(required=False)
tags: str(required=False)
deprecated: bool(required=False)
kubeVersion: str(required=False)
annotations: map(str(), str(), required=False)
type: str(required=False)
---
maintainer:
name: str()
email: str(required=False)
url: str(required=False)
---
dependency:
name: str()
version: str()
repository: str(required=False)
condition: str(required=False)
tags: list(str(), required=False)
enabled: bool(required=False)
import-values: any(list(str()), list(include('import-value')), required=False)
alias: str(required=False)
---
import-value:
child: str()
parent: str()
2 changes: 1 addition & 1 deletion charts/cloudflare-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: cloudflare-exporter
version: 0.1.9
version: 0.2.0
appVersion: 0.0.9
home: https://github.com/lablabs/cloudflare-exporter
description: A Helm chart for cloudflare exporter
Expand Down
5 changes: 5 additions & 0 deletions charts/cloudflare-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Common labels
{{- define "cloudflare-exporter.labels" -}}
helm.sh/chart: {{ include "cloudflare-exporter.chart" . }}
{{ include "cloudflare-exporter.selectorLabels" . }}
{{- if .Values.labels }}
{{- range $key, $value := .Values.labels }}
{{ $key }}: "{{ $value }}"
{{- end }}
{{- end }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion charts/cloudflare-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "cloudflare-exporter.selectorLabels" . | nindent 8 }}
{{- include "cloudflare-exporter.labels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
Loading

0 comments on commit 7f97eee

Please sign in to comment.