in pkg/controller/ingress/concurrency_watchdog.go [42:82]
func NginxScrapeFn(ctx context.Context, client rest.Interface, pod *corev1.Pod) (float64, error) {
lgr := logr.FromContextOrDiscard(ctx)
lgr.Info("scraping pod", "pod", pod.Name)
resp, err := client.Get().
AbsPath("/api/v1/namespaces", pod.Namespace, "pods", pod.Name+":10254", "proxy/metrics").
Timeout(time.Second * 30).
MaxRetries(4).
DoRaw(ctx)
if err != nil {
return 0, err
}
family := &prommodel.MetricFamily{}
format, err := expfmt.NewOpenMetricsFormat(expfmt.OpenMetricsVersion_0_0_1)
if err != nil {
return 0, fmt.Errorf("creating open metrics format: %w", err)
}
dec := expfmt.NewDecoder(bytes.NewReader(resp), format)
for {
err = dec.Decode(family)
if errors.Is(err, io.EOF) {
break
}
if err != nil {
return 0, err
}
if family.GetName() != "nginx_ingress_controller_nginx_process_connections" {
continue
}
for _, metric := range family.Metric {
if metric.Gauge == nil || !metricHasLabel(metric, "state", "active") {
continue
}
return metric.Gauge.GetValue(), nil
}
}
return 0, fmt.Errorf("active connections metric not found")
}