Skip to content

Commit aefb3a7

Browse files
fix(kuma-dp): add logging for MeshMetric application scraping failures (backport of #15513) (#15518)
Automatic cherry-pick of #15513 for branch release-2.11 Generated by [action](https://github.com/kumahq/kuma/actions/runs/21663883137) cherry-picked commit 9074d92 --------- Signed-off-by: Marcin Skalski <skalskimarcin33@gmail.com> Co-authored-by: Marcin Skalski <marcin.skalski@konghq.com> Co-authored-by: Marcin Skalski <skalskimarcin33@gmail.com>
1 parent 3a20e0a commit aefb3a7

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

app/kuma-dp/pkg/dataplane/metrics/metrics_format_mapper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ func FromPrometheusMetrics(appMetrics map[string]*io_prometheus_client.MetricFam
2525
extraAttributes := extraAttributesFrom(mesh, dataplane, service, extraLabels)
2626

2727
scopedMetrics := map[instrumentation.Scope][]metricdata.Metrics{}
28+
if len(appMetrics) == 0 {
29+
log.V(1).Info("FromPrometheusMetrics called with empty input")
30+
return scopedMetrics
31+
}
2832
for _, prometheusMetric := range appMetrics {
2933
var scopedAggregations map[instrumentation.Scope]metricdata.Aggregation
3034
switch prometheusMetric.GetType() {

app/kuma-dp/pkg/dataplane/metrics/metrics_producer.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ func (ap *AggregatedProducer) Produce(ctx context.Context) ([]metricdata.ScopeMe
5555
appsToScrape = append(appsToScrape, ap.applicationsToScrape...)
5656
ap.applicationsToScrapeMutex.Unlock()
5757

58+
if len(appsToScrape) > 0 {
59+
appNames := make([]string, 0, len(appsToScrape))
60+
for _, app := range appsToScrape {
61+
appNames = append(appNames, app.Name)
62+
}
63+
log.V(1).Info("starting metrics collection", "applications", appNames, "count", len(appsToScrape))
64+
}
65+
5866
out := make(chan map[instrumentation.Scope][]metricdata.Metrics, len(appsToScrape))
5967
var wg sync.WaitGroup
6068
done := make(chan []byte)
@@ -77,7 +85,11 @@ func (ap *AggregatedProducer) Produce(ctx context.Context) ([]metricdata.ScopeMe
7785
case <-ctx.Done():
7886
return nil, nil
7987
case <-done:
80-
return combineMetrics(out), nil
88+
result := combineMetrics(out)
89+
if len(result) == 0 && len(appsToScrape) > 0 {
90+
log.Info("metrics collection completed with zero metrics", "applicationCount", len(appsToScrape))
91+
}
92+
return result, nil
8193
}
8294
}
8395

@@ -115,13 +127,20 @@ func (ap *AggregatedProducer) fetchStats(ctx context.Context, app ApplicationToS
115127
return nil
116128
}
117129
defer resp.Body.Close()
130+
if resp.StatusCode != http.StatusOK {
131+
log.Info("application returned non-200 status", "name", app.Name, "status", resp.StatusCode, "path", app.Path, "port", app.Port)
132+
return nil
133+
}
118134
requestTime := time.Now().UTC()
119135

120136
metricsFromApplication, err := app.MeshMetricMutator(resp.Body)
121137
if err != nil {
122138
log.Error(err, "failed to mutate metrics")
123139
return nil
124140
}
141+
if len(metricsFromApplication) == 0 {
142+
log.Info("application returned empty metrics after parsing", "name", app.Name, "path", app.Path, "port", app.Port)
143+
}
125144
return FromPrometheusMetrics(metricsFromApplication, ap.mesh, ap.dataplane, ap.service, ap.kumaVersion, app.ExtraLabels, requestTime)
126145
}
127146

app/kuma-dp/pkg/dataplane/metrics/server.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ func (s *Hijacker) getStats(ctx context.Context, initReq *http.Request, app Appl
361361
logger.Error(err, "failed call", "name", app.Name, "path", app.Path, "port", app.Port)
362362
return nil, ""
363363
}
364+
if resp.StatusCode != http.StatusOK {
365+
bodyBytes, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
366+
logger.Info("application returned non-200 status", "name", app.Name, "status", resp.StatusCode, "path", app.Path, "port", app.Port, "body", string(bodyBytes))
367+
return nil, ""
368+
}
364369

365370
respContentType := responseFormat(resp.Header)
366371

@@ -379,6 +384,9 @@ func (s *Hijacker) getStats(ctx context.Context, initReq *http.Request, app Appl
379384
return nil, ""
380385
}
381386
}
387+
if len(bodyBytes) == 0 {
388+
logger.V(1).Info("application returned empty body", "name", app.Name, "path", app.Path, "port", app.Port)
389+
}
382390
return bodyBytes, respContentType
383391
}
384392

0 commit comments

Comments
 (0)