github.com/thanos-io/thanos@v0.32.5/CONTRIBUTING.md (about) 1 # Contributing 2 3 This document explains the process of contributing to the Thanos project. 4 5 First of all please follow the [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) in all your interactions within the project. 6 7 ## Thanos Philosophy 8 9 The philosophy of Thanos and our community borrows heavily from UNIX philosophy and the Golang programming language. 10 11 * Each subcommand should do one thing and do it well. 12 * eg. Thanos query proxies incoming calls to known store API endpoints merging the result 13 * Write components that work together. 14 * e.g. blocks should be stored in native Prometheus format 15 * Make it easy to read, write, and run components. 16 * e.g. reduce complexity in system design and implementation 17 18 ## Feedback / Issues 19 20 If you encounter any issue or you have an idea to improve, please: 21 22 * Search through Google and [existing open and closed GitHub Issues](https://github.com/thanos-io/thanos/issues) for the answer first. If you find a relevant topic, please comment on the issue. 23 * If none of the issues are relevant, please add an issue to [GitHub issues](https://github.com/thanos-io/thanos/issues). Please provide any relevant information as suggested by the Issue template. 24 * If you have a quick question you might want to also ask on #thanos or #thanos-dev slack channel in the CNCF workspace. We recommend using GitHub issues for issues and feedback, because GitHub issues are trackable. 25 26 If you encounter a security vulnerability, please refer to [Reporting a Vulnerability process](SECURITY.md#reporting-a-vulnerability) 27 28 ## Adding New Features / Components 29 30 When contributing a complex change to Thanos repository, please discuss the change you wish to make within a Github issue, in Slack, or by another method with the owners of this repository before making the change. 31 32 Adding a large new feature or/and component to Thanos should be done by first creating a [proposal](docs/proposals-done) document outlining the design decisions of the change, motivations for the change, and any alternatives that might have been considered. 33 34 ## General Naming 35 36 In the code and documentation prefer non-offensive terminology, for example: 37 38 * `allowlist` / `denylist` (instead of `whitelist` / `blacklist`) 39 * `primary` / `replica` (instead of `master` / `slave`) 40 * `openbox` / `closedbox` (instead of `whitebox` / `blackbox`) 41 42 ## Components Naming 43 44 Thanos is a distributed system comprised of several services and CLI tools as listed [here](cmd/thanos). 45 46 When we refer to them in a technical capacity we use the verbal form: `store`, `compact`, `rule`, `query`, `query-frontend`. This includes: 47 48 * Code 49 * Metrics 50 * Commands 51 * Mixin examples: alerts, rules, dashboards 52 * Container names 53 * Flags and configuration 54 * Package names 55 * Log messages, traces 56 57 However, when discussing these components in a more general manner we use the `actor` noun form: `store gateway`, `compactor`, `ruler`, `querier`, `query frontend`. This includes areas like: 58 59 * Public communication 60 * Documentation 61 * Code comments 62 63 ## Development 64 65 The following section explains various suggestions and procedures to note during development of Thanos. 66 67 ### Prerequisites 68 69 * It is strongly recommended that you use Linux distributions systems or macOS for development. 70 * Running [WSL 2 (on Windows)](https://learn.microsoft.com/en-us/windows/wsl/) is also possible. Note that if during development you run a local Kubernetes cluster and have a Service with `service.spec.sessionAffinity: ClientIP`, it will break things until it's removed[^windows_xt_recent]. 71 * Go 1.21.x or higher. 72 * Docker (to run e2e tests) 73 * For React UI, you will need a working NodeJS environment and the npm package manager to compile the Web UI assets. 74 75 [^windows_xt_recent]: A WSL 2 kernel recompilation is required to enable the `xt_recent` kernel module, used by `iptables` in `kube-proxy` to implement ClientIP session affinity. See [issue in WSL](https://github.com/microsoft/WSL/issues/7124). 76 77 ### First Steps 78 79 It's key to get familiarized with the style guide and mechanics of Thanos, especially if your contribution touches more than one component of the Thanos distributed system. We recommend: 80 81 * Reading the [getting started docs](docs/getting-started.md) and working through them, or alternatively working through the [Thanos tutorial](https://killercoda.com/thanos). 82 * Familiarizing yourself with our [coding style guidelines.](docs/contributing/coding-style-guide.md). 83 * Familiarizing yourself with the [Makefile](Makefile) commands, for example `format`, `build`, `proto`, `docker` and `test`. `make help` will print most of available commands with relevant details. 84 * To get started, create a codespace for this repository by clicking this 👉 [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=109162639) 85 * A codespace will open in a web-based version of Visual Studio Code. The [dev container](.devcontainer/devcontainer.json) is fully configured with software needed for this project. 86 * **Note**: Dev containers is an open spec which is supported by [GitHub Codespaces](https://github.com/codespaces) and [other tools](https://containers.dev/supporting). 87 * Spin up a prebuilt dev environment using Gitpod.io [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/thanos-io/thanos) 88 * In case you want to develop the project locally, install **Golang** in your machine. Here is a nice [gist](https://gist.github.com/nikhita/432436d570b89cab172dcf2894465753) for this purpose. 89 * You can run an interactive example, which populates some data as well, by following the steps mentioned [here](https://github.com/thanos-io/thanos/blob/main/tutorials/interactive-example/README.md). 90 91 ### Installing Project locally in your machine 92 93 * Find any directory in your system your want Thanos repo in. e.g `~/Repos` - 94 * `cd ~/Repos` 95 * Make sure that the GOBIN, GOPATH and GOPROXY (useful) environment variables are set and that GOBIN is included in your PATH. You may use `GOPROXY=https://goproxy.cn` as an alternative if you cannot visit `https://proxy.golang.org`. For example - 96 97 ``` 98 export GOBIN="~/Repos/thanos/.bin" # It's nice to have local tooling installed and stored locally. 99 100 export GOPATH="~/Repos/thanosgopath" # Use if you want to have an isolated directory for deps, otherwise, the directory where you have installed golang will be used. 101 102 export GOPROXY="https://proxy.golang.org" 103 export PATH="$GOBIN:$PATH" 104 ``` 105 106 * Consider adding the environment variables to your host machine (e.g `/.bashrc` or [`.envrc`](https://direnv.net/)) file so that those environment variables are persisted across sessions. 107 * Clone Thanos inside the `~/Repos` folder - 108 * For HTTPS - `git clone https://github.com/thanos-io/thanos.git` 109 * For SSH - `git clone git@github.com:thanos-io/thanos.git` 110 * Once installed, you can run `make help` inside Thanos folder for getting a list of helper commands which are provided for making development easy for you :) 111 112 ### Building/Running/Developing 113 114 * Run `make help` for getting a list of helper commands that will make your development life much more easy. Especially consider using `make lint` often. It provides auto **linting** and **formatter** for making sure the code quality meets the standards of contribution. 115 * Usually, while sending in a PR `make build`, `make format`, `make lint`, `make test`, `make docs`, `make check-docs`, `make quickstart` are the most used commands while developing Thanos. 116 * When you run `make build` from Thanos repo root, code is compiled and a binary named `thanos` is created and built into your `$GOBIN` or `$GOPATH/bin`. 117 * In case you are working on a component of Thanos, you would love it if you don’t have to set up the yaml configuration for Prometheus and other components, before you start running the component. This is a repetitive task, and the Thanos Community has provided commands/script for automating the running of components - 118 * Run `make quickstart` for spinning up all components of Thanos quickly. 119 * If you want to run specific components instead of all, feel free to use and edit - [quickstart.sh](https://github.com/thanos-io/thanos/blob/b08c0ea62abfe4dcf1400da0e37598f0cd8fa8cf/scripts/quickstart.sh) 120 121 ### Pull Request Process 122 123 **Forking and Creating the local setup for developing Thanos** 124 125 Start your development with forking `thanos-io/thanos.git` . Here are sample steps to setup your development environment: 126 127 ```console 128 $ GOPATH=$(go env GOPATH) 129 $ mkdir -p $GOPATH/src/github.com/thanos-io 130 $ cd $GOPATH/src/github.com/thanos-io 131 $ git clone https://github.com/<your_github_id>/thanos.git 132 $ cd thanos 133 $ git remote add upstream https://github.com/thanos-io/thanos.git 134 $ git remote update 135 $ git merge upstream/main 136 $ make build 137 $ export PATH=$PATH:$GOPATH/bin 138 $ thanos -h 139 ``` 140 141 **Signing your work: DCO (Developer Certificate of Origin) Process.** 142 143 * By contributing to this project you agree to the [Developer Certificate of Origin](https://developercertificate.org/)(DCO). This document was created by the Linux Kernel community and is a simple statement that you, as a contributor, have the legal right to make the contribution. 144 * To signoff, you need to add `Signed-off-by: Your Name <your email id>` at the end of your commit messages. You can do this using [`git commit -s`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--s). For example: 145 146 ``` 147 $ git commit -s -m 'This is my commit message' 148 ``` 149 * You can also alias `commit` as `commit -s` in your `~/.gitconfig` to signoff all your future commits. 150 * If you have authored an unsigned commit, you can update it using `git commit --amend --signoff`. If you've pushed your changes to GitHub already you'll need to force push your branch after this with `git push -f`. 151 152 1. Keep PRs as small as possible. For each of your PRs, you create a new branch based on the latest main. Chain them if needed (base one PR on other PRs). You can read more details about the workflow from [here](https://gist.github.com/Chaser324/ce0505fbed06b947d962). 153 154 ```console 155 $ git checkout main 156 $ git remote update 157 $ git merge upstream/main 158 $ git checkout -b <your_branch_for_new_pr> 159 $ make build 160 $ <Iterate your development> 161 $ git push origin <your_branch_for_new_pr> 162 ``` 163 164 **Tests your changes** 165 166 **Formatting** 167 168 First of all, fall back to `make help` to see all availible commands. There are a few checks that happen when making a PR and these need to pass. We can make sure locally before making the PR by using commands that are related to your changes: 169 - `make docs` generates, formats and cleans up white noise. 170 - `make changed-docs` does same as above, but just for changed docs by checking `git diff` on which files are changed. 171 - `make check-docs` generates, formats, cleans up white noise and checks links. Since it can be annoying to wait on link check results - it takes forever - to skip the check, you can use `make docs`). 172 - `make format` formats code 173 174 If you only made documentation changes, which do not include a link, you will be fine by using `make docs`. If you also changed some code, run `make format` as well. 175 176 **Updating your branch** 177 178 It is a good practice to keep your branch updated by rebasing your branch to main. 179 * Update your main - `git checkout main; git pull <remote_name> main` 180 * Rebase your main - `git rebase -i main` 181 182 **Changelog and Review Procedure** 183 184 * If your change affects users (adds or removes feature) consider adding the item to the [CHANGELOG](CHANGELOG.md). 185 * You may merge the Pull Request once you have the sign-off of at least one developer with write access, or if you do not have permission to do that, you may request the second reviewer to merge it for you. 186 * If you feel like your PR is waiting too long for a review, feel free to ping the [`#thanos-dev`](https://slack.cncf.io/) channel on our slack for a review! 187 * If you are a new contributor with no write access, you can tag in the respective maintainer for the changes, but be patient enough for the reviews. *Remember, good things take time :)* 188 189 ### Dependency management 190 191 The Thanos project uses [Go modules](https://golang.org/cmd/go/#hdr-Modules__module_versions__and_more) to manage dependencies on external packages. This requires a working Go environment with version 1.11 or greater and git installed. 192 193 To add or update a new dependency, use the `go get` command: 194 195 ```bash 196 # Pick the latest tagged release. 197 go get example.com/some/module/pkg 198 199 # Pick a specific version. 200 go get example.com/some/module/pkg@vX.Y.Z 201 ``` 202 203 Tidy up the `go.mod` and `go.sum` files: 204 205 ```bash 206 make deps 207 git add go.mod go.sum 208 git commit 209 ``` 210 211 You have to commit the changes to `go.mod` and `go.sum` before submitting the pull request. 212 213 ### Running Tests 214 215 * Thanos provides make commands that help you run the tests locally. 216 * If you don't have a live object store ready, you can use the `make test-local` command. 217 * **NOTE**: This command skips tests against live object storage systems by specifying environment variables; this causes the store-specific tests to be run against memory and filesystem object storage types only. The CI tests run uses GCS, AWS and Swift. 218 * Not specifying these variables will result in auth errors against GCS, AWS, Azure, COS etc. 219 * If you have a decent hardware to run the tests, you can run them locally. 220 * If you want to run the tests once in a while, it is suitable for you to send in a PR, the built in CI/CD setup runs the tests for you, which is nice for once in a while run. 221 * `make test`: Runs all Thanos Go unit tests against each supported version of Prometheus. This excludes tests in `./test/e2e`. 222 * `make test-local`: Runs test excluding tests for ALL object storage integrations. 223 * `make test-e2e`: Runs all Thanos e2e docker-based e2e tests from test/e2e. Required access to docker daemon. 224 * `make test-e2e-local`: Runs all thanos e2e tests locally. 225 226 ### Advanced testing 227 228 At some point during development it is useful, in addition to running unit or e2e tests, to run and play with Thanos components manually. While you can run any component manually by crafting specific flags for a test setup, there are already some nice tools and scripts available. Consider the following methods: 229 230 * `make quickstart`: this command spins up a simple setup of all Thanos components. 231 * `make test-e2e`: the e2e tests cover most of the setups and functionality Thanos offers. It's extremely easy to add `time.Sleep(10* time.Minute)` at certain points in the tests (e.g for compactor [here](https://github.com/thanos-io/thanos/blob/8f492a9f073f819019dd9f044e346a1e1fa730bc/test/e2e/compact_test.go#L379)). This way when you run `make test-e2e`, the test will sleep for some time, allowing you to connect to the setup manually using the port printed in the logs. For example: 232 233 ```bash 234 querier-1: level=info name=querier-1 ts=2020-04-01T12:53:56.101029491Z caller=http.go:56 service=http/server component=query msg="listening for requests and metrics" address=:80 235 querier-1: level=info name=querier-1 ts=2020-04-01T12:53:56.101106805Z caller=intrumentation.go:48 msg="changing probe status" status=ready 236 querier-1: level=info name=querier-1 ts=2020-04-01T12:53:56.101290229Z caller=grpc.go:106 service=gRPC/server component=query msg="listening for StoreAPI gRPC" address=:9091 237 Ports for container: e2e_test_store_gateway-querier-1 Mapping: map[80:32825 9091:32824] 238 ``` 239 240 This output indicates that the HTTP (`80`) endpoint will be available on `http://localhost:32825`. You can quickly craft your own test case with our framework as well! 241 242 NOTE: `make docker` has to work in order for `make test-e2e` to run. This currently might not work properly on macOS.