Skip to content

Commit

Permalink
Add pre-commit hooks and fix lint on all required files to pass the t…
Browse files Browse the repository at this point in the history
…ests (kube-burner#318)
  • Loading branch information
morenod authored May 24, 2023
1 parent 8265762 commit d60a612
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 109 deletions.
27 changes: 17 additions & 10 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@ about: Create a report to help us improve
title: "[BUG]"
labels: bug
assignees: ''

---

**Output of `kube-burner `version**
# Bug Description

## **Output of `kube-burner` version**

## **Describe the bug**

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
## **To Reproduce**

Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
1. Click on '....'
1. Scroll down to '....'
1. See error

## **Expected behavior**

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots or output**
## **Screenshots or output**

If applicable, add screenshots or kube-burner output to help explain your problem.

**Additional context**
## **Additional context**

Add any other context about the problem here.
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.52.2
hooks:
- id: golangci-lint
args: [--timeout=5m]
- repo: https://github.com/markdownlint/markdownlint
rev: v0.12.0
hooks:
- id: markdownlint
args: [-r, ~MD013] # MD013 Line length
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: shellcheck
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-json
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

.PHONY: build clean test help images push manifest manifest-build
.PHONY: build lint clean test help images push manifest manifest-build all


ARCH ?= amd64
Expand Down Expand Up @@ -28,6 +28,7 @@ help:
@echo "Commands for $(BIN_PATH):"
@echo
@echo 'Usage:'
@echo ' make lint Install and execute pre-commit'
@echo ' make clean Clean the compiled binaries'
@echo ' [ARCH=arch] make build Compile the project for arch, default amd64'
@echo ' [ARCH=arch] make install Installs kube-burner binary in the system, default amd64'
Expand All @@ -44,7 +45,11 @@ $(BIN_PATH): $(SOURCES)
GOARCH=$(ARCH) CGO_ENABLED=$(CGO) go build -v -ldflags "-X $(KUBE_BURNER_VERSION).GitCommit=$(GIT_COMMIT) -X $(KUBE_BURNER_VERSION).BuildDate=$(BUILD_DATE) -X $(KUBE_BURNER_VERSION).Version=$(VERSION)" -o $(BIN_PATH) ./cmd/kube-burner

lint:
golangci-lint run
@echo -e "\n\033[2mUpdating pre-commit hooks..\033[0m"
pre-commit autoupdate
@echo "Executing pre-commit for all files"
pre-commit run --all-files
@echo "pre-commit executed."

clean:
test ! -e $(BIN_DIR) || rm -Rf $(BIN_PATH)
Expand All @@ -70,4 +75,3 @@ manifest-build:
for arch in $(MANIFEST_ARCHS); do \
$(ENGINE) manifest add $(CONTAINER_NAME) $(CONTAINER_NAME)-$${arch}; \
done

12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<img src="./media/logo/kube-burner-logo.png" width="60%">
![Kube-burner Logo](./media/logo/kube-burner-logo.png)

[![Build Status](https://github.com/cloud-bulldozer/kube-burner/workflows/Go/badge.svg?branch=master)](https://github.com/cloud-bulldozer/kube-burner/actions?query=workflow%3AGo)
[![Go Report Card](https://goreportcard.com/badge/github.com/cloud-bulldozer/kube-burner)](https://goreportcard.com/report/github.com/cloud-bulldozer/kube-burner)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

# What is Kube-burner?
# What is Kube-burner

Kube-burner is a tool aimed at stressing kubernetes clusters. The main functionallity it provides can be summarized in these three steps:

Expand All @@ -23,7 +23,7 @@ But it also provides other features like

## Documentation

Documentation is available at https://cloud-bulldozer.github.io/kube-burner/
Documentation is [available here](https://cloud-bulldozer.github.io/kube-burner/)

## Downloading Kube-burner

Expand All @@ -32,3 +32,9 @@ In case you want to start tinkering with Kube-burner now:
- You can find the binaries in the [releases section of the repository](https://github.com/cloud-bulldozer/kube-burner/releases).
- There's also a container image available at [quay](https://quay.io/repository/cloud-bulldozer/kube-burner?tab=tags).
- Example configuration files can be found at the [examples directory](./examples).

## Contributing Guidelines, CI, and Code Style

Please read the [Contribution Guidelines](docs/ci.md) before contributing to this project. It provides information on how to contribute, guidelines for setting an environment a CI checks to be done before commiting code.

This project utilizes a Continuous Integration (CI) pipeline to ensure code quality and maintain project standards. The CI process automatically builds, tests, and verifies the project on each commit and pull request.
29 changes: 14 additions & 15 deletions docs/alerting.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Alerting

Kube-burner includes an alert mechanism able to evaluate Prometheus expressions after the end of the latest Kube-burner's job.
Kube-burner includes an alert mechanism able to evaluate Prometheus expressions after the end of the latest Kube-burner's job.

## Configuration

Expand All @@ -9,8 +9,8 @@ Alerting is configured through a configuration file pointed by the flag `--alert
```yaml
- expr: avg_over_time(histogram_quantile(0.99, rate(etcd_disk_wal_fsync_duration_seconds_bucket[2m]))[5m:]) > 0.01
description: 5 minutes avg. etcd fsync latency on {{$labels.pod}} higher than 10ms {{$value}}
severity: error
severity: error

- expr: avg_over_time(histogram_quantile(0.99, rate(etcd_network_peer_round_trip_time_seconds_bucket[5m]))[5m:]) > 0.1
description: 5 minutes avg. etcd netowrk peer round trip on {{$labels.pod}} higher than 100ms {{$value}}
severity: error
Expand All @@ -28,7 +28,6 @@ Alarm can be configured with a severity. Each one with different effects. At the
- error: Prints a error message with the alarm description to stdout and makes kube-burner rc = 1
- critical: Prints a fatal message with the alarm description to stdout and exits execution immediately with rc != 0


### Using the elapsed variable

There's a special go-template variable that can be used within the prometheus expression, the variable **elapsed** is set to the value of the job duration (or the range given to check-alerts). This variable is especially useful in expressions using [aggregations over time functions](https://prometheus.io/docs/prometheus/latest/querying/functions/#aggregation_over_time).
Expand All @@ -45,22 +44,22 @@ i.e:
It's possible to look for alerts w/o triggering a kube-burner workload. To do so you can use the `check-alerts` option from the CLI, similar to the `index` CLI option, this one accepts the flags `--start` and `--end` to evaluate the alerts at a given time range.

```shell
$ kube-burner check-alerts -u https://prometheus.url.com -t ${token} -a alert-profile.yml
INFO[2020-12-10 11:47:23] Setting log level to info
INFO[2020-12-10 11:47:23] 👽 Initializing prometheus client
$ kube-burner check-alerts -u https://prometheus.url.com -t ${token} -a alert-profile.yml
INFO[2020-12-10 11:47:23] Setting log level to info
INFO[2020-12-10 11:47:23] 👽 Initializing prometheus client
INFO[2020-12-10 11:47:24] 🔔 Initializing alert manager
INFO[2020-12-10 11:47:24] Evaluating expression: 'avg_over_time(histogram_quantile(0.99, rate(etcd_disk_wal_fsync_duration_seconds_bucket[2m]))[5m:]) > 0.01'
ERRO[2020-12-10 11:47:24] Alert triggered at 2020-12-10 11:01:53 +0100 CET: '5 minutes avg. etcd fsync latency on etcd-ip-10-0-213-209.us-west-2.compute.internal higher than 10ms 0.010281314285714311'
INFO[2020-12-10 11:47:24] Evaluating expression: 'avg_over_time(histogram_quantile(0.99, rate(etcd_network_peer_round_trip_time_seconds_bucket[5m]))[5m:]) > 0.1'
INFO[2020-12-10 11:47:24] Evaluating expression: 'increase(etcd_server_leader_changes_seen_total[2m]) > 0'
INFO[2020-12-10 11:47:24] Evaluating expression: 'avg_over_time(histogram_quantile(0.99, rate(etcd_disk_wal_fsync_duration_seconds_bucket[2m]))[5m:]) > 0.01'
ERRO[2020-12-10 11:47:24] Alert triggered at 2020-12-10 11:01:53 +0100 CET: '5 minutes avg. etcd fsync latency on etcd-ip-10-0-213-209.us-west-2.compute.internal higher than 10ms 0.010281314285714311'
INFO[2020-12-10 11:47:24] Evaluating expression: 'avg_over_time(histogram_quantile(0.99, rate(etcd_network_peer_round_trip_time_seconds_bucket[5m]))[5m:]) > 0.1'
INFO[2020-12-10 11:47:24] Evaluating expression: 'increase(etcd_server_leader_changes_seen_total[2m]) > 0'
INFO[2020-12-10 11:47:24] Evaluating expression: 'avg_over_time(histogram_quantile(0.99, sum(apiserver_request_duration_seconds_bucket{apiserver="kube-apiserver",verb=~"POST|PUT|DELETE|PATCH|CREATE"}) by (verb,resource,subresource,le))[5m
:]) > 1'
:]) > 1'
INFO[2020-12-10 11:47:25] Evaluating expression: 'avg_over_time(histogram_quantile(0.99, sum(rate(apiserver_request_duration_seconds_bucket{apiserver="kube-apiserver",verb="GET",scope="resource"}[2m])) by (verb,resource,subresource,le))[5
m:]) > 1'
m:]) > 1'
INFO[2020-12-10 11:47:25] Evaluating expression: 'avg_over_time(histogram_quantile(0.99, sum(rate(apiserver_request_duration_seconds_bucket{apiserver="kube-apiserver",verb="LIST",scope="namespace"}[2m])) by (verb,resource,subresource,le))
[5m:]) > 5'
[5m:]) > 5'
INFO[2020-12-10 11:47:26] Evaluating expression: 'avg_over_time(histogram_quantile(0.99, sum(rate(apiserver_request_duration_seconds_bucket{apiserver="kube-apiserver",verb="LIST",scope="cluster"}[2m])) by (verb,resource,subresource,le))[5
m:]) > 30'
m:]) > 30'
INFO[2020-12-10 11:47:27] Evaluating expression: 'avg_over_time(histogram_quantile(0.99,rate(coredns_kubernetes_dns_programming_duration_seconds_bucket[2m]))[5m:]) > 1'
```

Expand Down
83 changes: 83 additions & 0 deletions docs/ci.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Contributing Guidelines

Thank you for considering contributing to this project! Before making any contributions, please take a moment to review the following guidelines to ensure a smooth collaboration process.

## Table of Contents

- [Pre-commit Checks](#pre-commit-checks)

## Pre-commit Checks

To maintain code quality and catch issues early on, we use pre-commit checks. These checks are automatically executed before each commit to ensure that the code complies with our standards.

Following hooks have been enabled for this project:

- [Golang Lint](https://github.com/golangci/golangci-lint)
- [Shell Lint](https://github.com/jumanjihouse/pre-commit-hooks)
- [Markdown Lint](https://github.com/markdownlint/markdownlint)

Main purpose for pre-commit is to allow developers to pass the Lint Checks before commiting the code. Same checks will be executed on all the commits once they are pushed to GitHub

### Installation

To enable pre-commit checks locally, follow these steps:

1. Install [pre-commit](https://pre-commit.com/) by running the following command:

```shell
pip install pre-commit
```

1. `gem` is required for running the Markdown Linter, installation will depends on your Operating System, for example, on Fedora:

```shell
yum install rubygems
```

1. Initialize pre-commit on the repo:

```shell
pre-commit install
```

### Executing Manually

To run pre-commit manually for all files, you can use `make lint`

```shell
$ make lint
```

Or you can run against an especific file:

```shell
$ pre-commit run --files README.md
golangci-lint........................................(no files to check)Skipped
Markdownlint.............................................................Passed
```

```shell
$ pre-commit run --files ./cmd/kube-burner/kube-burner.go
golangci-lint............................................................Passed
Markdownlint.........................................(no files to check)Skipped
```

```shell
$ pre-commit run --all-files
golangci-lint............................................................Passed
Markdownlint.............................................................Passed
```

Using master as rev is not supported anymore on pre-commit, so reference has been pointed to the last version available.

Hooks can be updated using `pre-commit autoupdate`:

```shell
$ pre-commit autoupdate
[WARNING] The 'rev' field of repo 'https://github.com/golangci/golangci-lint' appears to be a mutable reference (moving tag / branch). Mutable references are never updated after first install and are not supported. See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details. Hint: `pre-commit autoupdate` often fixes this.
[WARNING] The 'rev' field of repo 'https://github.com/markdownlint/markdownlint' appears to be a mutable reference (moving tag / branch). Mutable references are never updated after first install and are not supported. See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details. Hint: `pre-commit autoupdate` often fixes this.
[WARNING] The 'rev' field of repo 'https://github.com/jumanjihouse/pre-commit-hooks' appears to be a mutable reference (moving tag / branch). Mutable references are never updated after first install and are not supported. See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details. Hint: `pre-commit autoupdate` often fixes this.
[https://github.com/golangci/golangci-lint] updating master -> v1.52.2
[https://github.com/markdownlint/markdownlint] updating master -> v0.12.0
[https://github.com/jumanjihouse/pre-commit-hooks] updating master -> 3.0.0
```
10 changes: 5 additions & 5 deletions docs/cli.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CLI

kube-burner is tool written in golang that can be used to stress kubernetes clusters by creating, deleting and patching resources at a
kube-burner is tool written in golang that can be used to stress kubernetes clusters by creating, deleting and patching resources at a
given rate. The actions taken by this tool are highly custimizable, and their available subcommands are detailed below:

```console
Expand Down Expand Up @@ -54,25 +54,25 @@ This is the main subcommand, it triggers a new kube-burner benchmark and it supp
With the above, triggering kube-burner would be as simple as:

```console
$ kube-burner init -c cfg.yml -u https://prometheus-k8s-openshift-monitoring.apps.rsevilla.stress.mycluster.example.com -t ${token} --uuid 67f9ec6d-6a9e-46b6-a3bb-065cde988790`
kube-burner init -c cfg.yml -u https://prometheus-k8s-openshift-monitoring.apps.rsevilla.stress.mycluster.example.com -t ${token} --uuid 67f9ec6d-6a9e-46b6-a3bb-065cde988790`
```

Kube-burner also supports remote configuration files served by a web server, to use it, rather than a path pass a URL like below:

```console
$ kube-burner init -c http://web.domain.com:8080/cfg.yml -t ${token} --uuid 67f9ec6d-6a9e-46b6-a3bb-065cde988790`
kube-burner init -c http://web.domain.com:8080/cfg.yml -t ${token} --uuid 67f9ec6d-6a9e-46b6-a3bb-065cde988790`
```

If you have no interest in collecting prometheus metrics, kube-burner can also be launched w/o any prometheus reference to disable metrics collection.

```console
$ kube-burner init -c cfg.yml --uuid 67f9ec6d-6a9e-46b6-a3bb-065cde988790`
kube-burner init -c cfg.yml --uuid 67f9ec6d-6a9e-46b6-a3bb-065cde988790`
```

To scrape metrics from multiple endpoints init command can be triggered as below.

```console
$ kube-burner init -c cluster-density.yml -e metrics-endpoints.yaml
kube-burner init -c cluster-density.yml -e metrics-endpoints.yaml
```

And a metrics-endpoints.yaml file with valid keys for the `init` command would look something like this.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/cloud-bulldozer/kube-burner)](https://goreportcard.com/report/github.com/cloud-bulldozer/kube-burner)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

# What's this?
# What's this

Kube-burner is a tool aimed at stressing kubernetes clusters. The main functionallity it provides can be summarized in these three steps:

Expand Down
Loading

0 comments on commit d60a612

Please sign in to comment.