Skip to content

Commit

Permalink
[exporter/dynatrace] rename struct to keep expected `exporter.Factory…
Browse files Browse the repository at this point in the history
…` and pass checkapi (open-telemetry#27048)

**Description:** 
Rename struct to keep expected exporter.Factory and pass checkapi

**Link to tracking Issue:** 

open-telemetry#26304

**Testing:**
go run cmd/checkapi/main.go .
make chlog-validate
go test for dynatraceexporter

**Documentation:**
  • Loading branch information
sakulali authored and jmsnll committed Nov 12, 2023
1 parent d0de9d6 commit c20f62e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
27 changes: 27 additions & 0 deletions .chloggen/dynatraceexporter-checkapi-26304.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: dynatraceexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Rename struct to keep expected `exporter.Factory` and pass checkapi.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [26304]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
1 change: 0 additions & 1 deletion cmd/checkapi/allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
connector/servicegraphconnector
exporter/coralogixexporter
exporter/dynatraceexporter
exporter/kafkaexporter
exporter/pulsarexporter
extension/observer/ecsobserver
Expand Down
12 changes: 6 additions & 6 deletions exporter/dynatraceexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
exp "go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"

dtconfig "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/dynatraceexporter/config"
Expand All @@ -17,11 +17,11 @@ import (
)

// NewFactory creates a Dynatrace exporter factory
func NewFactory() exp.Factory {
return exp.NewFactory(
func NewFactory() exporter.Factory {
return exporter.NewFactory(
metadata.Type,
createDefaultConfig,
exp.WithMetrics(createMetricsExporter, metadata.MetricsStability),
exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability),
)
}

Expand All @@ -45,9 +45,9 @@ func createDefaultConfig() component.Config {
// createMetricsExporter creates a metrics exporter based on this
func createMetricsExporter(
ctx context.Context,
set exp.CreateSettings,
set exporter.CreateSettings,
c component.Config,
) (exp.Metrics, error) {
) (exporter.Metrics, error) {

cfg := c.(*dtconfig.Config)

Expand Down
24 changes: 12 additions & 12 deletions exporter/dynatraceexporter/metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/dynatrace-oss/dynatrace-metric-utils-go/metric/dimensions"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/consumererror"
exp "go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.uber.org/zap"

Expand All @@ -31,8 +31,8 @@ const (
cMaxAgeSeconds = 900
)

// NewExporter exports to a Dynatrace Metrics v2 API
func newMetricsExporter(params exp.CreateSettings, cfg *config.Config) *exporter {
// newMetricsExporter exports to a Dynatrace Metrics v2 API
func newMetricsExporter(params exporter.CreateSettings, cfg *config.Config) *metricsExporter {
var confDefaultDims []dimensions.Dimension
for key, value := range cfg.DefaultDimensions {
confDefaultDims = append(confDefaultDims, dimensions.NewDimension(key, value))
Expand All @@ -48,7 +48,7 @@ func newMetricsExporter(params exp.CreateSettings, cfg *config.Config) *exporter
prevPts := ttlmap.New(cSweepIntervalSeconds, cMaxAgeSeconds)
prevPts.Start()

return &exporter{
return &metricsExporter{
settings: params.TelemetrySettings,
cfg: cfg,
defaultDimensions: defaultDimensions,
Expand All @@ -57,8 +57,8 @@ func newMetricsExporter(params exp.CreateSettings, cfg *config.Config) *exporter
}
}

// exporter forwards metrics to a Dynatrace agent
type exporter struct {
// metricsExporter forwards metrics to a Dynatrace agent
type metricsExporter struct {
settings component.TelemetrySettings
cfg *config.Config
client *http.Client
Expand All @@ -82,7 +82,7 @@ func dimensionsFromTags(tags []string) dimensions.NormalizedDimensionList {
return dimensions.NewNormalizedDimensionList(dims...)
}

func (e *exporter) PushMetricsData(ctx context.Context, md pmetric.Metrics) error {
func (e *metricsExporter) PushMetricsData(ctx context.Context, md pmetric.Metrics) error {
if e.isDisabled {
return nil
}
Expand All @@ -109,7 +109,7 @@ func (e *exporter) PushMetricsData(ctx context.Context, md pmetric.Metrics) erro
return nil
}

func (e *exporter) serializeMetrics(md pmetric.Metrics) []string {
func (e *metricsExporter) serializeMetrics(md pmetric.Metrics) []string {
var lines []string

resourceMetrics := md.ResourceMetrics()
Expand Down Expand Up @@ -154,7 +154,7 @@ var lastLog int64

// send sends a serialized metric batch to Dynatrace.
// An error indicates all lines were dropped regardless of the returned number.
func (e *exporter) send(ctx context.Context, lines []string) error {
func (e *metricsExporter) send(ctx context.Context, lines []string) error {
e.settings.Logger.Debug("Exporting", zap.Int("lines", len(lines)))

if now := time.Now().Unix(); len(lines) > apiconstants.GetPayloadLinesLimit() && now-lastLog > 60 {
Expand Down Expand Up @@ -185,7 +185,7 @@ func (e *exporter) send(ctx context.Context, lines []string) error {

// send sends a serialized metric batch to Dynatrace.
// An error indicates all lines were dropped regardless of the returned number.
func (e *exporter) sendBatch(ctx context.Context, lines []string) error {
func (e *metricsExporter) sendBatch(ctx context.Context, lines []string) error {
message := strings.Join(lines, "\n")
e.settings.Logger.Debug(
"sending a batch of metric lines",
Expand Down Expand Up @@ -278,7 +278,7 @@ func (e *exporter) sendBatch(ctx context.Context, lines []string) error {
}

// start starts the exporter
func (e *exporter) start(_ context.Context, host component.Host) (err error) {
func (e *metricsExporter) start(_ context.Context, host component.Host) (err error) {
client, err := e.cfg.HTTPClientSettings.ToClient(host, e.settings)
if err != nil {
e.settings.Logger.Error("Failed to construct HTTP client", zap.Error(err))
Expand All @@ -290,7 +290,7 @@ func (e *exporter) start(_ context.Context, host component.Host) (err error) {
return nil
}

func (e *exporter) unmarshalResponseBody(resp *http.Response) (metricsResponse, error) {
func (e *metricsExporter) unmarshalResponseBody(resp *http.Response) (metricsResponse, error) {
bodyBytes, err := io.ReadAll(resp.Body)
responseBody := metricsResponse{}
if err != nil {
Expand Down
24 changes: 12 additions & 12 deletions exporter/dynatraceexporter/metrics_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func Test_exporter_PushMetricsData(t *testing.T) {
}

t.Run(test.name, func(t *testing.T) {
e := &exporter{
e := &metricsExporter{
settings: test.fields.settings,
cfg: test.fields.cfg,
client: test.fields.client,
Expand Down Expand Up @@ -305,7 +305,7 @@ func Test_SumMetrics(t *testing.T) {
prevPts := ttlmap.New(cSweepIntervalSeconds, cMaxAgeSeconds)

// set up the exporter
exp := &exporter{
exp := &metricsExporter{
settings: componenttest.NewNopTelemetrySettings(),
cfg: &config.Config{
APIToken: "token",
Expand Down Expand Up @@ -368,7 +368,7 @@ func Test_exporter_PushMetricsData_EmptyPayload(t *testing.T) {
noneMetric := metrics.AppendEmpty()
noneMetric.SetName("none")

e := &exporter{
e := &metricsExporter{
settings: componenttest.NewNopTelemetrySettings(),
cfg: &config.Config{
HTTPClientSettings: confighttp.HTTPClientSettings{Endpoint: ts.URL},
Expand Down Expand Up @@ -405,7 +405,7 @@ func Test_exporter_PushMetricsData_isDisabled(t *testing.T) {
intGaugeDataPoint.SetIntValue(10)
intGaugeDataPoint.SetTimestamp(testTimestamp)

e := &exporter{
e := &metricsExporter{
settings: componenttest.NewNopTelemetrySettings(),
cfg: &config.Config{
HTTPClientSettings: confighttp.HTTPClientSettings{Endpoint: ts.URL},
Expand All @@ -431,7 +431,7 @@ func Test_exporter_send_BadRequest(t *testing.T) {
}))
defer ts.Close()

e := &exporter{
e := &metricsExporter{
settings: componenttest.NewNopTelemetrySettings(),
cfg: &config.Config{
HTTPClientSettings: confighttp.HTTPClientSettings{Endpoint: ts.URL},
Expand All @@ -456,7 +456,7 @@ func Test_exporter_send_Unauthorized(t *testing.T) {
}))
defer ts.Close()

e := &exporter{
e := &metricsExporter{
settings: componenttest.NewNopTelemetrySettings(),
cfg: &config.Config{
HTTPClientSettings: confighttp.HTTPClientSettings{Endpoint: ts.URL},
Expand All @@ -481,7 +481,7 @@ func Test_exporter_send_TooLarge(t *testing.T) {
}))
defer ts.Close()

e := &exporter{
e := &metricsExporter{
settings: componenttest.NewNopTelemetrySettings(),
cfg: &config.Config{
HTTPClientSettings: confighttp.HTTPClientSettings{Endpoint: ts.URL},
Expand All @@ -506,7 +506,7 @@ func Test_exporter_send_NotFound(t *testing.T) {
}))
defer ts.Close()

e := &exporter{
e := &metricsExporter{
settings: componenttest.NewNopTelemetrySettings(),
cfg: &config.Config{
APIToken: "token",
Expand Down Expand Up @@ -534,7 +534,7 @@ func Test_exporter_send_TooManyRequests(t *testing.T) {
}))
defer ts.Close()

e := &exporter{
e := &metricsExporter{
settings: componenttest.NewNopTelemetrySettings(),
cfg: &config.Config{
APIToken: "token",
Expand All @@ -557,7 +557,7 @@ func Test_exporter_send_MiscellaneousErrorCode(t *testing.T) {
}))
defer ts.Close()

e := &exporter{
e := &metricsExporter{
settings: componenttest.NewNopTelemetrySettings(),
cfg: &config.Config{
APIToken: "token",
Expand Down Expand Up @@ -588,7 +588,7 @@ func Test_exporter_send_chunking(t *testing.T) {
}))
defer ts.Close()

e := &exporter{
e := &metricsExporter{
settings: componenttest.NewNopTelemetrySettings(),
cfg: &config.Config{
HTTPClientSettings: confighttp.HTTPClientSettings{Endpoint: ts.URL},
Expand Down Expand Up @@ -672,7 +672,7 @@ func Test_exporter_PushMetricsData_Error(t *testing.T) {
}

t.Run(test.name, func(t *testing.T) {
e := &exporter{
e := &metricsExporter{
settings: componenttest.NewNopTelemetrySettings(),
cfg: test.fields.cfg,
client: test.fields.client,
Expand Down

0 comments on commit c20f62e

Please sign in to comment.