Skip to content

Commit 2ee6a99

Browse files
authored
Lint (#216)
1 parent fd8f5c5 commit 2ee6a99

File tree

91 files changed

+314
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+314
-188
lines changed

.github/workflows/go.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,3 @@ jobs:
4545
run: |
4646
export KUBECONFIG="${HOME}/.kube/config"
4747
make test-e2e
48-

.github/workflows/kind/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ nodes:
77
kind: InitConfiguration
88
nodeRegistration:
99
kubeletExtraArgs:
10-
node-labels: "nodepool=monitoring"
10+
node-labels: "nodepool=monitoring"

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ monitoring-*/manifests/*/*/*.yaml
55
config.yaml
66

77
.idea
8-
./kind
8+
./kind

.gitpod.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ workspaceLocation: observability/observability.code-workspace
33
tasks:
44
- init: |
55
# TODO(arthursens): We should update the workspace image so we dont need the step below
6-
sudo apt update ; sudo apt-get install apt-transport-https ca-certificates -y ; sudo update-ca-certificates
6+
sudo apt update ; sudo apt-get install shellcheck apt-transport-https ca-certificates -y ; sudo update-ca-certificates
77
make --always-make
8+
pip install pre-commit && pre-commit install --install-hooks
89
vscode:
910
extensions:
1011
- heptio.jsonnet

.golangci.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
run:
2+
timeout: 5m
3+
go: '1.19'
4+
skip-dirs:
5+
- vendor/
6+
7+
linters:
8+
disable-all: true
9+
enable:
10+
- bodyclose # checks whether HTTP response body is closed successfully
11+
- deadcode # Finds unused code
12+
- gci # Gci controls golang package import order and makes it always deterministic.
13+
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
14+
- dupl # Tool for code clone detection
15+
- errcheck # checks whether Err of rows is checked successfully
16+
- goconst # Finds repeated strings that could be replaced by a constant
17+
- gocritic # check for bugs, performance and style issues.
18+
- gocyclo # Computes and checks the cyclomatic complexity of functions
19+
- gofmt
20+
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt.
21+
- goprintffuncname # Checks that printf-like functions are named with f at the end
22+
- gosec # Inspects source code for security problems
23+
- gosimple # Linter for Go source code that specializes in simplifying code
24+
- govet
25+
- ineffassign # Detects when assignments to existing variables are not used
26+
- nakedret # Finds naked returns in functions
27+
- stylecheck # Stylecheck is a replacement for golint
28+
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
29+
- unparam # Reports unused function parameters
30+
- unused # Checks Go code for unused constants, variables, functions and types
31+
- varcheck # Finds unused global variables and constants
32+
- whitespace # Tool for detection of leading and trailing whitespace
33+
34+
issues:
35+
# List of regexps of issue texts to exclude.
36+
exclude-rules:
37+
- linters:
38+
- gosec
39+
text: "G306"
40+
41+
linters-settings:
42+
gci:
43+
# Section configuration to compare against.
44+
# Section names are case-insensitive and may contain parameters in ().
45+
# Default: ["standard", "default"]
46+
sections:
47+
- standard # Captures all standard packages if they do not match another section.
48+
- default # Contains all imports that could not be matched to another section type.
49+
- prefix(github.com/gitpod-io/observability) # Groups all imports with the specified Prefix.

.pre-commit-config.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: check-symlinks
9+
- id: mixed-line-ending
10+
- id: check-case-conflict
11+
- id: check-executables-have-shebangs
12+
- id: check-shebang-scripts-are-executable
13+
- id: check-merge-conflict
14+
15+
# keep fork in sync!
16+
- repo: https://github.com/gitpod-io/pre-commit-hooks
17+
rev: "2.1.5"
18+
hooks:
19+
- id: forbid-binary
20+
exclude: |
21+
(?x)^(
22+
.*example-layer.tar.gz|
23+
.*\.(png|svg|ico|gpg)|
24+
dev/version-manifest/version-manifest|
25+
.*gradle-wrapper\.jar
26+
)$
27+
- id: script-must-have-extension
28+
- id: shellcheck
29+
args: [ -e, "SC1090,SC1091" ]
30+
exclude: .*/gradlew$
31+
32+
- repo: https://github.com/golangci/golangci-lint
33+
rev: "v1.48.0"
34+
hooks:
35+
- id: golangci-lint
36+
name: golangci-lint
37+
entry: bash -c 'cd installer && golangci-lint run --fix'
38+
types: [ go ]
39+
language: golang
40+
pass_filenames: false
41+
42+
exclude: ^vendor|^hack/deploy.*

CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Therefore, adding new external variables to the project is considered a breaking
2727

2828
### Adding new components
2929

30-
In an ideal world, new components that we'd like to add to any of our applications would already have a jsonnet library that we could easily import and use. Unfortunately, this is not a common practice.
30+
In an ideal world, new components that we'd like to add to any of our applications would already have a jsonnet library that we could easily import and use. Unfortunately, this is not a common practice.
3131

32-
For the components that do not have a jsonnet library, we can create them ourselves under the [components](components/) directory. Those libraries should generate all manifests required to monitor this component, e.g. network policies, services and serviceMonitors.
32+
For the components that do not have a jsonnet library, we can create them ourselves under the [components](components/) directory. Those libraries should generate all manifests required to monitor this component, e.g. network policies, services and serviceMonitors.
3333

3434
After adding a new library, make sure you're adding it to either [monitoring-satellite](monitoring-satellite/monitoring-satellite.libsonnet) or [monitoring-central](monitoring-central/monitoring-central.libsonnet).
3535

@@ -79,4 +79,4 @@ The format can be described more formally as follows:
7979
The first line is the subject and should be no longer than 70 characters, the
8080
second line is always blank, and other lines should be wrapped at 80 characters.
8181
This allows the message to be easier to read on GitHub as well as in various
82-
git tools.
82+
git tools.

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ clean:
1515
git clean -Xfd .
1616

1717
.PHONY: setup-workspace
18-
setup-workspace:
18+
setup-workspace:
1919
go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
2020
go get github.com/brancz/gojsontoyaml
2121
go get github.com/google/go-jsonnet/cmd/jsonnet
@@ -25,7 +25,7 @@ setup-workspace:
2525

2626
.PHONY: generate
2727
generate: $(JSONNET_BIN)
28-
./hack/generate.sh
28+
./hack/generate.sh
2929

3030
.PHONY: generate-ci
3131
generate-ci: $(JSONNET_BIN)
@@ -37,14 +37,14 @@ fmt: $(JSONNETFMT_BIN)
3737
xargs -n 1 -- $(JSONNET_FMT) -i
3838

3939
.PHONY: lint
40-
lint: $(JSONNETFMT_BIN)
40+
lint: $(JSONNETFMT_BIN)
4141
find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
4242
while read f; do \
4343
$(JSONNET_FMT) "$$f" | diff -u "$$f" -; \
4444
done
4545

4646
.PHONY: promtool-lint
47-
promtool-lint:
47+
promtool-lint:
4848
promtool check rules monitoring-satellite/manifests/ci_prometheus_rules.yaml
4949

5050
$(BIN_DIR):
@@ -76,4 +76,4 @@ deploy-central: generate
7676

7777
.PHONY: test-e2e
7878
test-e2e:
79-
@cd tests/e2e && go test -timeout 55m -v . -count=1
79+
@cd tests/e2e && go test -timeout 55m -v . -count=1

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ monitoring-satellite/manifests/yaml-generator.jsonnet | xargs -I{} sh -c 'cat {}
4747
#### Components
4848

4949
* [Grafana](https://github.com/grafana/grafana)
50-
* [VictoriaMetrics](https://github.com/VictoriaMetrics/VictoriaMetrics)
50+
* [VictoriaMetrics](https://github.com/VictoriaMetrics/VictoriaMetrics)
5151

5252
To customize the stack, we make use of Jsonnet's [external-variables feature](https://jsonnet.org/ref/stdlib.html). We expect one single external variable called `config` which is loaded and merged with monitoring-satellite to customize the stack.
5353

@@ -74,4 +74,4 @@ jsonnet -c -J vendor -m monitoring-central/manifests \
7474
},
7575
}" \
7676
monitoring-central/manifests/yaml-generator.jsonnet | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml' -- {}
77-
```
77+
```

docs/code-design.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It not only assures a good level of quality but also alleviates the maintainance
1111

1212
Kube-prometheus is the most popular project that bundles together several components, and their mixins, that are commonly used together to monitor applications that run on Kubernetes Clusters.
1313

14-
Inspired by [kube-prometheus](https://github.com/prometheus-operator/kube-prometheus) design, we separate our libsonnet code in 3 main sections. By following their design, it's easy for us to propose new features upstream instead of maintaing them ourselves :)
14+
Inspired by [kube-prometheus](https://github.com/prometheus-operator/kube-prometheus) design, we separate our libsonnet code in 3 main sections. By following their design, it's easy for us to propose new features upstream instead of maintaing them ourselves :)
1515

1616
The sections are:
1717

@@ -34,4 +34,4 @@ Since we are betting on Prometheus for metrics, we'll go with a tech stack that
3434

3535
1. `Traces` - To be collected with [Jaeger](https://www.jaegertracing.io/) or [Tempo](https://grafana.com/oss/tempo/)
3636
1. `Logs` - To be collected with [Loki](https://grafana.com/oss/loki/)
37-
1. `Profiles` - To be collected with [Conprof](https://github.com/conprof/conprof)
37+
1. `Profiles` - To be collected with [Conprof](https://github.com/conprof/conprof)

docs/monitoring-central.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ message Stackdriver {
6464

6565
// Google service account's private key.
6666
required string privateKey = 3;
67-
}
67+
}

docs/monitoring-satellite.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,4 @@ message Kubescape {
119119

120120
message Pyrra {
121121

122-
}
122+
}

hack/deploy-central.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/podsecuritypoli
3030

3131
kubectl $KUBECONFIG_FLAG apply -f monitoring-central/manifests/grafana/
3232
kubectl $KUBECONFIG_FLAG apply -f monitoring-central/manifests/victoriametrics/
33-
kubectl $KUBECONFIG_FLAG apply -f monitoring-central/manifests/pyrra/
33+
kubectl $KUBECONFIG_FLAG apply -f monitoring-central/manifests/pyrra/

hack/deploy-crds.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ if [[ $KUBECONFIG != "" ]]; then
2323
KUBECONFIG_FLAG="--kubeconfig ${KUBECONFIG}"
2424
fi
2525

26-
for CRD in $(find monitoring-satellite/manifests/prometheusOperator/ -type f -name "*CustomResourceDefinition.yaml");
27-
do
26+
# shellcheck disable=SC2044
27+
for CRD in $(find monitoring-satellite/manifests/prometheusOperator/ -type f -name "*CustomResourceDefinition.yaml");
28+
do
2829
kubectl $KUBECONFIG_FLAG replace -f $CRD || kubectl $KUBECONFIG_FLAG create -f $CRD
2930
done
3031

3132
until kubectl $KUBECONFIG_FLAG get servicemonitors.monitoring.coreos.com --all-namespaces ; do date; sleep 1; echo ""; done
3233
until kubectl $KUBECONFIG_FLAG get prometheusrules.monitoring.coreos.com --all-namespaces ; do date; sleep 1; echo ""; done
3334

34-
kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/pyrra/crd.yaml
35+
kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/pyrra/crd.yaml

hack/deploy-satellite.sh

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ fi
2626
kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/namespace.yaml
2727
kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/podsecuritypolicy-restricted.yaml
2828

29-
./hack/deploy-crds.sh --kubeconfig $KUBECONFIG
29+
./hack/deploy-crds.sh --kubeconfig "${KUBECONFIG}"
3030

31-
for operatorManifest in $(find monitoring-satellite/manifests/prometheusOperator/ -type f ! -name "*CustomResourceDefinition.yaml");
32-
do
33-
kubectl $KUBECONFIG_FLAG apply -f $operatorManifest
31+
# shellcheck disable=SC2044
32+
for operatorManifest in $(find monitoring-satellite/manifests/prometheusOperator/ -type f ! -name "*CustomResourceDefinition.yaml");
33+
do
34+
kubectl $KUBECONFIG_FLAG apply -f "${operatorManifest}"
3435
done
3536

3637
kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/prometheus/
@@ -43,4 +44,4 @@ kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/alertmanager/
4344
kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/otelCollector/
4445
kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/pyrra/
4546
kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/blackboxExporter/
46-
kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/probers/
47+
kubectl $KUBECONFIG_FLAG apply -f monitoring-satellite/manifests/probers/

hack/generate.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -o pipefail
77

88
while getopts ":e:" option; do
99
case $option in
10-
e)
10+
e)
1111
environment=$OPTARG;;
1212
\?) # Invalid option
1313
echo "Error: Invalid option"
@@ -106,7 +106,7 @@ jsonnet -c -J vendor -m monitoring-satellite/manifests \
106106
stackdriver: {
107107
clientEmail: '[email protected]',
108108
defaultProject: 'google-project',
109-
privateKey:
109+
privateKey:
110110
|||
111111
multiline
112112
fake
@@ -142,7 +142,7 @@ jsonnet -c -J vendor -m monitoring-central/manifests \
142142
stackdriver: {
143143
clientEmail: '[email protected]',
144144
defaultProject: 'google-project',
145-
privateKey:
145+
privateKey:
146146
|||
147147
multiline
148148
fake

hack/prepare-kind.sh

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/bin/bash
22

3+
# shellcheck disable=SC2230
34
which kind
4-
if [[ $? != 0 ]]; then
5+
if [[ ! $? ]]; then
6+
# shellcheck disable=SC2016
57
echo 'kind not available in $PATH, installing latest kind'
68
# Install latest kind
79
curl -s https://api.github.com/repos/kubernetes-sigs/kind/releases/latest \
@@ -11,11 +13,13 @@ if [[ $? != 0 ]]; then
1113
| wget -qi -
1214
sudo mv kind-linux-amd64 /usr/bin/kind && sudo chmod +x /usr/bin/kind
1315
rm -f kind-linux-amd64*
16+
binpath=$PATH:$(pwd)/tmp/bin
17+
export PATH=$binpath
1418
fi
1519

1620
cluster_created=$(kind get clusters 2>&1)
17-
if [[ "$cluster_created" == "No kind clusters found." ]]; then
18-
kind create cluster --config $PWD/.github/workflows/kind/config.yml
21+
if [[ "$cluster_created" == "No kind clusters found." ]]; then
22+
kind create cluster --config "${PWD}"/.github/workflows/kind/config.yml
1923
else
20-
echo "Cluster '$cluster_created' already present"
21-
fi
24+
echo "Cluster ${cluster_created} already present"
25+
fi

hack/tools.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ import (
99
_ "github.com/google/go-jsonnet/cmd/jsonnet"
1010
_ "github.com/google/go-jsonnet/cmd/jsonnetfmt"
1111
_ "github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb"
12-
)
12+
)

installer/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
installer
2-
monitoring-satellite.yaml
2+
monitoring-satellite.yaml
33
config.yaml

installer/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ generate: installer
2525
.PHONY: deploy-satellite
2626
apply-satellite: monitoring-satellite.yaml
2727
kubectl create ns monitoring-satellite || true
28-
kubectl apply -f monitoring-satellite.yaml
28+
kubectl apply -f monitoring-satellite.yaml

installer/cmd/render.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"fmt"
5-
"github.com/gitpod-io/observability/installer/pkg/components"
65
"io"
76
"io/ioutil"
87
"os"
@@ -12,6 +11,7 @@ import (
1211
"sigs.k8s.io/yaml"
1312

1413
"github.com/gitpod-io/observability/installer/pkg/common"
14+
"github.com/gitpod-io/observability/installer/pkg/components"
1515
"github.com/gitpod-io/observability/installer/pkg/config"
1616
)
1717

@@ -98,7 +98,6 @@ func loadConfig(cfgFN string) (rawCfg interface{}, cfg *config.Config, err error
9898
cfgBytes, err := ioutil.ReadFile(cfgFN)
9999
if err != nil {
100100
panic(fmt.Sprintf("couldn't read file %s, %s", cfgFN, err))
101-
102101
}
103102
overrideConfig = string(cfgBytes)
104103
}

0 commit comments

Comments
 (0)