Skip to content

Commit

Permalink
Addressed comments.
Browse files Browse the repository at this point in the history
Signed-off-by: bwplotka <[email protected]>
  • Loading branch information
bwplotka committed Oct 7, 2024
1 parent ee65708 commit ed62793
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 18 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Go
on: [push]

jobs:
build:
runs-on: ubuntu-latest
name: Unit tests on Go ${{ matrix.go }} ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.22.x'
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
- name: Run unit tests.
env:
GOBIN: /tmp/.bin
run: make test
39 changes: 39 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# This action is synced from https://github.com/prometheus/prometheus
name: golangci-lint
on:
push:
paths:
- "go.sum"
- "go.mod"
- "**.go"
- "scripts/errcheck_excludes.txt"
- ".github/workflows/golangci-lint.yml"
- ".golangci.yml"
pull_request:

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
golangci:
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Install Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.23.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
args: --verbose ./tools/mtypes/...
version: v1.60.2
135 changes: 131 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,135 @@
# Generally copied from prometheus/prometheus.
run:
deadline: 5m
skip-files:
# Skip autogenerated files.
- ^.*\.(pb|y)\.go$
timeout: 15m

output:
sort-results: true

linters:
enable:
- depguard
- errorlint
- gocritic
- godot
- gofumpt
- goimports
- misspell
- nolintlint
- perfsprint
- predeclared
- revive
- testifylint
- unconvert
- unused
- usestdlibvars
- whitespace
- loggercheck

issues:
max-issues-per-linter: 0
max-same-issues: 0
# The default exclusions are too aggressive. For one, they
# essentially disable any linting on doc comments. We disable
# default exclusions here and add exclusions fitting our codebase
# further down.
exclude-use-default: false
exclude-files:
# Skip autogenerated files.
- ^.*\.(pb|y)\.go$
exclude-rules:
- linters:
- errcheck
# Taken from the default exclusions (that are otherwise disabled above).
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
- linters:
- govet
# We use many Seek methods that do not follow the usual pattern.
text: "stdmethods: method Seek.* should have signature Seek"
- path: _test.go
linters:
- errcheck
- linters:
- godot
source: "^// ==="
- linters:
- perfsprint
text: "fmt.Sprintf can be replaced with string concatenation"
linters-settings:
depguard:
rules:
main:
deny:
- pkg: "sync/atomic"
desc: "Use go.uber.org/atomic instead of sync/atomic"
- pkg: "github.com/stretchr/testify/assert"
desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
- pkg: "github.com/go-kit/kit/log"
desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
- pkg: "io/ioutil"
desc: "Use corresponding 'os' or 'io' functions instead."
- pkg: "regexp"
desc: "Use github.com/grafana/regexp instead of regexp"
- pkg: "github.com/pkg/errors"
desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors"
- pkg: "gzip"
desc: "Use github.com/klauspost/compress instead of gzip"
- pkg: "zlib"
desc: "Use github.com/klauspost/compress instead of zlib"
- pkg: "golang.org/x/exp/slices"
desc: "Use 'slices' instead."
errcheck:
exclude-functions:
# Don't flag lines such as "io.Copy(io.Discard, resp.Body)".
- io.Copy
# The next two are used in HTTP handlers, any error is handled by the server itself.
- io.WriteString
- (net/http.ResponseWriter).Write
# No need to check for errors on server's shutdown.
- (*net/http.Server).Shutdown
# Never check for logger errors.
- (github.com/go-kit/log.Logger).Log
goimports:
local-prefixes: github.com/prometheus/prometheus
gofumpt:
extra-rules: true
perfsprint:
# Optimizes `fmt.Errorf`.
errorf: false
revive:
# By default, revive will enable only the linting rules that are named in the configuration file.
# So, it's needed to explicitly enable all required rules here.
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
- name: blank-imports
- name: comment-spacings
- name: context-as-argument
arguments:
# Allow functions with test or bench signatures.
- allowTypesBefore: "*testing.T,testing.TB"
- name: context-keys-type
- name: dot-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: unused-parameter
disabled: true
- name: var-declaration
- name: var-naming
testifylint:
disable:
- float-compare
- go-require
enable-all: true
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ cluster-destroy: check-deps ## Tear down the benchmarking GKE cluster.
.PHONY: lint
lint: ## Lint resources.
bash ./scripts/shellcheck.sh

