Skip to content

Commit

Permalink
Merge pull request #64 from vshn/new-billing-cloud
Browse files Browse the repository at this point in the history
New billing cloud
  • Loading branch information
TheBigLee authored Dec 20, 2023
2 parents dcfe10b + 066d295 commit c362853
Show file tree
Hide file tree
Showing 72 changed files with 1,267 additions and 4,056 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,3 @@ jobs:

- name: Run tests
run: make test-integration

golden:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Golden diff
working-directory: component/
run: make test golden-diff-all
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# VSCode
.vscode/

# Goreleaser
/dist/
/.github/release-notes.md
Expand All @@ -17,3 +20,8 @@
# Configuration
env
.env

__debug*

# Golden test that may contain live API keys for local testing
fromenv/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ build-bin: fmt vet ## Build binary
build-docker: ## Build docker image
env CGO_ENABLED=0 GOOS=$(DOCKER_IMAGE_GOOS) GOARCH=$(DOCKER_IMAGE_GOARCH) \
go build -o ${BIN_FILENAME}
$(DOCKER_CMD) build -t $(CONTAINER_IMG) .
$(DOCKER_CMD) build --platform $(DOCKER_IMAGE_GOOS)/$(DOCKER_IMAGE_GOARCH) -t $(CONTAINER_IMG) .

.PHONY: docs-serve
docs-serve: ## Preview the documentation
Expand Down
78 changes: 17 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,35 @@
[build]: https://github.com/vshn/billing-collector-cloudservices/actions?query=workflow%3ATest
[releases]: https://github.com/vshn/billing-collector-cloudservices/releases

