Skip to content

Commit

Permalink
Merge branch 'main' into kafka-header-extract
Browse files Browse the repository at this point in the history
  • Loading branch information
VihasMakwana authored and Vihas Splunk committed Sep 21, 2023
2 parents 8c81cfe + ccfd8b1 commit 3514800
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 107 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]
28 changes: 28 additions & 0 deletions .chloggen/pkg-stanza-severity-text-overwrite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use this changelog template to create an entry for release notes.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add 'overwrite_text' option to severity parser.

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

# (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: |
Allows the user to overwrite the text of the severity parser with the official string representation of the severity level.
# 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: []
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
50 changes: 25 additions & 25 deletions pkg/stanza/entry/severity.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,31 @@ const (
)

var sevText = map[Severity]string{
Default: "default",
Trace: "trace",
Trace2: "trace2",
Trace3: "trace3",
Trace4: "trace4",
Debug: "debug",
Debug2: "debug2",
Debug3: "debug3",
Debug4: "debug4",
Info: "info",
Info2: "info2",
Info3: "info3",
Info4: "info4",
Warn: "warn",
Warn2: "warn2",
Warn3: "warn3",
Warn4: "warn4",
Error: "error",
Error2: "error2",
Error3: "error3",
Error4: "error4",
Fatal: "fatal",
Fatal2: "fatal2",
Fatal3: "fatal3",
Fatal4: "fatal4",
Default: "DEFAULT",
Trace: "TRACE",
Trace2: "TRACE2",
Trace3: "TRACE3",
Trace4: "TRACE4",
Debug: "DEBUG",
Debug2: "DEBUG2",
Debug3: "DEBUG3",
Debug4: "DEBUG4",
Info: "INFO",
Info2: "INFO2",
Info3: "INFO3",
Info4: "INFO4",
Warn: "WARN",
Warn2: "WARN2",
Warn3: "WARN3",
Warn4: "WARN4",
Error: "ERROR",
Error2: "ERROR2",
Error3: "ERROR3",
Error4: "ERROR4",
Fatal: "FATAL",
Fatal2: "FATAL2",
Fatal3: "FATAL3",
Fatal4: "FATAL4",
}

// ToString converts a severity to a string
Expand Down
Loading

0 comments on commit 3514800

Please sign in to comment.