Skip to content

Commit

Permalink
Merge pull request #20 from vshn/pricing
Browse files Browse the repository at this point in the history
Add setup instructions and adjust pricing
  • Loading branch information
davidgubler authored Nov 4, 2022
2 parents 95b0d08 + c6793d4 commit 303d2d7
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 9 deletions.
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,71 @@
Batch job to sync usage data from the Exoscale API to the [APPUiO Cloud reporting](https://github.com/appuio/appuio-cloud-reporting/) database.

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


## Getting started for developers

In order to run this tool, you need
* An instance of the billing database
* Access to the Exoscale account which has the services to be invoiced
* Access to the Kubernetes cluster which has the claims corresponding to the Exoscale services

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

```
export EXOSCALE_API_KEY="..."
export EXOSCALE_API_SECRET="..."
export K8S_SERVER_URL='https://...'
export K8S_TOKEN='...'
export ACR_DB_URL="postgres://reporting:reporting@localhost/appuio-cloud-reporting-test?sslmode=disable"
```

Then source the env file and run the client:

```
$ . ./env
$ make build
$ ./exoscale-metrics-collector objectstorage
```

### 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:

```
$ cd appuio-cloud-reporting
$ make docker-compose-up
```

### Exoscale API key and secret

You can get your Exoscale API key and secret from the Exoscale web UI. Be sure to select the correct project.

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 exoscale-metrics-collector
$ oc -n default --as cluster-admin apply -f clusterrole.yaml
$ oc -n default --as cluster-admin create serviceaccount vshn-exoscale-metrics-collector
$ oc --as cluster-admin adm policy add-cluster-role-to-user vshn-exoscale-metrics-collector system:serviceaccount:default:vshn-exoscale-metrics-collector
$ oc -n default --as cluster-admin apply -f clusterrole-secret.yaml
$ oc -n default --as cluster-admin get secret vshn-exoscale-metrics-collector-secret -o jsonpath='{.data.token}' | base64 -d
```

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

The last command will print out your token without trailing newline; be sure to copy the correct part of the output.
7 changes: 7 additions & 0 deletions clusterrole-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
type: kubernetes.io/service-account-token
metadata:
name: vshn-exoscale-metrics-collector-secret
annotations:
kubernetes.io/service-account.name: vshn-exoscale-metrics-collector
4 changes: 0 additions & 4 deletions clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# $ oc --as cluster-admin apply -f clusterrole.yaml
# $ oc -n default --as cluster-admin create serviceaccount vshn-exoscale-metrics-collector
# $ oc --as cluster-admin adm policy add-cluster-role-to-user vshn-exoscale-metrics-collector system:serviceaccount:default:vshn-exoscale-metrics-collector
# $ oc -n default --as cluster-admin serviceaccounts get-token vshn-exoscale-metrics-collector
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
Expand Down
2 changes: 1 addition & 1 deletion component/class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ parameters:
collector:
registry: 'ghcr.io'
repository: 'vshn/exoscale-metrics-collector'
tag: 'v0.2.3'
tag: 'v0.3.0'
# Times in UTC! Don't run job around midnight as exoscale API may return incomplete data
# default: Every day at minute 10 past hour 10, 16 and 20.
schedule: '10 10,16,20 * * *'
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
envFrom:
- secretRef:
name: credentials-collector-cloudscale-lpg-2
image: ghcr.io/vshn/exoscale-metrics-collector:v0.2.3
image: ghcr.io/vshn/exoscale-metrics-collector:v0.3.0
name: exoscale-metrics-collector-backfill
resources: {}
restartPolicy: OnFailure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
envFrom:
- secretRef:
name: credentials-exoscale-metrics-collector
image: ghcr.io/vshn/exoscale-metrics-collector:v0.2.3
image: ghcr.io/vshn/exoscale-metrics-collector:v0.3.0
name: exoscale-metrics-collector-backfill
resources: {}
restartPolicy: OnFailure
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/jmoiron/sqlx v1.3.5
github.com/stretchr/testify v1.8.0
github.com/urfave/cli/v2 v2.20.3
github.com/vshn/cloudscale-metrics-collector v0.3.3
github.com/vshn/cloudscale-metrics-collector v0.4.0
github.com/vshn/provider-exoscale v0.1.0
go.uber.org/zap v1.23.0
k8s.io/apimachinery v0.25.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/vshn/cloudscale-metrics-collector v0.3.3 h1:81y66v4WV1dPYYf+gpPwyxHa2bDb+igSXXUIZF/1vrg=
github.com/vshn/cloudscale-metrics-collector v0.3.3/go.mod h1:Ejyqp4eZDBrjnXJPA66ttA8cI3I06aa6W2CGxV2DB2o=
github.com/vshn/cloudscale-metrics-collector v0.4.0 h1:hhqxPeQBo+nOHuHjlaRxw8i/nlloteIZDq3NccFnRXc=
github.com/vshn/cloudscale-metrics-collector v0.4.0/go.mod h1:Ejyqp4eZDBrjnXJPA66ttA8cI3I06aa6W2CGxV2DB2o=
github.com/vshn/provider-exoscale v0.1.0 h1:2qEYt37BYvTkIvPUYWmZ2pZ7stAy4rGl4CvqTL86CTk=
github.com/vshn/provider-exoscale v0.1.0/go.mod h1:ilQ+p905LOQByfrwPMnm+kfYRoRn8yXax4i1TJaNYhQ=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
product = db.Product{
Source: queryAndZone,
Target: sql.NullString{String: "1402", Valid: true},
Amount: 0.00066,
Amount: 0.000726,
Unit: "GBDay",
During: db.InfiniteRange(),
}
Expand Down

0 comments on commit 303d2d7

Please sign in to comment.