Skip to content

Commit

Permalink
Merge pull request #265 from vshn/fix/pg_exporter
Browse files Browse the repository at this point in the history
Add new custom pg exporter config
  • Loading branch information
Kidswiss authored Nov 25, 2024
2 parents 2b7f184 + 911f230 commit 4e3d1c8
Show file tree
Hide file tree
Showing 3 changed files with 939 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/comp-functions/functions/vshnpostgres/pgqexporter_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package vshnpostgres

import (
"context"
_ "embed"
"fmt"

"github.com/crossplane/function-sdk-go/proto/v1beta1"
xkube "github.com/vshn/appcat/v4/apis/kubernetes/v1alpha2"
vshnv1 "github.com/vshn/appcat/v4/apis/vshn/v1"
"github.com/vshn/appcat/v4/pkg/comp-functions/runtime"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

/*
This code ensures we have minimalistic postgresql-exporter configuration
It prevents high memory usage for big databases
*/
//go:embed scripts/queries.yml
var queries string

func PgExporterConfig(ctx context.Context, comp *vshnv1.VSHNPostgreSQL, svc *runtime.ServiceRuntime) *v1beta1.Result {
err := svc.GetObservedComposite(comp)
if err != nil {
return runtime.NewFatalResult(fmt.Errorf("cannot get composite: %w", err))
}
// get configmap
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"stackgres.io/reconciliation-pause": "true",
},
Name: comp.GetName() + "-prometheus-postgres-exporter-config",
Namespace: comp.GetInstanceNamespace(),
},
Data: map[string]string{
"queries.yaml": queries,
},
}
xRef := xkube.Reference{
DependsOn: &xkube.DependsOn{
APIVersion: "stackgres.io/v1",
Kind: "SGCluster",
Name: comp.GetName(),
Namespace: comp.GetInstanceNamespace(),
},
}
// add crossplane object containing ConfigMap
err = svc.SetDesiredKubeObjectWithName(configMap, comp.GetName()+"-prometheus-postgres-exporter-config", comp.GetName(), runtime.KubeOptionAddRefs(xRef))
if err != nil {
return runtime.NewWarningResult(fmt.Sprintf("cannot add ConfigMap: %s", err))
}
return nil
}
4 changes: 4 additions & 0 deletions pkg/comp-functions/functions/vshnpostgres/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func init() {
Name: "billing",
Execute: AddBilling,
},
{
Name: "custom-exporter-configs",
Execute: PgExporterConfig,
},
},
})
}
Loading

0 comments on commit 4e3d1c8

Please sign in to comment.