diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index 15e8286..f5f840b 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -24,7 +24,7 @@ resources: # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required. #- ../certmanager # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. -#- ../prometheus +- ../prometheus patches: - path: manager_env_patch.yaml diff --git a/go.mod b/go.mod index f635c16..25d5e2e 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/joeig/go-powerdns/v3 v3.14.1 github.com/onsi/ginkgo/v2 v2.20.0 github.com/onsi/gomega v1.34.1 + github.com/prometheus/client_golang v1.20.0 k8s.io/apimachinery v0.31.0 k8s.io/client-go v0.31.0 k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 @@ -38,12 +39,12 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.17.9 // indirect + github.com/kylelemons/godebug v1.1.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/prometheus/client_golang v1.20.0 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.55.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect diff --git a/internal/controller/pdns_metrics.go b/internal/controller/pdns_metrics.go new file mode 100644 index 0000000..0b2c2c6 --- /dev/null +++ b/internal/controller/pdns_metrics.go @@ -0,0 +1,49 @@ +package controller + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/testutil" +) + +var ( + rrsetsStatusesMetric = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "rrsets_status", + Help: "Statuses of RRsets processed", + }, + []string{"fqdn", "type", "status", "name", "namespace"}, + ) +) + +func updateRrsetsMetrics(fqdn, rrsetType, rrsetStatus, name, namespace string) { + rrsetsStatusesMetric.With(map[string]string{ + "fqdn": fqdn, + "type": rrsetType, + "status": rrsetStatus, + "name": name, + "namespace": namespace, + }).Set(1) +} +func removeRrsetMetrics(name, namespace string) { + rrsetsStatusesMetric.DeletePartialMatch( + map[string]string{ + "namespace": namespace, + "name": name, + }, + ) +} + +//nolint:unparam +func getMetricWithLabels(rrsetFQDN, rrsetType, rrsetStatus, rrsetName, rrsetNamespace string) float64 { + return testutil.ToFloat64(rrsetsStatusesMetric.With(prometheus.Labels{ + "fqdn": rrsetFQDN, + "type": rrsetType, + "status": rrsetStatus, + "name": rrsetName, + "namespace": rrsetNamespace, + })) +} + +func countMetrics() int { + return testutil.CollectAndCount(rrsetsStatusesMetric) +} diff --git a/internal/controller/rrset_controller.go b/internal/controller/rrset_controller.go index 893ba62..54acfb8 100644 --- a/internal/controller/rrset_controller.go +++ b/internal/controller/rrset_controller.go @@ -24,6 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/metrics" dnsv1alpha1 "github.com/orange-opensource/powerdns-operator/api/v1alpha1" ) @@ -40,6 +41,11 @@ type RRsetReconciler struct { PDNSClient PdnsClienter } +func init() { + // Register custom metrics with the global prometheus registry + metrics.Registry.MustRegister(rrsetsStatusesMetric) +} + // +kubebuilder:rbac:groups=dns.cav.enablers.ob,resources=rrsets,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=dns.cav.enablers.ob,resources=rrsets/status,verbs=get;update;patch // +kubebuilder:rbac:groups=dns.cav.enablers.ob,resources=rrsets/finalizers,verbs=update @@ -77,6 +83,8 @@ func (r *RRsetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl log.Error(err, "Failed to remove finalizer") return ctrl.Result{}, err } + // Remove resource metrics + removeRrsetMetrics(rrset.Name, rrset.Namespace) } // Race condition when creating Zone+RRset at the same time // RRset is not created because Zone is not created yet @@ -119,6 +127,9 @@ func (r *RRsetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl log.Error(err, "Failed to remove finalizer") return ctrl.Result{}, err } + // Remove resource metrics + removeRrsetMetrics(rrset.Name, rrset.Namespace) + //nolint:ineffassign lastUpdateTime = &metav1.Time{Time: time.Now().UTC()} } @@ -129,6 +140,9 @@ func (r *RRsetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl // We cannot exit previously (at the early moments of reconcile), because we have to allow deletion process if isInFailedStatus { + // Update resource metrics + updateRrsetsMetrics(getRRsetName(rrset), rrset.Spec.Type, *rrset.Status.SyncStatus, rrset.Name, rrset.Namespace) + return ctrl.Result{}, nil } @@ -151,6 +165,10 @@ func (r *RRsetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl log.Error(err, "unable to patch RRSet status") return ctrl.Result{}, err } + + // Update resource metrics + updateRrsetsMetrics(getRRsetName(rrset), rrset.Spec.Type, *rrset.Status.SyncStatus, rrset.Name, rrset.Namespace) + return ctrl.Result{}, nil } @@ -195,6 +213,9 @@ func (r *RRsetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl return ctrl.Result{}, err } + // Metrics calculation + updateRrsetsMetrics(getRRsetName(rrset), rrset.Spec.Type, *rrset.Status.SyncStatus, rrset.Name, rrset.Namespace) + return ctrl.Result{}, nil } diff --git a/internal/controller/rrset_controller_test.go b/internal/controller/rrset_controller_test.go index dc70792..e45668b 100644 --- a/internal/controller/rrset_controller_test.go +++ b/internal/controller/rrset_controller_test.go @@ -168,6 +168,7 @@ var _ = Describe("RRset Controller", func() { Context("When existing resource", func() { It("should successfully retrieve the resource", Label("rrset-initialization"), func() { + ic := countMetrics() ctx := context.Background() By("Getting the existing resource") createdResource := &dnsv1alpha1.RRset{} @@ -176,6 +177,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(0), "No more metric should have been created") + Expect(getMetricWithLabels(resourceDNSName+"."+zoneRef+".", resourceType, SUCCEEDED_STATUS, resourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(resourceName, resourceType)).To(Equal(resourceRecords)) Expect(getMockedTTL(resourceName, resourceType)).To(Equal(resourceTTL)) Expect(getMockedComment(resourceName, resourceType)).To(Equal(resourceComment)) @@ -187,6 +190,7 @@ var _ = Describe("RRset Controller", func() { Context("When updating RRset", func() { It("should successfully reconcile the resource", Label("rrset-modification", "records"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables updatedRecords := []string{"127.0.0.3"} @@ -218,6 +222,8 @@ var _ = Describe("RRset Controller", func() { err := k8sClient.Get(ctx, rssetLookupKey, updatedRRset) return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(0), "No more metric should have been created") + Expect(getMetricWithLabels(resourceDNSName+"."+zoneRef+".", resourceType, SUCCEEDED_STATUS, resourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(resourceName, resourceType)).To(Equal(updatedRecords)) Expect(getMockedTTL(resourceName, resourceType)).To(Equal(resourceTTL)) Expect(getMockedComment(resourceName, resourceType)).To(Equal(resourceComment)) @@ -236,6 +242,7 @@ var _ = Describe("RRset Controller", func() { Context("When updating RRset", func() { It("should successfully reconcile the resource", Label("rrset-modification", "ttl"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables modifiedResourceTTL := uint32(150) @@ -269,6 +276,8 @@ var _ = Describe("RRset Controller", func() { rrset, found := readFromRecordsMap(makeCanonical(resourceName)) return err == nil && found && *rrset.TTL != resourceTTL // ensure the RRset has been updated in the backend }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(0), "No more metric should have been created") + Expect(getMetricWithLabels(resourceDNSName+"."+zoneRef+".", resourceType, SUCCEEDED_STATUS, resourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(resourceName, resourceType)).To(Equal(resourceRecords)) Expect(getMockedTTL(resourceName, resourceType)).To(Equal(modifiedResourceTTL)) Expect(getMockedComment(resourceName, resourceType)).To(Equal(resourceComment)) @@ -286,6 +295,7 @@ var _ = Describe("RRset Controller", func() { Context("When updating RRset", func() { It("should successfully reconcile the resource", Label("rrset-modification", "comments"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables modifiedResourceComment := "Just another comment" @@ -317,6 +327,8 @@ var _ = Describe("RRset Controller", func() { err := k8sClient.Get(ctx, rssetLookupKey, updatedRRset) return err == nil && *updatedRRset.Spec.Comment != resourceComment }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(0), "No more metric should have been created") + Expect(getMetricWithLabels(resourceDNSName+"."+zoneRef+".", resourceType, SUCCEEDED_STATUS, resourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(resourceName, resourceType)).To(Equal(resourceRecords)) Expect(getMockedTTL(resourceName, resourceType)).To(Equal(resourceTTL)) Expect(getMockedComment(resourceName, resourceType)).To(Equal(modifiedResourceComment)) @@ -334,6 +346,7 @@ var _ = Describe("RRset Controller", func() { Context("When existing resource", func() { It("should successfully recreate an existing rrset", Label("rrset-recreation"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables recreationResourceName := "test2.example2.org" @@ -393,6 +406,8 @@ var _ = Describe("RRset Controller", func() { return err == nil && updatedRRset.Status.LastUpdateTime != nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(resourceDNSName+"."+zoneRef+".", resourceType, SUCCEEDED_STATUS, resourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Eventually(func() bool { return getMockedRecordsForType(recreationResourceName, recreationResourceType) != nil }, timeout, interval).Should(BeTrue()) @@ -412,6 +427,7 @@ var _ = Describe("RRset Controller", func() { Context("When existing resource", func() { It("should successfully modify a deleted rrset", Label("rrset-modification-after-deletion"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables @@ -461,6 +477,8 @@ var _ = Describe("RRset Controller", func() { return err == nil && rrsetFound }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(0), "No more metric should have been created") + Expect(getMetricWithLabels(resourceDNSName+"."+zoneRef+".", resourceType, SUCCEEDED_STATUS, resourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(resourceName, resourceType)).To(Equal(modifiedResourceRecords)) Expect(getMockedTTL(resourceName, resourceType)).To(Equal(modifiedResourceTTL)) Expect(getMockedComment(resourceName, resourceType)).To(Equal(modifiedResourceComment)) @@ -469,6 +487,7 @@ var _ = Describe("RRset Controller", func() { Context("When existing resource", func() { It("should successfully delete a deleted rrset", Label("rrset-deletion-after-deletion"), func() { + ic := countMetrics() ctx := context.Background() By("Creating a RRset") @@ -525,11 +544,14 @@ var _ = Describe("RRset Controller", func() { err := k8sClient.Get(ctx, fakeTypeNamespacedName, fakeResource) return errors.IsNotFound(err) }, timeout, interval).Should(BeTrue()) + + Expect(countMetrics()-ic).To(Equal(0), "No more metric should have been created") }) }) Context("When creating RRset", func() { It("should successfully reconcile the resource", Label("rrset-creation", "AAAA-Type"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables additionalResourceName := "aaaa" @@ -582,6 +604,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(additionalResourceName+"."+zoneName+".", additionalResourceType, SUCCEEDED_STATUS, additionalResourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceRecords)) Expect(getMockedTTL(DnsFqdn, additionalResourceType)).To(Equal(resourceTTL)) Expect(getMockedComment(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceComment)) @@ -594,6 +618,7 @@ var _ = Describe("RRset Controller", func() { Context("When creating RRset", func() { It("should successfully reconcile the resource", Label("rrset-creation", "CNAME-Type"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables additionalResourceName := "cname" @@ -646,6 +671,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(additionalResourceName+"."+zoneName+".", additionalResourceType, SUCCEEDED_STATUS, additionalResourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceRecords)) Expect(getMockedTTL(DnsFqdn, additionalResourceType)).To(Equal(resourceTTL)) Expect(getMockedComment(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceComment)) @@ -657,6 +684,7 @@ var _ = Describe("RRset Controller", func() { Context("When creating RRset", func() { It("should successfully reconcile the resource", Label("rrset-creation", "Wildcard-Type"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables additionalResourceName := "wildcard" @@ -709,6 +737,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(additionalResourceName+"."+zoneName+".", additionalResourceType, SUCCEEDED_STATUS, additionalResourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceRecords)) Expect(getMockedTTL(DnsFqdn, additionalResourceType)).To(Equal(resourceTTL)) Expect(getMockedComment(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceComment)) @@ -719,6 +749,7 @@ var _ = Describe("RRset Controller", func() { }) Context("When creating RRset", func() { It("should successfully reconcile the resource", Label("rrset-creation", "MX-Type"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables additionalResourceName := "mx" @@ -771,6 +802,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(additionalResourceName+"."+zoneName+".", additionalResourceType, SUCCEEDED_STATUS, additionalResourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceRecords)) Expect(getMockedTTL(DnsFqdn, additionalResourceType)).To(Equal(resourceTTL)) Expect(getMockedComment(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceComment)) @@ -782,6 +815,7 @@ var _ = Describe("RRset Controller", func() { Context("When creating RRset", func() { It("should successfully reconcile the resource", Label("rrset-creation", "NS-Type"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables additionalResourceName := "ns" @@ -834,6 +868,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(additionalResourceName+"."+zoneName+".", additionalResourceType, SUCCEEDED_STATUS, additionalResourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceRecords)) Expect(getMockedTTL(DnsFqdn, additionalResourceType)).To(Equal(resourceTTL)) Expect(getMockedComment(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceComment)) @@ -845,6 +881,7 @@ var _ = Describe("RRset Controller", func() { Context("When creating RRset", func() { It("should successfully reconcile the resource", Label("rrset-creation", "TXT-Type"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables additionalResourceName := "txt" @@ -897,6 +934,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(additionalResourceName+"."+zoneName+".", additionalResourceType, SUCCEEDED_STATUS, additionalResourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceRecords)) Expect(getMockedTTL(DnsFqdn, additionalResourceType)).To(Equal(resourceTTL)) Expect(getMockedComment(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceComment)) @@ -908,6 +947,7 @@ var _ = Describe("RRset Controller", func() { Context("When creating RRset", func() { It("should successfully reconcile the resource", Label("rrset-creation", "SRV-Type"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables additionalResourceName := "srv" @@ -960,6 +1000,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(additionalResourceName+"."+zoneName+".", additionalResourceType, SUCCEEDED_STATUS, additionalResourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceRecords)) Expect(getMockedTTL(DnsFqdn, additionalResourceType)).To(Equal(resourceTTL)) Expect(getMockedComment(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceComment)) @@ -971,6 +1013,7 @@ var _ = Describe("RRset Controller", func() { Context("When creating RRset", func() { It("should successfully reconcile the resource", Label("rrset-creation", "PTR-Type"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables reverseZoneName := "123.168.192.in-addr.arpa" @@ -1052,6 +1095,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(additionalResourceName+"."+reverseZoneName+".", additionalResourceType, SUCCEEDED_STATUS, additionalResourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceRecords)) Expect(getMockedTTL(DnsFqdn, additionalResourceType)).To(Equal(resourceTTL)) Expect(getMockedComment(DnsFqdn, additionalResourceType)).To(Equal(additionalResourceComment)) @@ -1063,6 +1108,7 @@ var _ = Describe("RRset Controller", func() { Context("When creating a wrong RRset", func() { It("should reconcile the resource with Failed status", Label("wrong-rrset", "wrong-type"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables badTypeResourceName := "wrong-type" @@ -1112,6 +1158,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(badTypeResourceDNSName+"."+zoneRef+".", badTypeResourceType, FAILED_STATUS, badTypeResourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(DnsFqdn, badTypeResourceType)).To(Equal([]string{}), "RRset should not have been created in backend") Expect(*createdResource.Status.SyncStatus).To(Equal(FAILED_STATUS), "RRset status should be 'Failed'") Expect(createdResource.GetOwnerReferences()).NotTo(BeEmpty(), "RRset should have setOwnerReference") @@ -1122,6 +1170,7 @@ var _ = Describe("RRset Controller", func() { Context("When creating a wrong RRset", func() { It("should reconcile the resource with Failed status", Label("wrong-rrset", "wrong-format"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables badFormatResourceName := "wrong-format" @@ -1171,6 +1220,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(badFormatResourceDNSName+"."+zoneRef+".", badFormatResourceType, FAILED_STATUS, badFormatResourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(DnsFqdn, badFormatResourceType)).To(Equal([]string{}), "RRset should not have been created in backend") Expect(*createdResource.Status.SyncStatus).To(Equal(FAILED_STATUS), "RRset status should be 'Failed'") Expect(createdResource.GetOwnerReferences()).NotTo(BeEmpty(), "RRset should have setOwnerReference") @@ -1181,6 +1232,7 @@ var _ = Describe("RRset Controller", func() { Context("When creating a wrong RRset", func() { It("should reconcile the resource with Failed status", Label("wrong-rrset", "unquoted-txt"), func() { + ic := countMetrics() ctx := context.Background() // Specific test variables unquotedResourceName := "unquoted" @@ -1230,6 +1282,8 @@ var _ = Describe("RRset Controller", func() { return err == nil }, timeout, interval).Should(BeTrue()) + Expect(countMetrics()-ic).To(Equal(1), "One more metric should have been created") + Expect(getMetricWithLabels(unquotedResourceDNSName+"."+zoneRef+".", unquotedResourceType, FAILED_STATUS, unquotedResourceName, resourceNamespace)).To(Equal(1.0), "metric should be 1.0") Expect(getMockedRecordsForType(DnsFqdn, unquotedResourceType)).To(Equal([]string{}), "RRset should not have been created in backend") Expect(*createdResource.Status.SyncStatus).To(Equal(FAILED_STATUS), "RRset status should be 'Failed'") Expect(createdResource.GetOwnerReferences()).NotTo(BeEmpty(), "RRset should have setOwnerReference")