Skip to content

Commit 5363d20

Browse files
committed
added a generic Clone function to remove type infer in when cloning ScrapedData
Signed-off-by: Nir Rozenbaum <[email protected]>
1 parent ce0377e commit 5363d20

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

pkg/epp/backend/metrics/fake_metrics_scraper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (s *FakeMetricsScraper) Scrape(ctx context.Context, pod *backend.Pod, port
6060
return nil, fmt.Errorf("no pod found: %v", pod.NamespacedName)
6161
}
6262
log.FromContext(ctx).V(logutil.VERBOSE).Info("Fetching metrics for pod", "existing", s.existingMetrics, "new", res)
63-
return res.Clone(), nil
63+
return podinfo.Clone(res), nil
6464
}
6565

6666
func (s *FakeMetricsScraper) ProcessResult(ctx context.Context, podinfo podinfo.ScrapedData) {} // noop

pkg/epp/backend/metrics/metrics_scraper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (s *MetricsScraper) ProcessResult(ctx context.Context, data podinfo.Scraped
105105
// promToPodMetrics updates internal pod metrics with scraped Prometheus metrics.
106106
func (s *MetricsScraper) promToPodMetrics(metricFamilies map[string]*dto.MetricFamily) (podinfo.ScrapedData, error) {
107107
var errs error
108-
updated := s.existingMetrics.Clone().(*Metrics)
108+
updated := podinfo.Clone(s.existingMetrics)
109109

110110
if s.MetricMapping.TotalQueuedRequests != nil {
111111
queued, err := s.getMetric(metricFamilies, *s.MetricMapping.TotalQueuedRequests)

pkg/epp/backend/pod-info/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ type Datastore interface {
6565
// PodGetAll() []PodMetrics
6666
// PodList(func(PodMetrics) bool) []PodMetrics
6767
}
68+
69+
// Clone is a generic function that clones any struct that implements ScrapedData interface.
70+
func Clone[T ScrapedData](base T) T {
71+
copy := base.Clone()
72+
return copy.(T)
73+
}

0 commit comments

Comments
 (0)