From 19d9bc8ef99b8cb083f0485df816db46dd68e5fc Mon Sep 17 00:00:00 2001 From: Aditya Kolhar Date: Mon, 8 Nov 2021 15:22:25 +0530 Subject: [PATCH] Changes to add A records of source and registry as metrics Changes to add A records of source and registry as metrics. The existing metrics - external_dns_registry_endpoints_total & external_dns_source_endpoints_total gives a cumulative count of records all records (A, SRV, CNAME, TXT). We have a metric - external_dns_controller_verified_records which gives the intersection of A records between source & regsitry. However, in order to determined how many records are yet to be synced to registry, we need count of total A records in registry & source. --- controller/controller.go | 23 ++++++++++++++++- controller/controller_test.go | 47 +++++++++++++++++++++++++++++++++++ docs/faq.md | 2 ++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/controller/controller.go b/controller/controller.go index 6070d66dd5..d609c089da 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -94,6 +94,22 @@ var ( Help: "Number of Source errors.", }, ) + registryARecords = prometheus.NewGauge( + prometheus.GaugeOpts{ + Namespace: "external_dns", + Subsystem: "registry", + Name: "a_records", + Help: "Number of Registry A records.", + }, + ) + sourceARecords = prometheus.NewGauge( + prometheus.GaugeOpts{ + Namespace: "external_dns", + Subsystem: "source", + Name: "a_records", + Help: "Number of Source A records.", + }, + ) verifiedARecords = prometheus.NewGauge( prometheus.GaugeOpts{ Namespace: "external_dns", @@ -113,6 +129,8 @@ func init() { prometheus.MustRegister(deprecatedRegistryErrors) prometheus.MustRegister(deprecatedSourceErrors) prometheus.MustRegister(controllerNoChangesTotal) + prometheus.MustRegister(registryARecords) + prometheus.MustRegister(sourceARecords) prometheus.MustRegister(verifiedARecords) } @@ -150,7 +168,8 @@ func (c *Controller) RunOnce(ctx context.Context) error { return err } registryEndpointsTotal.Set(float64(len(records))) - + regARecords := filterARecords(records) + registryARecords.Set(float64(len(regARecords))) ctx = context.WithValue(ctx, provider.RecordsContextKey, records) endpoints, err := c.Source.Endpoints(ctx) @@ -160,6 +179,8 @@ func (c *Controller) RunOnce(ctx context.Context) error { return err } sourceEndpointsTotal.Set(float64(len(endpoints))) + srcARecords := filterARecords(endpoints) + sourceARecords.Set(float64(len(srcARecords))) vRecords := fetchMatchingARecords(endpoints, records) verifiedARecords.Set(float64(len(vRecords))) endpoints = c.Registry.AdjustEndpoints(endpoints) diff --git a/controller/controller_test.go b/controller/controller_test.go index 591c80d245..27d01777c2 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -470,3 +470,50 @@ func TestVerifyARecords(t *testing.T) { ) assert.Equal(t, math.Float64bits(2), valueFromMetric(verifiedARecords)) } + +func TestARecords(t *testing.T) { + testControllerFiltersDomains( + t, + []*endpoint.Endpoint{ + { + DNSName: "record1.used.tld", + RecordType: endpoint.RecordTypeA, + Targets: endpoint.Targets{"1.2.3.4"}, + }, + { + DNSName: "record2.used.tld", + RecordType: endpoint.RecordTypeA, + Targets: endpoint.Targets{"8.8.8.8"}, + }, + { + DNSName: "_mysql-svc._tcp.mysql.used.tld", + RecordType: endpoint.RecordTypeSRV, + Targets: endpoint.Targets{"0 50 30007 mysql.used.tld"}, + }, + }, + endpoint.NewDomainFilter([]string{"used.tld"}), + []*endpoint.Endpoint{ + { + DNSName: "record1.used.tld", + RecordType: endpoint.RecordTypeA, + Targets: endpoint.Targets{"1.2.3.4"}, + }, + { + DNSName: "_mysql-svc._tcp.mysql.used.tld", + RecordType: endpoint.RecordTypeSRV, + Targets: endpoint.Targets{"0 50 30007 mysql.used.tld"}, + }, + }, + []*plan.Changes{{ + Create: []*endpoint.Endpoint{ + { + DNSName: "record2.used.tld", + RecordType: endpoint.RecordTypeA, + Targets: endpoint.Targets{"8.8.8.8"}, + }, + }, + }}, + ) + assert.Equal(t, math.Float64bits(2), valueFromMetric(sourceARecords)) + assert.Equal(t, math.Float64bits(1), valueFromMetric(registryARecords)) +} diff --git a/docs/faq.md b/docs/faq.md index 7a3c0f06de..30af2309ca 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -187,6 +187,8 @@ Here is the full list of available metrics provided by ExternalDNS: | external_dns_source_errors_total | Number of Source errors | Counter | | external_dns_controller_verified_records | Number of DNS A-records that exists both in | Gauge | | | source & registry | | +| external_dns_registry_a_records | Number of A records in registry | Gauge | +| external_dns_source_a_records | Number of A records in source | Gauge | ### How can I run ExternalDNS under a specific GCP Service Account, e.g. to access DNS records in other projects?