Skip to content

Commit

Permalink
Merge pull request #28 from vshn/add-dbaas-exoscale
Browse files Browse the repository at this point in the history
Support Kafka, Redis, OpenSearch and MySQL DBaaS
  • Loading branch information
zugao authored Dec 2, 2022
2 parents b299ea8 + c1b4507 commit a9e67f0
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 260 deletions.
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ The Service Account connected to this token should have `get` and `list` permiss
type:: string
default:: Required.
The Billing Database URL.
The Billing Database URL.
12 changes: 0 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,6 @@ github.com/urfave/cli/v2 v2.20.3 h1:lOgGidH/N5loaigd9HjFsOIhXSTrzl7tBpHswZ428w4=
github.com/urfave/cli/v2 v2.20.3/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
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/cloudscale-metrics-collector v0.5.2 h1:pGuEnpW/7tZNsk2Vyo+716/OMlgapPTytJGP8/GfjKs=
github.com/vshn/cloudscale-metrics-collector v0.5.2/go.mod h1:+LaljJgQVTZE34xDLahbXv855BI6ugOC5wQEUxxAVS8=
github.com/vshn/provider-exoscale v0.3.0 h1:U40odEMuedpdMgRVlcHATu8VMj7LHsJrFuOF+q6+9zg=
Expand Down Expand Up @@ -602,8 +600,6 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb h1:8tDJ3aechhddbdPAxpycgXHJRMLpk/Ab+aa4OgdN5/g=
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb/go.mod h1:jaDAt6Dkxork7LmZnYtzbRWj0W47D86a3TGe0YHBvmE=
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 h1:lxqLZaMad/dJHMFZH0NiNpiEZI/nhgWhe4wgzpE+MuA=
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -894,18 +890,12 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.25.2 h1:v6G8RyFcwf0HR5jQGIAYlvtRNrxMJQG1xJzaSeVnIS8=
k8s.io/api v0.25.2/go.mod h1:qP1Rn4sCVFwx/xIhe+we2cwBLTXNcheRyYXwajonhy0=
k8s.io/api v0.25.4 h1:3YO8J4RtmG7elEgaWMb4HgmpS2CfY1QlaOz9nwB+ZSs=
k8s.io/api v0.25.4/go.mod h1:IG2+RzyPQLllQxnhzD8KQNEu4c4YvyDTpSMztf4A0OQ=
k8s.io/apiextensions-apiserver v0.25.0 h1:CJ9zlyXAbq0FIW8CD7HHyozCMBpDSiH7EdrSTCZcZFY=
k8s.io/apiextensions-apiserver v0.25.0/go.mod h1:3pAjZiN4zw7R8aZC5gR0y3/vCkGlAjCazcg1me8iB/E=
k8s.io/apimachinery v0.25.2 h1:WbxfAjCx+AeN8Ilp9joWnyJ6xu9OMeS/fsfjK/5zaQs=
k8s.io/apimachinery v0.25.2/go.mod h1:hqqA1X0bsgsxI6dXsJ4HnNTBOmJNxyPp8dw3u2fSHwA=
k8s.io/apimachinery v0.25.4 h1:CtXsuaitMESSu339tfhVXhQrPET+EiWnIY1rcurKnAc=
k8s.io/apimachinery v0.25.4/go.mod h1:jaF9C/iPNM1FuLl7Zuy5b9v+n35HGSh6AQ4HYRkCqwo=
k8s.io/client-go v0.25.2 h1:SUPp9p5CwM0yXGQrwYurw9LWz+YtMwhWd0GqOsSiefo=
k8s.io/client-go v0.25.2/go.mod h1:i7cNU7N+yGQmJkewcRD2+Vuj4iz7b30kI8OcL3horQ4=
k8s.io/client-go v0.25.4 h1:3RNRDffAkNU56M/a7gUfXaEzdhZlYhoW8dgViGy5fn8=
k8s.io/client-go v0.25.4/go.mod h1:8trHCAC83XKY0wsBIpbirZU4NTUpbuhc2JnI7OruGZw=
k8s.io/component-base v0.25.0 h1:haVKlLkPCFZhkcqB6WCvpVxftrg6+FK5x1ZuaIDaQ5Y=
Expand All @@ -919,8 +909,6 @@ k8s.io/utils v0.0.0-20220922133306-665eaaec4324/go.mod h1:OLgZIPagt7ERELqWJFomSt
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/controller-runtime v0.13.0 h1:iqa5RNciy7ADWnIc8QxCbOX5FEKVR3uxVxKHRMc2WIQ=
sigs.k8s.io/controller-runtime v0.13.0/go.mod h1:Zbz+el8Yg31jubvAEyglRZGdLAjplZl+PgtYNI6WNTI=
sigs.k8s.io/controller-runtime v0.13.1 h1:tUsRCSJVM1QQOOeViGeX3GMT3dQF1eePPw6sEE3xSlg=
sigs.k8s.io/controller-runtime v0.13.1/go.mod h1:Zbz+el8Yg31jubvAEyglRZGdLAjplZl+PgtYNI6WNTI=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k=
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
)

