Skip to content

Commit

Permalink
Fix warnings and errors from go lang linter (#56)
Browse files Browse the repository at this point in the history
* Add GO lang linter to GH workflow and pre-commit hook

* fix .golangci.yaml

* go lang ci lint workflow

* remove comments from golang-ci.yml

* Fix warnings and errors from go lang linter
  • Loading branch information
tomas-balaz authored Dec 16, 2021
1 parent aef471c commit 1df59e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 40 deletions.
10 changes: 5 additions & 5 deletions cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ type accountResp struct {
} `json:"sum"`

Quantiles struct {
CpuTimeP50 float32 `json:"cpuTimeP50"`
CpuTimeP75 float32 `json:"cpuTimeP75"`
CpuTimeP99 float32 `json:"cpuTimeP99"`
CpuTimeP999 float32 `json:"cpuTimeP999"`
CPUTimeP50 float32 `json:"cpuTimeP50"`
CPUTimeP75 float32 `json:"cpuTimeP75"`
CPUTimeP99 float32 `json:"cpuTimeP99"`
CPUTimeP999 float32 `json:"cpuTimeP999"`
DurationP50 float32 `json:"durationP50"`
DurationP75 float32 `json:"durationP75"`
DurationP99 float32 `json:"durationP99"`
Expand Down Expand Up @@ -124,7 +124,7 @@ type zoneResp struct {
} `json:"responseStatusMap"`
ThreatPathing []struct {
Name string `json:"threatPathingName"`
Requests uint64 `json:"requests "`
Requests uint64 `json:"requests"`
} `json:"threatPathingMap"`
Threats uint64 `json:"threats"`
} `json:"sum"`
Expand Down
40 changes: 5 additions & 35 deletions prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,12 @@ var (
}, []string{"zone"},
)

zoneRequestUncached = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cloudflare_zone_requests_uncached",
Help: "Number of uncached requests for zone",
}, []string{"zone"},
)

zoneRequestSSLEncrypted = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cloudflare_zone_requests_ssl_encrypted",
Help: "Number of encrypted requests for zone",
}, []string{"zone"},
)

zoneRequestSSLUnencrypted = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cloudflare_zone_requests_ssl_unencrypted",
Help: "Number of encrypted requests for zone",
}, []string{"zone"},
)

zoneRequestContentType = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cloudflare_zone_requests_content_type",
Help: "Number of request for zone per content type",
Expand Down Expand Up @@ -84,24 +72,12 @@ var (
}, []string{"zone"},
)

zoneBandwidthUncached = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cloudflare_zone_bandwidth_uncached",
Help: "Uncached bandwidth per zone in bytes",
}, []string{"zone"},
)

zoneBandwidthSSLEncrypted = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cloudflare_zone_bandwidth_ssl_encrypted",
Help: "Encrypted bandwidth per zone in bytes",
}, []string{"zone"},
)

zoneBandwidthSSLUnencrypted = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cloudflare_zone_bandwidth_ssl_unencrypted",
Help: "Unencrypted bandwidth per zone in bytes",
}, []string{"zone"},
)

zoneBandwidthContentType = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cloudflare_zone_bandwidth_content_type",
Help: "Bandwidth per zone per content type",
Expand Down Expand Up @@ -138,12 +114,6 @@ var (
}, []string{"zone"},
)

zonePageviewsSearchEngines = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cloudflare_zone_pageviews_search_engines",
Help: "Pageviews per zone per engine",
}, []string{"zone", "searchengine"},
)

zoneUniquesTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cloudflare_zone_uniques_total",
Help: "Uniques per zone",
Expand Down Expand Up @@ -186,7 +156,7 @@ var (
}, []string{"script_name"},
)

workerCpuTime = promauto.NewGaugeVec(prometheus.GaugeOpts{
workerCPUTime = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "cloudflare_worker_cpu_time",
Help: "CPU time quantiles by script name",
}, []string{"script_name", "quantile"},
Expand All @@ -212,10 +182,10 @@ func fetchWorkerAnalytics(account cloudflare.Account, wg *sync.WaitGroup) {
for _, w := range a.WorkersInvocationsAdaptive {
workerRequests.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName}).Add(float64(w.Sum.Requests))
workerErrors.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName}).Add(float64(w.Sum.Errors))
workerCpuTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "quantile": "P50"}).Set(float64(w.Quantiles.CpuTimeP50))
workerCpuTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "quantile": "P75"}).Set(float64(w.Quantiles.CpuTimeP75))
workerCpuTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "quantile": "P99"}).Set(float64(w.Quantiles.CpuTimeP99))
workerCpuTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "quantile": "P999"}).Set(float64(w.Quantiles.CpuTimeP999))
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "quantile": "P50"}).Set(float64(w.Quantiles.CPUTimeP50))
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "quantile": "P75"}).Set(float64(w.Quantiles.CPUTimeP75))
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "quantile": "P99"}).Set(float64(w.Quantiles.CPUTimeP99))
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "quantile": "P999"}).Set(float64(w.Quantiles.CPUTimeP999))
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "quantile": "P50"}).Set(float64(w.Quantiles.DurationP50))
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "quantile": "P75"}).Set(float64(w.Quantiles.DurationP75))
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "quantile": "P99"}).Set(float64(w.Quantiles.DurationP99))
Expand Down

0 comments on commit 1df59e2

Please sign in to comment.