GOMODS := $(shell find . -name "go.mod" | grep -v .bingo)
.PHONY: test
test:
@for gomod in $(GOMODS); do \
cd `dirname $$gomod` && go test -v ./...; \
done
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You can start as many scenarios as you want on the single cluster (make sure to

The scenario is a path to the "collector" manifest, so anything that will scrape `./manifests/load/avalanche.exampletarget.yaml`. Feel free to adjust anything in `./manifests/scenarios/` or add your own.

This setup uses separate Prometheus for gathering metrics about core resources and collectors (available locally and in GCM). Make sure your pod has `app=collector` label and relevant port name has `-ins` suffix, sto be scraped by this core Prometheus. There is also a dashboard you can apply to GCM in `./dashboards/`.
This setup uses separate Prometheus for gathering metrics about core resources and collectors (available locally and in GCM). Make sure your pod has `app=collector` label and relevant port name has `-ins` suffix, to be scraped by this core Prometheus. There is also a dashboard you can apply to GCM in `./dashboards/`.

* `make stop CLUSTER_NAME=my-prombenchy BENCH_NAME=<name of benchmark, also k8s namespace> SCENARIO=./manifests/scenarios/gmp` kill the node-pool and experiment.

Expand Down
3 changes: 3 additions & 0 deletions manifests/scenarios/gmp-otel/1_collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ data:
# - delete_key(attributes, "project_id")
receivers:
# NOTE(bwplotka): Mimicking scrape config of GMP operator, to ensure
# we have the same labels on the output with the same relabel processing.
# Related issue: https://github.com/bwplotka/prombenchy/issues/13
prometheus/bench:
config:
scrape_configs:
Expand Down
33 changes: 20 additions & 13 deletions tools/mtypes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,40 +67,47 @@ func main() {
writeStatistics(os.Stdout, total, statistics)

if *avalancheFlagsForTotal > 0 {
// adjustedGoal is tracking the # of adjusted series we want to generate with avalanche.
adjustedGoal := float64(*avalancheFlagsForTotal)
fmt.Println()
fmt.Println("Avalanche flags for the similar distribution to get to the adjusted series goal of:", adjustedGoal)

adjustedGoal = adjustedGoal / 10.0 // Assuming --series-count=10
// adjustedSum is tracking the total sum of series so far (at the end hopefully adjustedSum ~= adjustedGoal)
adjustedSum := 0
for _, mtype := range allTypes {
s := statistics[mtype]

// adjustedSeriesRatio is tracking the ratio of this type in the input file.
// We try to get similar ratio, but with different absolute counts, given the total sum of series we are aiming for.
adjustedSeriesRatio := float64(s.adjustedSeries) / float64(total.adjustedSeries)

adjustedSeries := int(adjustedGoal * adjustedSeriesRatio)
// adjustedSeriesForType is tracking (per metric type), how many unique series of that
// metric type avalanche needs to create according to the ratio we got from our input.
adjustedSeriesForType := int(adjustedGoal * adjustedSeriesRatio)

switch mtype {
case dto.MetricType_GAUGE:
fmt.Printf("--gauge-metric-count=%v\n", adjustedSeries)
adjustedSum += adjustedSeries
fmt.Printf("--gauge-metric-count=%v\n", adjustedSeriesForType)
adjustedSum += adjustedSeriesForType
case dto.MetricType_COUNTER:
fmt.Printf("--counter-metric-count=%v\n", adjustedSeries)
adjustedSum += adjustedSeries
fmt.Printf("--counter-metric-count=%v\n", adjustedSeriesForType)
adjustedSum += adjustedSeriesForType
case dto.MetricType_HISTOGRAM:
avgBkts := s.buckets / s.series
adjustedSeries /= 2 + avgBkts
fmt.Printf("--histogram-metric-count=%v\n", adjustedSeries)
adjustedSeriesForType /= 2 + avgBkts
fmt.Printf("--histogram-metric-count=%v\n", adjustedSeriesForType)
fmt.Printf("--histogram-metric-bucket-count=%v\n", avgBkts-1) // -1 is due to caveat of additional +Inf not added by avalanche.
adjustedSum += adjustedSeries * (2 + avgBkts)
adjustedSum += adjustedSeriesForType * (2 + avgBkts)
case metricType_NATIVE_HISTOGRAM:
fmt.Printf("--native-histogram-metric-count=%v\n", adjustedSeries)
adjustedSum += adjustedSeries
fmt.Printf("--native-histogram-metric-count=%v\n", adjustedSeriesForType)
adjustedSum += adjustedSeriesForType
case dto.MetricType_SUMMARY:
avgObjs := s.objectives / s.series
adjustedSeries /= 2 + avgObjs
fmt.Printf("--summary-metric-count=%v\n", adjustedSeries)
adjustedSeriesForType /= 2 + avgObjs
fmt.Printf("--summary-metric-count=%v\n", adjustedSeriesForType)
fmt.Printf("--summary-metric-objective-count=%v\n", avgObjs)
adjustedSum += adjustedSeries * (2 + avgObjs)
adjustedSum += adjustedSeriesForType * (2 + avgObjs)
default:
if s.series > 0 {
log.Fatalf("not supported %v metric in avalanche", mtype)
Expand Down

0 comments on commit ed62793

Please sign in to comment.