From 2214dcfeae91220fec066ff2651b404aa109063f Mon Sep 17 00:00:00 2001 From: Cyb3r-Jak3 Date: Sun, 4 Aug 2024 09:22:51 -0400 Subject: [PATCH 1/4] feat: remove total metric as we can caculate it --- README.md | 1 - prometheus.go | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/README.md b/README.md index 4410d70..6ee89f1 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,6 @@ Note: `ZONE_` configuration is not supported as flag. # HELP cloudflare_logpush_failed_jobs_zone_count Number of failed logpush jobs on the zone level # HELP cloudflare_r2_operation_count Number of operations performed by R2 # HELP cloudflare_r2_storage_bytes Storage used by R2 -# HELP cloudflare_r2_storage_total_bytes Total storage used by R2 ``` ## Helm chart repository diff --git a/prometheus.go b/prometheus.go index 63d0471..d35adb7 100644 --- a/prometheus.go +++ b/prometheus.go @@ -52,7 +52,6 @@ const ( poolRequestsTotalMetricName MetricName = "cloudflare_zone_pool_requests_total" logpushFailedJobsAccountMetricName MetricName = "cloudflare_logpush_failed_jobs_account_count" logpushFailedJobsZoneMetricName MetricName = "cloudflare_logpush_failed_jobs_zone_count" - r2StorageTotalMetricName MetricName = "cloudflare_r2_storage_total_bytes" r2StorageMetricName MetricName = "cloudflare_r2_storage_bytes" r2OperationMetricName MetricName = "cloudflare_r2_operation_count" ) @@ -271,11 +270,6 @@ var ( []string{"destination", "job_id", "final"}, ) - r2StorageTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Name: r2StorageTotalMetricName.String(), - Help: "Total storage used by R2", - }, []string{"account"}) - r2Storage = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: r2StorageMetricName.String(), Help: "Storage used by R2", @@ -321,7 +315,6 @@ func buildAllMetricsSet() MetricsSet { allMetricsSet.Add(poolRequestsTotalMetricName) allMetricsSet.Add(logpushFailedJobsAccountMetricName) allMetricsSet.Add(logpushFailedJobsZoneMetricName) - allMetricsSet.Add(r2StorageTotalMetricName) allMetricsSet.Add(r2OperationMetricName) allMetricsSet.Add(r2StorageMetricName) return allMetricsSet @@ -437,9 +430,6 @@ func mustRegisterMetrics(deniedMetrics MetricsSet) { if !deniedMetrics.Has(logpushFailedJobsZoneMetricName) { prometheus.MustRegister(logpushFailedJobsZone) } - if !deniedMetrics.Has(r2StorageTotalMetricName) { - prometheus.MustRegister(r2StorageTotal) - } if !deniedMetrics.Has(r2StorageMetricName) { prometheus.MustRegister(r2Storage) } @@ -517,15 +507,12 @@ func fetchR2StorageForAccount(account cloudflare.Account, wg *sync.WaitGroup) { return } for _, acc := range r.Viewer.Accounts { - var totalStorage uint64 for _, bucket := range acc.R2StorageGroups { - totalStorage += bucket.Max.PayloadSize r2Storage.With(prometheus.Labels{"account": account.Name, "bucket": bucket.Dimensions.BucketName}).Set(float64(bucket.Max.PayloadSize)) } for _, operation := range acc.R2StorageOperations { r2Operation.With(prometheus.Labels{"account": account.Name, "bucket": operation.Dimensions.BucketName, "operation": operation.Dimensions.Action}).Set(float64(operation.Sum.Requests)) } - r2StorageTotal.With(prometheus.Labels{"account": account.Name}).Set(float64(totalStorage)) } } From 180a5c1231bd4a134fdd2b494506861276c9dbaf Mon Sep 17 00:00:00 2001 From: Cyb3r-Jak3 Date: Sun, 4 Aug 2024 09:30:01 -0400 Subject: [PATCH 2/4] bug: remove debugging message --- .github/workflows/{helm-release.yaml => helm-release.yaml.old} | 0 cloudflare.go | 1 - 2 files changed, 1 deletion(-) rename .github/workflows/{helm-release.yaml => helm-release.yaml.old} (100%) diff --git a/.github/workflows/helm-release.yaml b/.github/workflows/helm-release.yaml.old similarity index 100% rename from .github/workflows/helm-release.yaml rename to .github/workflows/helm-release.yaml.old diff --git a/cloudflare.go b/cloudflare.go index 3f054f6..55b3c50 100644 --- a/cloudflare.go +++ b/cloudflare.go @@ -803,7 +803,6 @@ func fetchR2Account(accountID string) (*cloudflareResponseR2Account, error) { ctx := context.Background() graphqlClient := graphql.NewClient(cfGraphQLEndpoint) - graphqlClient.Log = func(s string) { log.Debug(s) } var resp cloudflareResponseR2Account if err := graphqlClient.Run(ctx, request, &resp); err != nil { log.Errorf("Error fetching R2 account: %s", err) From 86f9054b235d8198c7765fdf5b853688012252fa Mon Sep 17 00:00:00 2001 From: Cyb3r-Jak3 Date: Sun, 4 Aug 2024 09:34:20 -0400 Subject: [PATCH 3/4] feat: Add version flags to makefile --- .goreleaser.yaml | 2 -- Makefile | 6 +++++- README.md | 21 +++++++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 1e67b3f..421e79c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -13,8 +13,6 @@ before: hooks: # You may remove this if you don't use go modules. - go mod tidy - # you may remove this if you don't need go generate - - go generate ./... builds: - env: diff --git a/Makefile b/Makefile index 2316840..53fac67 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ +GIT_VERSION ?= $(shell git describe --tags --always --dirty="-dev") +DATE ?= $(shell date -u '+%Y-%m-%d %H:%M UTC') +VERSION_FLAGS := -s -w -X "main.version=$(GIT_VERSION)" -X "main.date=$(DATE)" +CGO_ENABLED ?= 0 .PHONY: build build: - CGO_ENABLED=0 go build --ldflags '-w -s -extldflags "-static"' -o cloudflare_exporter . + go build -trimpath --ldflags '$(VERSION_FLAGS) -extldflags "-static"' -o cloudflare_exporter . lint: golangci-lint run clean: diff --git a/README.md b/README.md index 6ee89f1..2501715 100644 --- a/README.md +++ b/README.md @@ -110,17 +110,22 @@ Note: `ZONE_` configuration is not supported as flag. # HELP cloudflare_r2_storage_bytes Storage used by R2 ``` -## Helm chart repository -To deploy the exporter into Kubernetes, we recommend using our manager Helm repository: +[//]: # (## Helm chart repository) -``` -helm repo add cloudflare-exporter https://lablabs.github.io/cloudflare-exporter/ -helm install cloudflare-exporter/cloudflare-exporter -``` +[//]: # (To deploy the exporter into Kubernetes, we recommend using our manager Helm repository:) + +[//]: # () +[//]: # (```) + +[//]: # (helm repo add cloudflare-exporter https://lablabs.github.io/cloudflare-exporter/) + +[//]: # (helm install cloudflare-exporter/cloudflare-exporter) + +[//]: # (```) ## Docker ### Build -Images are available at [Github Container Registry](https://github.com/lablabs/cloudflare-exporter/pkgs/container/cloudflare_exporter) +Images are available at [Github Container Registry](https://github.com/Cyb3r-Jak3/cloudflare-exporter/pkgs/container/cloudflare_exporter) ``` docker build -t ghcr.io/Cyb3r-Jak3/cloudflare_exporter . @@ -149,7 +154,7 @@ docker run --rm -p 8080:8080 -e CF_API_TOKEN=${CF_API_TOKEN} -e FREE_TIER=true g Access help: ``` -docker run --rm -p 8080:8080 -i ghcr.io/lablabs/cloudflare_exporter --help +docker run --rm -p 8080:8080 -i ghcr.io/Cyb3r-Jak3/cloudflare_exporter --help ``` ## Contributing and reporting issues From e8057e8c630ddd5cff966679cd92c5b20373249f Mon Sep 17 00:00:00 2001 From: Cyb3r-Jak3 Date: Sun, 4 Aug 2024 09:47:50 -0400 Subject: [PATCH 4/4] bug: install syft on snapshot job --- .github/workflows/golang.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/golang.yaml b/.github/workflows/golang.yaml index e938b88..3911bed 100644 --- a/.github/workflows/golang.yaml +++ b/.github/workflows/golang.yaml @@ -74,6 +74,11 @@ jobs: with: go-version-file: go.mod + - name: Install syft + run: | + curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin + syft version + - name: GoReleaser Action uses: goreleaser/goreleaser-action@v6 with: