Project: OpenCost (Observability and Analysis / Continuous Optimization)
File: CONTRIBUTING.md

Thanks for your help improving the OpenCost project! There are many ways to contribute to the project, including the following: contributing or providing feedback on the contributing documentation here or to the joining the discussion in the in the channel keep up with community events using our participating in the fortnightly meetings () committing software via the workflow below If you have a question about OpenCost or have encountered problems using it, you can start by asking a question on in the channel or attend the biweekly from the to discuss OpenCost development. This repository's contribution workflow follows a typical open-source model: this repository Work on the forked repository Open a pull request to Follow these steps to build the OpenCost cost-model and UI from source and deploy. The provided build tooling is natively multi-architecture (built images will run on both AMD64 and ARM64 clusters). Dependencies: Docker (with `buildx`) (if you don't want to install it , Just read the `justfile` and run the commands manually) Multi-arch `buildx` builders set up via https://github.com/tonistiigi/binfmt `manifest-tool` via https://github.com/estesp/manifest-tool `npm` (if you want to build the UI) `just build "<repo>/opencost:<tag>"` Edit the in the `kubernetes/opencost.yaml` to `<repo>/opencost:<tag>` Set to the address of your Prometheus server `cd ui && just build "<repo>/opencost-ui:<tag>"` Edit the in the `kubernetes/opencost.yaml` to `<repo>/opencost-ui:<tag>` `kubectl create namespace opencost` `kubectl apply -f kubernetes/opencost --namespace opencost` `kubectl -n opencost port-forward service/opencost 9090 9003` To test, build the OpenCost containers and then push them to a Kubernetes cluster with a running Prometheus. To confirm that the server and UI are running, you can hit to access the OpenCost UI. You can test the server API with `curl http://localhost:9003/allocation/compute -d window=60m -G`. To run locally cd into `cmd/costmodel` and `go run main.go` OpenCost requires a connection to Prometheus in order to operate so setting the environment variable `PROMETHEUSSERVERENDPOINT` is required. In order to expose Prometheus to OpenCost it may be required to port-forward using kubectl to your Prometheus endpoint. For example: ```bash kubectl port-forward svc/prometheus-server 9080:80 ``` This would expose Prometheus on port 9080 and allow setting the environment variable as so: ```bash PROMETHEUSSERVERENDPOINT="http://127.0.0.1:9080" ``` If you want to run with a specific kubeconfig the environment variable `KUBECONFIG` can be used. OpenCost will attempt to connect to your Kubernetes cluster in a similar fashion as kubectl so the env is not required. The order of precedence is `KUBECONFIG` > default kubeconfig file location ($HOME/.kube/config) > in cluster config Example: ```bash export KUBECONFIG=~/.kube/config ``` An example of the full command: ```bash PROMETHEUSSERVERENDPOINT="http://127.0.0.1:9090" go run

``` Testing is provided by the `just test` command which runs unit tests code quality checks To run these tests: Make sure you have a kubeconfig that can point to your cluster, and have permissions to create/modify a namespace called "test" Connect to your the Prometheus OpenCost emits to on localhost:9003: `kubectl port-forward --namespace opencost service/prometheus-server 9003:80` Temporary workaround: Copy the default.json file in this project at cloud/default.json to /models/default.json on the machine your test is running on. TODO: fix this and inject the cloud/default.json path into provider.go. Navigate to cost-model/test Run `go test -timeout 700s` from the testing directory. The tests right now take about 10 minutes (600s) to run because they bring up and down pods and wait for Prometheus to scrape data about them. By contributing to this project, you certify that your contribution was created in whole or in part by you and that you have the right to submit it under the open source license indicated in the project. In other words, please confirm that you, as a contributor, have the legal right to make the contribution. This is enforced on Pull Requests and requires `Signed-off-by` with the email address for the author in the commit message. Please write a commit message with Fixes Issue # if there is an outstanding issue that is fixed. Its okay to submit a PR without a corresponding issue; just please try to be detailed in the description of the problem youre addressing. Please run `go fmt` on the project directory. Lint can be okay (for example, comments on exported functions are nice but not required on the server). Please reach us on in the channel or attend the biweekly from the to discuss OpenCost development. The THIRDPARTYLICENSES.txt file should contain the up-to-date license, copyright, and notice information for dependencies used by Opencost. When adding, updating, or removing dependencies, please update the associate section(s) of the file. For example, the `github.com/opencost/opencost/core` dependency contains the following third party attributions. The license associated with the SPDX identifier should also be included in the attributions file, if it is not already present. ``` == Dependency github.com/opencost/opencost/core == License Type SPDX:Apache-2.0 == Copyright Copyright 2019 - 2022 Stackwatch Incorporated. All Rights Reserved. Copyright 2022 - 2024 Cloud Native Computing Foundation == Notices OpenCost Copyright 2022 - 2024 Cloud Native Computing Foundation This product includes software developed at The Cloud Native Computing Foundation (http://www.cncf.io). The Initial Developer of some parts of the specification and project is Kubecost (http://www.kubecost.com). Copyright 2019 - 2022 Stackwatch Incorporated. All Rights Reserved. ```