diff --git a/internal/helm/repository/chart_repository.go b/internal/helm/repository/chart_repository.go index c4c93ebc0..e15f3dc13 100644 --- a/internal/helm/repository/chart_repository.go +++ b/internal/helm/repository/chart_repository.go @@ -284,12 +284,14 @@ func (r *ChartRepository) DownloadChart(chart *repo.ChartVersion) (*bytes.Buffer defer transport.Release(t) start := time.Now() buffer, err := r.Client.Get(u.String(), clientOpts...) - r.Recorder.RecordChartRepoEventDuration( - ChartRepoTypeHelm, - ChartRepoEventTypeDownloadChart, - r.Namespace, - r.URL, - start) + if r.Recorder != nil { + r.Recorder.RecordChartRepoEventDuration( + ChartRepoTypeHelm, + ChartRepoEventDownloadChart, + r.Namespace, + r.URL, + start) + } return buffer, err } @@ -459,12 +461,15 @@ func (r *ChartRepository) DownloadIndex(w io.Writer) (err error) { if err != nil { return err } - r.Recorder.RecordChartRepoEventDuration( - ChartRepoTypeHelm, - ChartRepoEventTypeDownloadIndex, - r.Namespace, - r.URL, - start) + if r.Recorder != nil { + r.Recorder.RecordChartRepoEventDuration( + ChartRepoTypeHelm, + ChartRepoEventDownloadIndex, + r.Namespace, + r.URL, + start) + } + if _, err = io.Copy(w, res); err != nil { return err } diff --git a/internal/helm/repository/chart_repository_test.go b/internal/helm/repository/chart_repository_test.go index c9bf7f1a1..047b48de0 100644 --- a/internal/helm/repository/chart_repository_test.go +++ b/internal/helm/repository/chart_repository_test.go @@ -63,13 +63,12 @@ func TestNewChartRepository(t *testing.T) { New: helmgetter.NewHTTPGetter, }, } - repoRecorder := MustMakeMetrics() options := []helmgetter.Option{helmgetter.WithBasicAuth("username", "password")} t.Run("should construct chart repository", func(t *testing.T) { g := NewWithT(t) - r, err := NewChartRepository(repositoryURL, "", providers, nil, options, "fake-namespace", repoRecorder) + r, err := NewChartRepository(repositoryURL, "", providers, nil, options, "fake-namespace", nil) g.Expect(err).ToNot(HaveOccurred()) g.Expect(r).ToNot(BeNil()) g.Expect(r.URL).To(Equal(repositoryURL)) @@ -79,7 +78,7 @@ func TestNewChartRepository(t *testing.T) { t.Run("should error on URL parsing failure", func(t *testing.T) { g := NewWithT(t) - r, err := NewChartRepository("https://ex ample.com", "", nil, nil, nil, "fake-namespace", repoRecorder) + r, err := NewChartRepository("https://ex ample.com", "", nil, nil, nil, "fake-namespace", nil) g.Expect(err).To(HaveOccurred()) g.Expect(err).To(BeAssignableToTypeOf(&url.Error{})) g.Expect(r).To(BeNil()) @@ -89,7 +88,7 @@ func TestNewChartRepository(t *testing.T) { t.Run("should error on unsupported scheme", func(t *testing.T) { g := NewWithT(t) - r, err := NewChartRepository("http://example.com", "", providers, nil, nil, "fake-namespace", repoRecorder) + r, err := NewChartRepository("http://example.com", "", providers, nil, nil, "fake-namespace", nil) g.Expect(err).To(HaveOccurred()) g.Expect(err.Error()).To(Equal("scheme \"http\" not supported")) g.Expect(r).To(BeNil()) @@ -236,9 +235,12 @@ func TestChartRepository_DownloadChart(t *testing.T) { t.Parallel() mg := mockGetter{} + r := &ChartRepository{ - URL: tt.url, - Client: &mg, + URL: tt.url, + Namespace: "dummy", + Client: &mg, + Recorder: nil, } res, err := r.DownloadChart(tt.chartVersion) if tt.wantErr { diff --git a/internal/helm/repository/metrics.go b/internal/helm/repository/metrics.go index 21ceabdc2..539b36ee2 100644 --- a/internal/helm/repository/metrics.go +++ b/internal/helm/repository/metrics.go @@ -25,8 +25,8 @@ import ( const ( ChartRepoTypeHelm = "helm" //ChartRepoTypeOCI = "oci" - ChartRepoEventTypeDownloadIndex = "chart_repository_download" - ChartRepoEventTypeDownloadChart = "chart_download" + ChartRepoEventDownloadIndex = "chart_repository_download" + ChartRepoEventDownloadChart = "chart_download" ) // Recorder is a recorder for chart repository events. @@ -58,7 +58,7 @@ func NewRepositoryRecorder() *Recorder { Help: "The duration in seconds of an event for a Helm Chart Repository.", Buckets: prometheus.ExponentialBuckets(10e-9, 10, 10), }, - []string{"name", "repo_type", "namespace", "url", "checksum"}, + []string{"name", "repo_type", "namespace", "url"}, ), } }