// Context contains necessary data that will be save in database
// Context contains necessary data that will be saved in database
type Context struct {
context.Context
Aggregated *Aggregated
Expand Down
20 changes: 20 additions & 0 deletions pkg/database/dbaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
)

const (
queryDBaaSPostgres = string(PostgresDBaaSType) + ":" + provider
queryDBaaSMysql = string(MysqlDBaaSType) + ":" + provider
queryDBaaSOpensearch = string(OpensearchDBaaSType) + ":" + provider
queryDBaaSRedis = string(RedisDBaaSType) + ":" + provider
queryDBaaSKafka = string(KafkaDBaaSType) + ":" + provider
defaultUnitDBaaS = "Instances"
)

// exoscale service types to query billing Database types
var (
billingTypes = map[string]string{
"pg": queryDBaaSPostgres,
"mysql": queryDBaaSMysql,
"opensearch": queryDBaaSOpensearch,
"redis": queryDBaaSRedis,
"kafka": queryDBaaSKafka,
}
)

// DBaaSDatabase contains the Database struct needed with the plan, specific of DBaaS
type DBaaSDatabase struct {
Database
Expand Down
51 changes: 51 additions & 0 deletions pkg/database/kafka.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package database

import (
"database/sql"
"github.com/appuio/appuio-cloud-reporting/pkg/db"
)

// KafkaDBaaSType represents kafka DBaaS type
const KafkaDBaaSType ObjectType = "kafka"

// Available plans for Kafka
var kafkaProductDBaaS = []ProductDBaaS{
{Plan: "startup-2", Target: "1416", Amount: 0.34305},
{Plan: "business-4", Target: "1416", Amount: 0.85131},
{Plan: "business-8", Target: "1416", Amount: 1.64491},
{Plan: "business-16", Target: "1416", Amount: 3.31770},
{Plan: "business-32", Target: "1416", Amount: 6.33919},
{Plan: "premium-6x-8", Target: "1416", Amount: 3.33140},
{Plan: "premium-6x-16", Target: "1416", Amount: 6.35223},
{Plan: "premium-6x-32", Target: "1416", Amount: 11.71154},
{Plan: "premium-9x-8", Target: "1416", Amount: 4.78083},
{Plan: "premium-9x-16", Target: "1416", Amount: 8.80127},
{Plan: "premium-9x-32", Target: "1416", Amount: 17.56341},
{Plan: "premium-15x-8", Target: "1416", Amount: 7.37187},
{Plan: "premium-15x-16", Target: "1416", Amount: 14.67527},
{Plan: "premium-15x-32", Target: "1416", Amount: 25.54634},
{Plan: "premium-30x-8", Target: "1416", Amount: 14.74374},
{Plan: "premium-30x-16", Target: "1416", Amount: 25.61155},
{Plan: "premium-30x-32", Target: "1416", Amount: 51.09267},
}

func generateKafkaProducts() []db.Product {
products := make([]db.Product, 0, len(kafkaProductDBaaS))
for _, p := range kafkaProductDBaaS {
s := dbaasSourceString{
Query: queryDBaaSKafka,
Organization: "*",
Namespace: "*",
Plan: p.Plan,
}
product := db.Product{
Source: s.getSourceString(),
Target: sql.NullString{String: p.Target, Valid: true},
Amount: p.Amount,
Unit: defaultUnitDBaaS,
During: db.InfiniteRange(),
}
products = append(products, product)
}
return products
}
56 changes: 56 additions & 0 deletions pkg/database/mysql.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package database

import (
"database/sql"
"github.com/appuio/appuio-cloud-reporting/pkg/db"
)

// MysqlDBaaSType represents mysql DBaaS type
const MysqlDBaaSType ObjectType = "mysql"

// Available plans for MySQL
var mysqlProductDBaaS = []ProductDBaaS{
{Plan: "hobbyist-2", Target: "1412", Amount: 0.06683},
{Plan: "startup-4", Target: "1412", Amount: 0.15731},
{Plan: "startup-8", Target: "1412", Amount: 0.30889},
{Plan: "startup-16", Target: "1412", Amount: 0.60507},
{Plan: "startup-32", Target: "1412", Amount: 1.10238},
{Plan: "startup-64", Target: "1412", Amount: 2.02408},
{Plan: "startup-128", Target: "1412", Amount: 3.58055},
{Plan: "startup-225", Target: "1412", Amount: 5.65519},
{Plan: "business-4", Target: "1412", Amount: 0.30787},
{Plan: "business-8", Target: "1412", Amount: 0.60525},
{Plan: "business-16", Target: "1412", Amount: 1.17123},
{Plan: "business-32", Target: "1412", Amount: 2.1285},
{Plan: "business-64", Target: "1412", Amount: 3.80662},
{Plan: "business-128", Target: "1412", Amount: 7.30291},
{Plan: "business-225", Target: "1412", Amount: 9.97887},
{Plan: "premium-4", Target: "1412", Amount: 0.44811},
{Plan: "premium-8", Target: "1412", Amount: 0.86957},
{Plan: "premium-16", Target: "1412", Amount: 1.72469},
{Plan: "premium-32", Target: "1412", Amount: 3.14683},
{Plan: "premium-64", Target: "1412", Amount: 5.64105},
{Plan: "premium-128", Target: "1412", Amount: 9.49136},
{Plan: "premium-225", Target: "1412", Amount: 14.84892},
}

func generateMysqlProducts() []db.Product {
products := make([]db.Product, 0, len(mysqlProductDBaaS))
for _, p := range mysqlProductDBaaS {
s := dbaasSourceString{
Query: queryDBaaSMysql,
Organization: "*",
Namespace: "*",
Plan: p.Plan,
}
product := db.Product{
Source: s.getSourceString(),
Target: sql.NullString{String: p.Target, Valid: true},
Amount: p.Amount,
Unit: defaultUnitDBaaS,
During: db.InfiniteRange(),
}
products = append(products, product)
}
return products
}
53 changes: 53 additions & 0 deletions pkg/database/opensearch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package database

import (
"database/sql"
"github.com/appuio/appuio-cloud-reporting/pkg/db"
)

// OpensearchDBaaSType represents opensearch DBaaS type
const OpensearchDBaaSType ObjectType = "opensearch"

// Available plans for OpenSearch
var opensearchProductDBaaS = []ProductDBaaS{
{Plan: "hobbyist-2", Target: "1414", Amount: 0.07875},
{Plan: "startup-4", Target: "1414", Amount: 0.18937},
{Plan: "startup-8", Target: "1414", Amount: 0.37583},
{Plan: "startup-16", Target: "1414", Amount: 0.73911},
{Plan: "startup-32", Target: "1414", Amount: 1.43845},
{Plan: "business-4", Target: "1414", Amount: 0.54946},
{Plan: "business-8", Target: "1414", Amount: 1.08649},
{Plan: "business-16", Target: "1414", Amount: 2.16514},
{Plan: "business-32", Target: "1414", Amount: 4.1663},
{Plan: "premium-6x-8", Target: "1414", Amount: 2.17296},
{Plan: "premium-6x-16", Target: "1414", Amount: 4.18124},
{Plan: "premium-6x-32", Target: "1414", Amount: 7.82587},
{Plan: "premium-9x-8", Target: "1414", Amount: 3.14767},
{Plan: "premium-9x-16", Target: "1414", Amount: 5.8918},
{Plan: "premium-9x-32", Target: "1414", Amount: 11.7388},
{Plan: "premium-15x-16", Target: "1414", Amount: 9.81967},
{Plan: "premium-15x-32", Target: "1414", Amount: 17.55262},
{Plan: "premium-30x-16", Target: "1414", Amount: 17.62729},
{Plan: "premium-30x-32", Target: "1414", Amount: 35.10523},
}

func generateOpensearchProducts() []db.Product {
products := make([]db.Product, 0, len(opensearchProductDBaaS))
for _, p := range opensearchProductDBaaS {
s := dbaasSourceString{
Query: queryDBaaSOpensearch,
Organization: "*",
Namespace: "*",
Plan: p.Plan,
}
product := db.Product{
Source: s.getSourceString(),
Target: sql.NullString{String: p.Target, Valid: true},
Amount: p.Amount,
Unit: defaultUnitDBaaS,
During: db.InfiniteRange(),
}
products = append(products, product)
}
return products
}
104 changes: 26 additions & 78 deletions pkg/database/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,88 +2,36 @@ package database

import (
"database/sql"

"github.com/appuio/appuio-cloud-reporting/pkg/db"
)

type productDBaaS struct {
Plan string
Target string
Amount float64
}

var (
// Hobbyist1 plan
Hobbyist1 = productDBaaS{Plan: "hobbyist-1", Target: "1411", Amount: 0.06148}
// Hobbyist2 plan
Hobbyist2 = productDBaaS{Plan: "hobbyist-2", Target: "1411", Amount: 0.06683}
// Startup4 plan
Startup4 = productDBaaS{Plan: "startup-4", Target: "1411", Amount: 0.15731}
// Startup8 plan
Startup8 = productDBaaS{Plan: "startup-8", Target: "1411", Amount: 0.30889}
// Startup16 plan
Startup16 = productDBaaS{Plan: "startup-16", Target: "1411", Amount: 0.60507}
// Startup32 plan
Startup32 = productDBaaS{Plan: "startup-32", Target: "1411", Amount: 1.10238}
// Startup64 plan
Startup64 = productDBaaS{Plan: "startup-64", Target: "1411", Amount: 2.02408}
// Startup128 plan
Startup128 = productDBaaS{Plan: "startup-128", Target: "1411", Amount: 3.58055}
// Startup225 plan
Startup225 = productDBaaS{Plan: "startup-225", Target: "1411", Amount: 5.65519}
// Business4 plan
Business4 = productDBaaS{Plan: "business-4", Target: "1411", Amount: 0.30787}
// Business8 plan
Business8 = productDBaaS{Plan: "business-8", Target: "1411", Amount: 0.60525}
// Business16 plan
Business16 = productDBaaS{Plan: "business-16", Target: "1411", Amount: 1.17123}
// Business32 plan
Business32 = productDBaaS{Plan: "business-32", Target: "1411", Amount: 2.1285}
// Business64 plan
Business64 = productDBaaS{Plan: "business-64", Target: "1411", Amount: 3.80662}
// Business128 plan
Business128 = productDBaaS{Plan: "business-128", Target: "1411", Amount: 7.30291}
// Business225 plan
Business225 = productDBaaS{Plan: "business-225", Target: "1411", Amount: 9.97887}
// Premium4 plan
Premium4 = productDBaaS{Plan: "premium-4", Target: "1411", Amount: 0.44811}
// Premium8 plan
Premium8 = productDBaaS{Plan: "premium-8", Target: "1411", Amount: 0.86957}
// Premium16 plan
Premium16 = productDBaaS{Plan: "premium-16", Target: "1411", Amount: 1.72469}
// Premium32 plan
Premium32 = productDBaaS{Plan: "premium-32", Target: "1411", Amount: 3.14683}
// Premium64 plan
Premium64 = productDBaaS{Plan: "premium-64", Target: "1411", Amount: 5.64105}
// Premium128 plan
Premium128 = productDBaaS{Plan: "premium-128", Target: "1411", Amount: 9.49136}
// Premium225 plan
Premium225 = productDBaaS{Plan: "premium-225", Target: "1411", Amount: 14.84892}
)
// PostgresDBaaSType represents postgres DBaaS type
const PostgresDBaaSType ObjectType = "postgres"

var postgresProductDBaaS = []productDBaaS{
Hobbyist2,
Startup4,
Startup8,
Startup16,
Startup32,
Startup64,
Startup128,
Startup225,
Business4,
Business8,
Business16,
Business32,
Business64,
Business128,
Business225,
Premium4,
Premium8,
Premium16,
Premium32,
Premium64,
Premium128,
Premium225,
// Available plans for PostgreSQL
var postgresProductDBaaS = []ProductDBaaS{
{Plan: "hobbyist-2", Target: "1411", Amount: 0.06683},
{Plan: "startup-4", Target: "1411", Amount: 0.15731},
{Plan: "startup-8", Target: "1411", Amount: 0.30889},
{Plan: "startup-16", Target: "1411", Amount: 0.60507},
{Plan: "startup-32", Target: "1411", Amount: 1.10238},
{Plan: "startup-64", Target: "1411", Amount: 2.02408},
{Plan: "startup-128", Target: "1411", Amount: 3.58055},
{Plan: "startup-225", Target: "1411", Amount: 5.65519},
{Plan: "business-4", Target: "1411", Amount: 0.30787},
{Plan: "business-8", Target: "1411", Amount: 0.60525},
{Plan: "business-16", Target: "1411", Amount: 1.17123},
{Plan: "business-32", Target: "1411", Amount: 2.1285},
{Plan: "business-64", Target: "1411", Amount: 3.80662},
{Plan: "business-128", Target: "1411", Amount: 7.30291},
{Plan: "business-225", Target: "1411", Amount: 9.97887},
{Plan: "premium-4", Target: "1411", Amount: 0.44811},
{Plan: "premium-8", Target: "1411", Amount: 0.86957},
{Plan: "premium-16", Target: "1411", Amount: 1.72469},
{Plan: "premium-32", Target: "1411", Amount: 3.14683},
{Plan: "premium-64", Target: "1411", Amount: 5.64105},
{Plan: "premium-128", Target: "1411", Amount: 9.49136},
{Plan: "premium-225", Target: "1411", Amount: 14.84892},
}

func generatePostgresProducts() []db.Product {
Expand Down
Loading

0 comments on commit a9e67f0

Please sign in to comment.