diff --git a/CHANGELOG.md b/CHANGELOG.md index 38d23ed6c33f..d5495af6323a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ - `tanzuobservabilityexporter`: Use semantic conventions for status.message (#7126) - `k8sattributesprocessor`: Move `kube` and `observability` packages to `internal` folder (#7159) - `zookeeperreceiver`: Refactored metrics to have correct units, types, and combined some metrics via attributes. (#7280) +- `prometheusremotewriteexporter`: `PRWExporter` struct and `NewPRWExporter()` + function are now unexported. (#TBD) ## 🚀 New components 🚀 diff --git a/exporter/prometheusremotewriteexporter/exporter.go b/exporter/prometheusremotewriteexporter/exporter.go index fc0cb8ba029f..e4cb3a2f8587 100644 --- a/exporter/prometheusremotewriteexporter/exporter.go +++ b/exporter/prometheusremotewriteexporter/exporter.go @@ -39,8 +39,8 @@ import ( const maxBatchByteSize = 3000000 -// PRWExporter converts OTLP metrics to Prometheus remote write TimeSeries and sends them to a remote endpoint. -type PRWExporter struct { +// prwExporter converts OTLP metrics to Prometheus remote write TimeSeries and sends them to a remote endpoint. +type prwExporter struct { namespace string externalLabels map[string]string endpointURL *url.URL @@ -52,8 +52,8 @@ type PRWExporter struct { clientSettings *confighttp.HTTPClientSettings } -// NewPRWExporter initializes a new PRWExporter instance and sets fields accordingly. -func NewPRWExporter(cfg *Config, buildInfo component.BuildInfo) (*PRWExporter, error) { +// newPRWExporter initializes a new prwExporter instance and sets fields accordingly. +func newPRWExporter(cfg *Config, buildInfo component.BuildInfo) (*prwExporter, error) { sanitizedLabels, err := validateAndSanitizeExternalLabels(cfg.ExternalLabels) if err != nil { return nil, err @@ -66,7 +66,7 @@ func NewPRWExporter(cfg *Config, buildInfo component.BuildInfo) (*PRWExporter, e userAgentHeader := fmt.Sprintf("%s/%s", strings.ReplaceAll(strings.ToLower(buildInfo.Description), " ", "-"), buildInfo.Version) - return &PRWExporter{ + return &prwExporter{ namespace: cfg.Namespace, externalLabels: sanitizedLabels, endpointURL: endpointURL, @@ -79,14 +79,14 @@ func NewPRWExporter(cfg *Config, buildInfo component.BuildInfo) (*PRWExporter, e } // Start creates the prometheus client -func (prwe *PRWExporter) Start(_ context.Context, host component.Host) (err error) { +func (prwe *prwExporter) Start(_ context.Context, host component.Host) (err error) { prwe.client, err = prwe.clientSettings.ToClient(host.GetExtensions()) return err } // Shutdown stops the exporter from accepting incoming calls(and return error), and wait for current export operations // to finish before returning -func (prwe *PRWExporter) Shutdown(context.Context) error { +func (prwe *prwExporter) Shutdown(context.Context) error { close(prwe.closeChan) prwe.wg.Wait() return nil @@ -95,7 +95,7 @@ func (prwe *PRWExporter) Shutdown(context.Context) error { // PushMetrics converts metrics to Prometheus remote write TimeSeries and send to remote endpoint. It maintain a map of // TimeSeries, validates and handles each individual metric, adding the converted TimeSeries to the map, and finally // exports the map. -func (prwe *PRWExporter) PushMetrics(ctx context.Context, md pdata.Metrics) error { +func (prwe *prwExporter) PushMetrics(ctx context.Context, md pdata.Metrics) error { prwe.wg.Add(1) defer prwe.wg.Done() @@ -199,7 +199,7 @@ func validateAndSanitizeExternalLabels(externalLabels map[string]string) (map[st return sanitizedLabels, nil } -func (prwe *PRWExporter) addNumberDataPointSlice(dataPoints pdata.NumberDataPointSlice, tsMap map[string]*prompb.TimeSeries, resource pdata.Resource, metric pdata.Metric) error { +func (prwe *prwExporter) addNumberDataPointSlice(dataPoints pdata.NumberDataPointSlice, tsMap map[string]*prompb.TimeSeries, resource pdata.Resource, metric pdata.Metric) error { if dataPoints.Len() == 0 { return consumererror.NewPermanent(fmt.Errorf("empty data points. %s is dropped", metric.Name())) } @@ -210,7 +210,7 @@ func (prwe *PRWExporter) addNumberDataPointSlice(dataPoints pdata.NumberDataPoin } // export sends a Snappy-compressed WriteRequest containing TimeSeries to a remote write endpoint in order -func (prwe *PRWExporter) export(ctx context.Context, tsMap map[string]*prompb.TimeSeries) []error { +func (prwe *prwExporter) export(ctx context.Context, tsMap map[string]*prompb.TimeSeries) []error { var errs []error // Calls the helper function to convert and batch the TsMap to the desired format requests, err := batchTimeSeries(tsMap, maxBatchByteSize) @@ -252,7 +252,7 @@ func (prwe *PRWExporter) export(ctx context.Context, tsMap map[string]*prompb.Ti return errs } -func (prwe *PRWExporter) execute(ctx context.Context, writeReq *prompb.WriteRequest) error { +func (prwe *prwExporter) execute(ctx context.Context, writeReq *prompb.WriteRequest) error { // Uses proto.Marshal to convert the WriteRequest into bytes array data, err := proto.Marshal(writeReq) if err != nil { diff --git a/exporter/prometheusremotewriteexporter/exporter_test.go b/exporter/prometheusremotewriteexporter/exporter_test.go index 1a7d47b173f0..70f6d2f1bfb5 100644 --- a/exporter/prometheusremotewriteexporter/exporter_test.go +++ b/exporter/prometheusremotewriteexporter/exporter_test.go @@ -111,7 +111,7 @@ func Test_NewPRWExporter(t *testing.T) { cfg.ExternalLabels = tt.externalLabels cfg.Namespace = tt.namespace cfg.RemoteWriteQueue.NumConsumers = 1 - prwe, err := NewPRWExporter(cfg, tt.buildInfo) + prwe, err := newPRWExporter(cfg, tt.buildInfo) if tt.returnErrorOnCreate { assert.Error(t, err) @@ -193,7 +193,7 @@ func Test_Start(t *testing.T) { cfg.RemoteWriteQueue.NumConsumers = 1 cfg.HTTPClientSettings = tt.clientSettings - prwe, err := NewPRWExporter(cfg, tt.buildInfo) + prwe, err := newPRWExporter(cfg, tt.buildInfo) assert.NoError(t, err) assert.NotNil(t, prwe) @@ -209,7 +209,7 @@ func Test_Start(t *testing.T) { // Test_Shutdown checks after Shutdown is called, incoming calls to PushMetrics return error. func Test_Shutdown(t *testing.T) { - prwe := &PRWExporter{ + prwe := &prwExporter{ wg: new(sync.WaitGroup), closeChan: make(chan struct{}), } @@ -335,7 +335,7 @@ func runExportPipeline(ts *prompb.TimeSeries, endpoint *url.URL) []error { Version: "1.0", } // after this, instantiate a CortexExporter with the current HTTP client and endpoint set to passed in endpoint - prwe, err := NewPRWExporter(cfg, buildInfo) + prwe, err := newPRWExporter(cfg, buildInfo) if err != nil { errs = append(errs, err) return errs @@ -627,7 +627,7 @@ func Test_PushMetrics(t *testing.T) { Description: "OpenTelemetry Collector", Version: "1.0", } - prwe, nErr := NewPRWExporter(cfg, buildInfo) + prwe, nErr := newPRWExporter(cfg, buildInfo) require.NoError(t, nErr) require.NoError(t, prwe.Start(context.Background(), componenttest.NewNopHost())) err := prwe.PushMetrics(context.Background(), *tt.md) diff --git a/exporter/prometheusremotewriteexporter/factory.go b/exporter/prometheusremotewriteexporter/factory.go index 491bdb665306..159ad229b77a 100644 --- a/exporter/prometheusremotewriteexporter/factory.go +++ b/exporter/prometheusremotewriteexporter/factory.go @@ -48,7 +48,7 @@ func createMetricsExporter(_ context.Context, set component.ExporterCreateSettin return nil, errors.New("invalid configuration") } - prwe, err := NewPRWExporter(prwCfg, set.BuildInfo) + prwe, err := newPRWExporter(prwCfg, set.BuildInfo) if err != nil { return nil, err }