Skip to content

Commit

Permalink
feat: added support for metrics type variable in scraper configuration (
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoL96 authored Nov 14, 2024
1 parent f3ff781 commit b574bbc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ metadata:
name: # DatabaseConfig name
namespace: # DatabaseConfig namespace
spec:
host: # host name for the database
token: # access token
clusterName: # generic compute cluster name
notebookPath: # path to the notebook
username: # username string
passwordSecretRef: # object reference to secret with password
name: # secret name
namespace: # secret namespace
key: # secret key
---
apiVersion: finops.krateo.io/v1
kind: ScraperConfig
Expand All @@ -50,7 +51,7 @@ spec:
- Access to a Kubernetes v1.11.3+ cluster.
### Dependencies
There is the need to have an active Databricks cluster, with SQL warehouse and notebooks configured. Its login details must be placed in the database-config CR.
You need to install CrateDB in the cluster and configure the Krateo Database Webservice.
### Installation with HELM
```sh
Expand All @@ -60,9 +61,8 @@ $ helm install finops-operator-scraper krateo/finops-operator-scraper
```
### Configuration
The database-config CR is required.
The deployment of the operator needs a secret for the repository, called `registry-credentials` in the namespace `finops`.

The scraper container is created in the namespace of the CR. The scraper container looks for a secret in the CR namespace called `registry-credentials-default`
The scraper container is created in the namespace of the CR. The scraper container looks for a secret in the CR namespace called `registry-credentials`, configurable in the HELM chart.

### Databricks token
The Databricks token can be obtained through the dashboard UI.
5 changes: 5 additions & 0 deletions config/crd/bases/finops.krateo.io_scraperconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
metricType:
default: cost
type: string
required:
- metricType
type: object
type: object
served: true
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/krateoplatformops/finops-operator-scraper
go 1.21

require (
github.com/krateoplatformops/finops-data-types v0.0.0-20240822144053-7ce9ae5c26a7
github.com/krateoplatformops/finops-data-types v0.0.0-20241114103324-d1c2aec150da
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
k8s.io/apimachinery v0.29.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/krateoplatformops/finops-data-types v0.0.0-20240822144053-7ce9ae5c26a7 h1:TDJf3NfxxjdENUc43Fpi/CDJ93PE3hSwCFA5+ZOg/74=
github.com/krateoplatformops/finops-data-types v0.0.0-20240822144053-7ce9ae5c26a7/go.mod h1:sBjqLz0E1UCBP5Jnz6i1c9almnmgaf3eZ8Q+fANKzs4=
github.com/krateoplatformops/finops-data-types v0.0.0-20241114103324-d1c2aec150da h1:JbW9RC2eN7oTddgVdCqUI+nhgqbdpwZMQXVQXHvHY2w=
github.com/krateoplatformops/finops-data-types v0.0.0-20241114103324-d1c2aec150da/go.mod h1:sBjqLz0E1UCBP5Jnz6i1c9almnmgaf3eZ8Q+fANKzs4=
github.com/krateoplatformops/finops-operator-exporter v0.0.0-20240714140455-0ba3f5de5546 h1:LZQI3kpAEF6uX0dfOo/N98rvyNSMXod6GxL666BvhzE=
github.com/krateoplatformops/finops-operator-exporter v0.0.0-20240714140455-0ba3f5de5546/go.mod h1:PzdGRjH/V9BIbLEyaCu5+Kyjzw0yOTqtxTOUmcZRD8k=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
Expand Down
14 changes: 10 additions & 4 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
finopsv1 "github.com/krateoplatformops/finops-operator-scraper/api/v1"
)

var repository = strings.TrimSuffix(os.Getenv("REPO"), "/")

type ScraperConfigFile struct {
DatabaseConfigRef finopsDataTypes.ObjectRef `yaml:"databaseConfigRef"`
Exporter Exporter `yaml:"exporter"`
Expand All @@ -24,6 +22,7 @@ type Exporter struct {
Url string `yaml:"url"`
PollingIntervalHours int `yaml:"pollingIntervalHours"`
TableName string `yaml:"tableName"`
MetricType string `yaml:"metricType"`
}

func int32Ptr(i int32) *int32 { return &i }
Expand Down Expand Up @@ -60,14 +59,20 @@ func GetGenericScraperDeployment(scraperConfig finopsv1.ScraperConfig) (*appsv1.
Containers: []corev1.Container{
{
Name: "scraper",
Image: repository + "/finops-prometheus-scraper-generic:latest",
Image: strings.TrimSuffix(os.Getenv("REGISTRY"), "/") + "/finops-prometheus-scraper-generic:latest",
ImagePullPolicy: corev1.PullAlways,
VolumeMounts: []corev1.VolumeMount{
{
Name: "config-volume",
MountPath: "/config",
},
},
Env: []corev1.EnvVar{
{
Name: "URL_DB_WEBSERVICE",
Value: os.Getenv("URL_DB_WEBSERVICE"),
},
},
},
},
Volumes: []corev1.Volume{
Expand All @@ -84,7 +89,7 @@ func GetGenericScraperDeployment(scraperConfig finopsv1.ScraperConfig) (*appsv1.
},
ImagePullSecrets: []corev1.LocalObjectReference{
{
Name: "registry-credentials-default",
Name: os.Getenv("REGISTRY_CREDENTIALS"),
},
},
},
Expand All @@ -98,6 +103,7 @@ func GetGenericScraperConfigMap(scraperConfig finopsv1.ScraperConfig) (*corev1.C
databaseConfigRef := finopsDataTypes.ObjectRef{}
exporter := Exporter{}

exporter.MetricType = scraperConfig.Status.MetricType
exporter.Url = scraperConfig.Spec.Url
exporter.PollingIntervalHours = scraperConfig.Spec.PollingIntervalHours
exporter.TableName = scraperConfig.Spec.TableName
Expand Down

0 comments on commit b574bbc

Please sign in to comment.