-
Notifications
You must be signed in to change notification settings - Fork 1
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 #265 from vshn/fix/pg_exporter
Add new custom pg exporter config
- Loading branch information
Showing
3 changed files
with
939 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
pkg/comp-functions/functions/vshnpostgres/pgqexporter_config.go
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,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 | ||
} |
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
Oops, something went wrong.