Skip to content

Commit

Permalink
webhook: Fix metric name and add request gauges
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
  • Loading branch information
mrueg committed Jan 3, 2024
1 parent af8b5d8 commit 540990e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
12 changes: 12 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ Here is the full list of available metrics provided by ExternalDNS:
| external_dns_source_a_records | Number of A records in source | Gauge |


If you're using the webhook provider, the following additional metrics will be provided:

| Name | Description | Type |
| ------------------------------------------------------------ | ------------------------------------------------------ | ------- |
| external_dns_webhook_provider_records_errors_total | Number of errors with the /records method | Gauge |
| external_dns_webhook_provider_records_requests_total | Number of requests made to the /records method | Gauge |
| external_dns_webhook_provider_applychanges_errors_total | Number of errors with the /applychanges method | Gauge |
| external_dns_webhook_provider_applychanges_requests_total | Number of requests made to the /applychanges method | Gauge |
| external_dns_webhook_provider_adjustendpoints_errors_total | Number of errors with the /adjustendpoints method | Gauge |
| external_dns_webhook_provider_adjustendpoints_requests_total | Number of requests made to the /adjustendpoints method | Gauge |


### How can I run ExternalDNS under a specific GCP Service Account, e.g. to access DNS records in other projects?

Have a look at https://github.com/linki/mate/blob/v0.6.2/examples/google/README.md#permissions
Expand Down
37 changes: 34 additions & 3 deletions provider/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,50 @@ var (
prometheus.GaugeOpts{
Namespace: "external_dns",
Subsystem: "webhook_provider",
Name: "records_errors",
Name: "records_errors_total",
Help: "Errors with Records method",
},
)
recordsRequestsGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "external_dns",
Subsystem: "webhook_provider",
Name: "records_requests_total",
Help: "Requests with Records method",
},
)
applyChangesErrorsGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "external_dns",
Subsystem: "webhook_provider",
Name: "applychanges_errors",
Name: "applychanges_errors_total",
Help: "Errors with ApplyChanges method",
},
)
applyChangesRequestsGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "external_dns",
Subsystem: "webhook_provider",
Name: "applychanges_requests_total",
Help: "Requests with ApplyChanges method",
},
)
adjustEndpointsErrorsGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "external_dns",
Subsystem: "webhook_provider",
Name: "adjustendpointsgauge_errors",
Name: "adjustendpoints_errors_total",
Help: "Errors with AdjustEndpoints method",
},
)
adjustEndpointsRequestsGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "external_dns",
Subsystem: "webhook_provider",
Name: "adjustendpoints_requests_total",
Help: "Requests with AdjustEndpoints method",
},
)
)

type WebhookProvider struct {
Expand All @@ -73,8 +97,11 @@ type WebhookProvider struct {

func init() {
prometheus.MustRegister(recordsErrorsGauge)
prometheus.MustRegister(recordsRequestsGauge)
prometheus.MustRegister(applyChangesErrorsGauge)
prometheus.MustRegister(applyChangesRequestsGauge)
prometheus.MustRegister(adjustEndpointsErrorsGauge)
prometheus.MustRegister(adjustEndpointsRequestsGauge)
}

func NewWebhookProvider(u string) (*WebhookProvider, error) {
Expand Down Expand Up @@ -132,7 +159,9 @@ func NewWebhookProvider(u string) (*WebhookProvider, error) {

// Records will make a GET call to remoteServerURL/records and return the results
func (p WebhookProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, error) {
recordsRequestsGauge.Inc()
u := p.remoteServerURL.JoinPath("records").String()

req, err := http.NewRequest("GET", u, nil)
if err != nil {
recordsErrorsGauge.Inc()
Expand Down Expand Up @@ -165,6 +194,7 @@ func (p WebhookProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, err

// ApplyChanges will make a POST to remoteServerURL/records with the changes
func (p WebhookProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
applyChangesRequestsGauge.Inc()
u := p.remoteServerURL.JoinPath("records").String()

b := new(bytes.Buffer)
Expand Down Expand Up @@ -203,6 +233,7 @@ func (p WebhookProvider) ApplyChanges(ctx context.Context, changes *plan.Changes
// based on a provider specific requirement.
// This method returns an empty slice in case there is a technical error on the provider's side so that no endpoints will be considered.
func (p WebhookProvider) AdjustEndpoints(e []*endpoint.Endpoint) ([]*endpoint.Endpoint, error) {
adjustEndpointsRequestsGauge.Inc()
endpoints := []*endpoint.Endpoint{}
u, err := url.JoinPath(p.remoteServerURL.String(), "adjustendpoints")
if err != nil {
Expand Down

0 comments on commit 540990e

Please sign in to comment.