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 Nov 29, 2023
1 parent 4d04113 commit 3f349d0
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions provider/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,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 @@ -74,8 +98,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 @@ -133,7 +160,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 @@ -166,6 +195,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 @@ -204,6 +234,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 3f349d0

Please sign in to comment.