Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions exporter/prometheusremotewriteexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,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
Expand All @@ -53,8 +53,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
Expand All @@ -67,7 +67,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,
Expand All @@ -80,7 +80,7 @@ func NewPrwExporter(cfg *Config, buildInfo component.BuildInfo) (*PrwExporter, e
}

// Start creates the http client
func (prwe *PrwExporter) Start(_ context.Context, host component.Host) error {
func (prwe *PRWExporter) Start(_ context.Context, host component.Host) error {
client, err := prwe.clientSettings.ToClient(host.GetExtensions())
if err != nil {
return err
Expand All @@ -91,7 +91,7 @@ func (prwe *PrwExporter) Start(_ context.Context, host component.Host) error {

// 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
Expand All @@ -100,7 +100,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()

Expand Down Expand Up @@ -192,7 +192,7 @@ func validateAndSanitizeExternalLabels(externalLabels map[string]string) (map[st
// handleScalarMetric processes data points in a single OTLP scalar metric by adding the each point as a Sample into
// its corresponding TimeSeries in tsMap.
// tsMap and metric cannot be nil, and metric must have a non-nil descriptor
func (prwe *PrwExporter) handleScalarMetric(tsMap map[string]*prompb.TimeSeries, resource pdata.Resource, metric pdata.Metric) error {
func (prwe *PRWExporter) handleScalarMetric(tsMap map[string]*prompb.TimeSeries, resource pdata.Resource, metric pdata.Metric) error {
switch metric.DataType() {
// int points
case pdata.MetricDataTypeDoubleGauge:
Expand Down Expand Up @@ -236,7 +236,7 @@ func (prwe *PrwExporter) handleScalarMetric(tsMap map[string]*prompb.TimeSeries,
// handleHistogramMetric processes data points in a single OTLP histogram metric by mapping the sum, count and each
// bucket of every data point as a Sample, and adding each Sample to its corresponding TimeSeries.
// tsMap and metric cannot be nil.
func (prwe *PrwExporter) handleHistogramMetric(tsMap map[string]*prompb.TimeSeries, resource pdata.Resource, metric pdata.Metric) error {
func (prwe *PRWExporter) handleHistogramMetric(tsMap map[string]*prompb.TimeSeries, resource pdata.Resource, metric pdata.Metric) error {
switch metric.DataType() {
case pdata.MetricDataTypeIntHistogram:
dataPoints := metric.IntHistogram().DataPoints()
Expand All @@ -261,7 +261,7 @@ func (prwe *PrwExporter) handleHistogramMetric(tsMap map[string]*prompb.TimeSeri
// handleSummaryMetric processes data points in a single OTLP summary metric by mapping the sum, count and each
// quantile of every data point as a Sample, and adding each Sample to its corresponding TimeSeries.
// tsMap and metric cannot be nil.
func (prwe *PrwExporter) handleSummaryMetric(tsMap map[string]*prompb.TimeSeries, resource pdata.Resource, metric pdata.Metric) error {
func (prwe *PRWExporter) handleSummaryMetric(tsMap map[string]*prompb.TimeSeries, resource pdata.Resource, metric pdata.Metric) error {
dataPoints := metric.Summary().DataPoints()
if dataPoints.Len() == 0 {
return fmt.Errorf("empty data points. %s is dropped", metric.Name())
Expand All @@ -273,7 +273,7 @@ func (prwe *PrwExporter) handleSummaryMetric(tsMap map[string]*prompb.TimeSeries
}

// 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)
Expand Down Expand Up @@ -315,7 +315,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 {
Expand Down
12 changes: 6 additions & 6 deletions exporter/prometheusremotewriteexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import (
"go.opentelemetry.io/collector/internal/testdata"
)

// Test_ NewPrwExporter checks that a new exporter instance with non-nil fields is initialized
func Test_NewPrwExporter(t *testing.T) {
// Test_NewPRWExporter checks that a new exporter instance with non-nil fields is initialized
func Test_NewPRWExporter(t *testing.T) {
cfg := &Config{
ExporterSettings: config.NewExporterSettings(config.NewID(typeStr)),
TimeoutSettings: exporterhelper.TimeoutSettings{},
Expand Down Expand Up @@ -116,7 +116,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.returnError {
assert.Error(t, err)
Expand All @@ -137,7 +137,7 @@ func Test_NewPrwExporter(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{}),
}
Expand Down Expand Up @@ -263,7 +263,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
Expand Down Expand Up @@ -521,7 +521,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()))

Expand Down
2 changes: 1 addition & 1 deletion exporter/prometheusremotewriteexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func createMetricsExporter(_ context.Context, params component.ExporterCreatePar
return nil, errors.New("invalid configuration")
}

prwe, err := NewPrwExporter(prwCfg, params.BuildInfo)
prwe, err := NewPRWExporter(prwCfg, params.BuildInfo)
if err != nil {
return nil, err
}
Expand Down