File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 55 "encoding/json"
66 "fmt"
77 "reflect"
8+ "github.com/prometheus/client_golang/prometheus"
89 "regexp"
910 "strings"
1011 "time"
@@ -20,6 +21,20 @@ import (
2021 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122)
2223
24+ var (
25+ pgStatus = prometheus .NewGaugeVec (
26+ prometheus.GaugeOpts {
27+ Name : "pg_sync_status" ,
28+ Help : "Postgres sync status (1 = ok, 0 = error)." ,
29+ },
30+ []string {"namespace" , "clusterName" },
31+ )
32+ )
33+
34+ func init () {
35+ prometheus .MustRegister (pgStatus )
36+ }
37+
2338// Sync syncs the cluster, making sure the actual Kubernetes objects correspond to what is defined in the manifest.
2439// Unlike the update, sync does not error out if some objects do not exist and takes care of creating them.
2540func (c * Cluster ) Sync (newSpec * acidv1.Postgresql ) error {
@@ -31,7 +46,10 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error {
3146 c .setSpec (newSpec )
3247
3348 defer func () {
49+ labels := prometheus.Labels {"namespace" :c .clusterName ().Namespace ,"clusterName" :c .clusterName ().Name }
50+ pgStatus .With (labels ).Set (1 )
3451 if err != nil {
52+ pgStatus .With (labels ).Set (0 )
3553 c .logger .Warningf ("error while syncing cluster state: %v" , err )
3654 c .KubeClient .SetPostgresCRDStatus (c .clusterName (), acidv1 .ClusterStatusSyncFailed )
3755 } else if ! c .Status .Running () {
You can’t perform that action at this time.
0 commit comments