-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from appuio/feat/odoo16
Report to Odoo16 instead of intermediate postgresql
- Loading branch information
Showing
100 changed files
with
512 additions
and
7,435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ dist/ | |
.github/release-notes.md | ||
|
||
# Build | ||
appuio-cloud-reporting | ||
appuio-reporting | ||
*.out | ||
|
||
# Docs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,36 @@ | ||
# APPUiO Cloud Reporting | ||
# APPUiO Reporting | ||
|
||
[![Build](https://img.shields.io/github/workflow/status/appuio/appuio-cloud-reporting/Test)][build] | ||
![Go version](https://img.shields.io/github/go-mod/go-version/appuio/appuio-cloud-reporting) | ||
[![Version](https://img.shields.io/github/v/release/appuio/appuio-cloud-reporting)][releases] | ||
[![Maintainability](https://img.shields.io/codeclimate/maintainability/appuio/appuio-cloud-reporting)][codeclimate] | ||
[![Coverage](https://img.shields.io/codeclimate/coverage/appuio/appuio-cloud-reporting)][codeclimate] | ||
[![GitHub downloads](https://img.shields.io/github/downloads/appuio/appuio-cloud-reporting/total)][releases] | ||
[![Build](https://img.shields.io/github/workflow/status/appuio/appuio-reporting/Test)][build] | ||
![Go version](https://img.shields.io/github/go-mod/go-version/appuio/appuio-reporting) | ||
[![Version](https://img.shields.io/github/v/release/appuio/appuio-reporting)][releases] | ||
[![Maintainability](https://img.shields.io/codeclimate/maintainability/appuio/appuio-reporting)][codeclimate] | ||
[![Coverage](https://img.shields.io/codeclimate/coverage/appuio/appuio-reporting)][codeclimate] | ||
[![GitHub downloads](https://img.shields.io/github/downloads/appuio/appuio-reporting/total)][releases] | ||
|
||
[build]: https://github.com/appuio/appuio-cloud-reporting/actions?query=workflow%3ATest | ||
[releases]: https://github.com/appuio/appuio-cloud-reporting/releases | ||
[codeclimate]: https://codeclimate.com/github/appuio/appuio-cloud-reporting | ||
|
||
## Use APPUiO Global instance | ||
|
||
```sh | ||
# Follow the login instructions to get a token | ||
oc login --server=https://api.cloudscale-lpg-2.appuio.cloud:6443 | ||
|
||
# Forward database and thanos to local host | ||
kubectl -n appuio-reporting port-forward svc/reporting-db 5432 & | ||
kubectl --as=cluster-admin -n appuio-thanos port-forward svc/thanos-query 9090 & | ||
|
||
# Check for pending migrations | ||
DB_USER=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.user}' | base64 --decode) | ||
DB_PASSWORD=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.password}' | base64 --decode) | ||
export ACR_DB_URL="postgres://${DB_USER}:${DB_PASSWORD}@localhost/reporting?sslmode=disable" | ||
go run . migrate --show-pending | ||
|
||
# Run a query | ||
go run . report --query-name ping --begin "2022-01-17T09:00:00Z" | ||
|
||
# Connect to the database's interactive terminal | ||
DB_USER=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.user}' | base64 --decode) | ||
export PGPASSWORD=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.password}' | base64 --decode) | ||
psql -U "${DB_USER}" -w -h localhost reporting | ||
``` | ||
|
||
## Local Installation | ||
|
||
```sh | ||
SUPERUSER_PW=$(pwgen 40 1) | ||
|
||
kubectl create ns appuio-reporting | ||
kubectl -n appuio-reporting create secret generic reporting-db-superuser --from-literal=user=reporting-db-superuser "--from-literal=password=${SUPERUSER_PW}" | ||
kubectl -n appuio-reporting apply -k manifests/base | ||
``` | ||
|
||
### Grafana | ||
|
||
There is a Grafana deployment prepared under `manifests/grafana`. | ||
To be able to use the deployment, customize the parameters in `grafana-helm-values.yaml` and run `make` to generate the manifest. | ||
|
||
Add the required Grafana Helm chart using `helm repo add grafana https://grafana.github.io/helm-charts`. | ||
|
||
The deployment requires a secret `grafana-creds` containing the admin username and password: | ||
|
||
```sh | ||
oc -n appuio-reporting create secret generic grafana-creds --from-literal=admin-password=$(pwgen 40 1) --from-literal=admin-user=admin | ||
``` | ||
[build]: https://github.com/appuio/appuio-reporting/actions?query=workflow%3ATest | ||
[releases]: https://github.com/appuio/appuio-reporting/releases | ||
[codeclimate]: https://codeclimate.com/github/appuio/appuio-reporting | ||
|
||
## Usage | ||
|
||
### Run Report | ||
|
||
```sh | ||
kubectl -n appuio-reporting port-forward svc/reporting-db 5432 & | ||
kubectl --as=cluster-admin -n appuio-thanos port-forward svc/thanos-query 9090 & | ||
|
||
DB_USER=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.user}' | base64 --decode) | ||
DB_PASSWORD=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.password}' | base64 --decode) | ||
export ACR_DB_URL="postgres://${DB_USER}:${DB_PASSWORD}@localhost/reporting?sslmode=disable" | ||
|
||
go run . report --query-name ping --begin "2022-01-17T09:00:00Z" | ||
``` | ||
|
||
### Migrate to Most Recent Schema | ||
|
||
```sh | ||
kubectl -n appuio-reporting port-forward svc/reporting-db 5432 & | ||
|
||
DB_USER=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.user}' | base64 --decode) | ||
DB_PASSWORD=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.password}' | base64 --decode) | ||
export ACR_DB_URL="postgres://${DB_USER}:${DB_PASSWORD}@localhost/reporting?sslmode=disable" | ||
|
||
go run . migrate --show-pending | ||
|
||
go run . migrate | ||
``` | ||
|
||
### Connect to the Database | ||
|
||
```sh | ||
kubectl -n appuio-reporting port-forward svc/reporting-db 5432 & | ||
|
||
DB_USER=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.user}' | base64 --decode) | ||
export PGPASSWORD=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.password}' | base64 --decode) | ||
|
||
psql -U "${DB_USER}" -w -h localhost reporting | ||
``` | ||
|
||
## Local Development | ||
|
||
Local development assumes a locally installed PostgreSQL database. | ||
This can be achieved by running `make docker-compose-up`. | ||
See `docker-compose.yml` for the configuration. | ||
|
||
```sh | ||
# Needs to be repeated after a Docker restart | ||
make docker-compose-up | ||
|
||
# Next command asks for a password, it is "reporting" | ||
createdb --username=reporting -h localhost -p 5432 appuio-cloud-reporting-test | ||
|
||
export ACR_DB_URL="postgres://reporting:reporting@localhost/appuio-cloud-reporting-test?sslmode=disable" | ||
|
||
# Required for tests | ||
make ensure-prometheus | ||
|
||
go run . migrate | ||
go run . migrate --seed | ||
go test ./... | ||
|
||
# To connect to the DB: | ||
psql -U reporting -W -h localhost appuio-cloud-reporting-test | ||
``` | ||
# Follow the login instructions to get a token | ||
oc login --server=https://api.cloudscale-lpg-2.appuio.cloud:6443 | ||
|
||
### IDE Integration | ||
# Forward mimir to local host | ||
kubectl --as cluster-admin -nvshn-appuio-mimir service/vshn-appuio-mimir-query-frontend 8080 | ||
|
||
To enable IDE Test/Debug support, `ACR_DB_URL` should be added to the test environment. | ||
# Set environment | ||
export ACR_PROM_URL="http://localhost:8080/prometheus" | ||
export ACR_ORG_ID="appuio-managed-openshift-billing" # mimir organization in which data is stored | ||
export ACR_ODOO_URL=https://test.central.vshn.ch/api/v2/product_usage_report_POST | ||
export ACR_ODOO_OAUTH_TOKEN_URL="https://test.central.vshn.ch/api/v2/authentication/oauth2/token" | ||
export ACR_ODOO_OAUTH_CLIENT_ID="your_client_id" # see https://docs.central.vshn.ch/rest-api.html#_authentication_and_authorization | ||
export ACR_ODOO_OAUTH_CLIENT_SECRET="your_client_secret" | ||
|
||
#### VS Code | ||
# Run a query | ||
go run . report --query 'sum by (label) (metric)' --begin "2023-07-08T13:00:00Z" --product-id "your-odoo-product-id" --instance-jsonnet 'local labels = std.extVar("labels"); "instance-%(label)s" % labels' --unit-id "your_odoo_unit_id" --timerange 1h --item-description-jsonnet '"This is a description."' --item-group-description-jsonnet 'local labels = std.extVar("labels"); "Instance %(label)s" % labels' | ||
|
||
```sh | ||
mkdir -p .vscode | ||
touch .vscode/settings.json | ||
jq -s '(.[0] // {}) | ."go.testEnvVars"."ACR_DB_URL" = $ENV."ACR_DB_URL"' .vscode/settings.json > .vscode/settings.json.i | ||
mv .vscode/settings.json.i .vscode/settings.json | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/appuio/appuio-cloud-reporting/pkg/db" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
const defaultTestForRequiredFlags = "<required>" | ||
|
||
func newDbURLFlag(destination *string) *cli.StringFlag { | ||
return &cli.StringFlag{Name: "db-url", Usage: "Database connection URL in the form of postgres://user@host:port/db-name?option=value", | ||
EnvVars: envVars("DB_URL"), Destination: destination, Required: true, DefaultText: defaultTestForRequiredFlags} | ||
} | ||
const defaultTextForRequiredFlags = "<required>" | ||
const defaultTextForOptionalFlags = "<optional>" | ||
|
||
func newPromURLFlag(destination *string) *cli.StringFlag { | ||
return &cli.StringFlag{Name: "prom-url", Usage: "Prometheus connection URL in the form of http://host:port", | ||
EnvVars: envVars("PROM_URL"), Destination: destination, Value: "http://localhost:9090"} | ||
} | ||
|
||
func queryNames(queries []db.Query) []string { | ||
names := make([]string, len(queries)) | ||
for i := range queries { | ||
names[i] = queries[i].Name | ||
} | ||
return names | ||
func newOdooURLFlag(destination *string) *cli.StringFlag { | ||
return &cli.StringFlag{Name: "odoo-url", Usage: "URL of the Odoo Metered Billing API", | ||
EnvVars: envVars("ODOO_URL"), Destination: destination, Value: "http://localhost:8080"} | ||
} |
Oops, something went wrong.