Batch job to sync usage data from the Exoscale and Cloudscale API to the [APPUiO Cloud reporting](https://github.com/appuio/appuio-cloud-reporting/) database.
Batch job to sync usage data from the Exoscale and Cloudscale API to Odoo16.

Metrics are collected taking into account product (e.g. `object-storage-storage:exoscale`), source (e.g. `exoscale:namespace`), tenant (as organization) and date time.
Metrics are collected based on [metered billing data flow](https://docs.central.vshn.ch/metered-billing-data-flow.html)

See the [component documentation](https://hub.syn.tools/billing-collector-cloudservices/index.html) for more information.

## APPUiO Cloud vs APPUiO Managed

The tool operates in 2 modes - APPUiO Cloud and APPUiO Managed.
The mode is decided by the environment variable `APPUIO_MANAGED_SALES_ORDER`.
If the sales order is set, the tool assumes that the whole cluster is APPUiO Managed thus changing the business logic accordingly.

## Getting started for developers

In order to run this tool, you need
* An instance of the billing database
* Access to the Exoscale and Cloudscale accounts which has the services to be invoiced
* Access to the Kubernetes cluster which has the claims corresponding to the Exoscale services
* Access to Odoo16 where to send the metrics data

Get all this (see below), and put it all into an 'env' file:

```
export EXOSCALE_API_KEY="..."
export EXOSCALE_API_SECRET="..."
export KUBERNETES_SERVER_URL='https://...'
export KUBERNETES_SERVER_TOKEN='...'
export ACR_DB_URL="postgres://reporting:reporting@localhost/appuio-cloud-reporting-test?sslmode=disable"
export APPUIO_MANAGED_SALES_"..."
export ODOO_OAUTH_CLIENT_SECRET="..."
export ODOO_OAUTH_TOKEN_URL="..."
export ODOO_URL="..."
export CLUSTER_ID="..."
```

Then source the env file and run the client:
Expand All @@ -40,24 +48,11 @@ $ make build

Then, run one of the available commands:

* Object Storage:
```
$ ./billing-collector-cloudservices exoscale objectstorage
```

* DBaaS (runs metrics collector for all supported databases):
* Exoscale DBaaS:
```
$ ./billing-collector-cloudservices exoscale dbaas
```

### Billing Database

Provided that you have Docker installed, you can easily run a local instance of the billing database by getting the [appuio-cloud-reporting](https://github.com/appuio/appuio-cloud-reporting/) repository and running:

```
$ make start-acr
```

### Create Resources in Lab Cluster to test metrics collector

You can first connect to your cluster and then create a claim for Postgres Database by applying a claim, for example:
Expand All @@ -70,20 +65,13 @@ metadata:
name: exoscale-postgres-lab-test-1
spec:
parameters:
backup:
timeOfDay: '13:00:00'
maintenance:
dayOfWeek: monday
timeOfDay: "12:00:00"
size:
plan: hobbyist-2
service:
majorVersion: "14"
writeConnectionSecretToRef:
name: postgres-connection-details
```

Once the database is created and `Ready`, you can run locally the command:
Once the database is created and `Ready`, you can run locally the command with the required env variables:
```
$ ./billing-collector-cloudservices exoscale dbaas
```
Expand All @@ -98,36 +86,9 @@ You can get your Exoscale API key and secret from the Exoscale web UI. Be sure t

The token should be restricted to the 'sos' and 'dbaas' services.

### Kubernetes API token

The following instructions work for OpenShift via the 'oc' utility. Not all of them will work with kubectl.

The commands assume that you are logged in to the Kubernetes cluster you want to use, and your working directory needs to be this git repository.

Instructions for OpenShift >=4.11:
```
$ cd billing-collector-cloudservices
$ oc -n default --as cluster-admin apply -f clusterrole.yaml
$ oc -n default --as cluster-admin create serviceaccount vshn-billing-collector-cloudservices
$ oc --as cluster-admin adm policy add-cluster-role-to-user vshn-billing-collector-cloudservices system:serviceaccount:default:vshn-billing-collector-cloudservices
$ oc -n default --as cluster-admin apply -f clusterrole-secret.yaml
$ oc -n default --as cluster-admin get secret vshn-billing-collector-cloudservices-secret -o jsonpath='{.data.token}' | base64 -d
```

Instructions for OpenShift <=4.10:
```
$ cd billing-collector-cloudservices
$ oc -n default --as cluster-admin apply -f clusterrole.yaml
$ oc -n default --as cluster-admin create serviceaccount vshn-billing-collector-cloudservices
$ oc --as cluster-admin adm policy add-cluster-role-to-user vshn-billing-collector-cloudservices system:serviceaccount:default:vshn-billing-collector-cloudservices
$ oc -n default --as cluster-admin serviceaccounts get-token vshn-billing-collector-cloudservices
```

The last command will print out your token without trailing newline; be sure to copy the correct part of the output.

### Integration tests

Integration tests create an envtest cluster and store data in an ACR (appuio-cloud-reporting) database. This is all automated when running:
Integration tests create an envtest cluster and export the metrics locally. This is all automated when running:

```bash
$ make test-integration
Expand All @@ -136,11 +97,6 @@ $ make test-integration
To run integration tests in your IDE of choice, be sure to set build tag `integration` and the following env variables:

```bash
ACR_DB_URL=postgres://reporting:reporting@localhost/appuio-cloud-reporting-test?sslmode=disable
CLOUDSCALE_API_TOKEN=<REDACTED>
EXOSCALE_API_KEY=<REDACTED>
EXOSCALE_API_SECRET=<REDACTED>

# path to directory where the respective go modules are installed. You can also specify the path to the local clone of the respective repositories.
EXOSCALE_CRDS_PATH="$(go list -f '{{.Dir}}' -m github.com/vshn/provider-exoscale)/package/crds)"
CLOUDSCALE_CRDS_PATH="$(go list -f '{{.Dir}}' -m github.com/vshn/provider-cloudscale)/package/crds)"
Expand Down
85 changes: 0 additions & 85 deletions component/Makefile

This file was deleted.

47 changes: 0 additions & 47 deletions component/Makefile.vars.mk

This file was deleted.

13 changes: 0 additions & 13 deletions component/class/billing-collector-cloudservices.yml

This file was deleted.

55 changes: 0 additions & 55 deletions component/class/defaults.yml

This file was deleted.

11 changes: 0 additions & 11 deletions component/component/app.jsonnet

This file was deleted.

Loading

0 comments on commit c362853

Please sign in to comment.