generated from vshn/go-bootstrap
-
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 #21 from vshn/postgres
Add Postgres to metrics collector
- Loading branch information
Showing
27 changed files
with
1,374 additions
and
386 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
const ( | ||
keyEnvVariable = "EXOSCALE_API_KEY" | ||
secretEnvVariable = "EXOSCALE_API_SECRET" | ||
dbURLEnvVariable = "ACR_DB_URL" | ||
k8sServerURLEnvVariable = "K8S_SERVER_URL" | ||
k8sTokenEnvVariable = "K8S_TOKEN" | ||
) | ||
|
||
type command struct { | ||
clusterURL string | ||
clusterToken string | ||
databaseURL string | ||
exoscaleKey string | ||
exoscaleSecret string | ||
} | ||
|
||
func getExoscaleSecretFlag(exoscaleSecret *string) *cli.StringFlag { | ||
return &cli.StringFlag{ | ||
Name: "exoscale-secret", | ||
Aliases: []string{"s"}, | ||
EnvVars: []string{secretEnvVariable}, | ||
Required: true, | ||
Usage: "The secret which has unrestricted SOS service access in an Exoscale organization", | ||
Destination: exoscaleSecret, | ||
} | ||
} | ||
|
||
func getExoscaleAccessKeyFlag(exoscaleKey *string) *cli.StringFlag { | ||
return &cli.StringFlag{ | ||
Name: "exoscale-access-key", | ||
Aliases: []string{"k"}, | ||
EnvVars: []string{keyEnvVariable}, | ||
Required: true, | ||
Usage: "A key which has unrestricted SOS service access in an Exoscale organization", | ||
Destination: exoscaleKey, | ||
} | ||
} | ||
|
||
func getDatabaseURLFlag(databaseURL *string) *cli.StringFlag { | ||
return &cli.StringFlag{ | ||
Name: "database-url", | ||
Aliases: []string{"d"}, | ||
EnvVars: []string{dbURLEnvVariable}, | ||
Required: true, | ||
Usage: "A PostgreSQL database URL where to save relevant metrics", | ||
Destination: databaseURL, | ||
} | ||
} | ||
|
||
func getK8sServerTokenURLFlag(clusterToken *string) *cli.StringFlag { | ||
return &cli.StringFlag{ | ||
Name: "k8s-server-token", | ||
Aliases: []string{"t"}, | ||
EnvVars: []string{k8sTokenEnvVariable}, | ||
Required: true, | ||
Usage: "A Kubernetes server token which can view buckets.exoscale.crossplane.io resources", | ||
Destination: clusterToken, | ||
} | ||
} | ||
|
||
func getClusterURLFlag(clusterURL *string) *cli.StringFlag { | ||
return &cli.StringFlag{ | ||
Name: "k8s-server-url", | ||
Aliases: []string{"u"}, | ||
EnvVars: []string{k8sServerURLEnvVariable}, | ||
Required: true, | ||
Usage: "A Kubernetes server URL from where to get the data from", | ||
Destination: clusterURL, | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/urfave/cli/v2" | ||
"github.com/vshn/exoscale-metrics-collector/pkg/clients/cluster" | ||
"github.com/vshn/exoscale-metrics-collector/pkg/clients/exoscale" | ||
"github.com/vshn/exoscale-metrics-collector/pkg/service/dbaas" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
const ( | ||
dbaasName = "dbaas" | ||
) | ||
|
||
type dbaasCommand struct { | ||
command | ||
} | ||
|
||
func newDBaasSCommand() *cli.Command { | ||
command := &dbaasCommand{} | ||
return &cli.Command{ | ||
Name: dbaasName, | ||
Usage: "Get metrics from database service", | ||
Action: command.execute, | ||
Flags: []cli.Flag{ | ||
getClusterURLFlag(&command.clusterURL), | ||
getK8sServerTokenURLFlag(&command.clusterToken), | ||
getDatabaseURLFlag(&command.databaseURL), | ||
getExoscaleAccessKeyFlag(&command.exoscaleKey), | ||
getExoscaleSecretFlag(&command.exoscaleSecret), | ||
}, | ||
} | ||
} | ||
|
||
func (c *dbaasCommand) execute(ctx *cli.Context) error { | ||
log := AppLogger(ctx).WithName(dbaasName) | ||
ctrl.SetLogger(log) | ||
|
||
log.Info("Creating Exoscale client") | ||
exoscaleClient, err := exoscale.InitClient(c.exoscaleKey, c.exoscaleSecret) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Info("Creating k8s client") | ||
k8sClient, err := cluster.InitK8sClientDynamic(c.clusterURL, c.clusterToken) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d := dbaas.NewDBaaSService(exoscaleClient, k8sClient, c.databaseURL) | ||
return d.Execute(ctx.Context) | ||
} |
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 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 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,3 +1,4 @@ | ||
* xref:index.adoc[Home] | ||
* xref:how-tos/installation.adoc[Installation] | ||
* xref:how-tos/multi-instance.adoc[Multi Instance] | ||
* xref:references/parameters.adoc[Parameters] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.