-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[exporter/Sematext] Second PR of New component: Sematext Exporter #37642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andrzej-stencel
merged 34 commits into
open-telemetry:main
from
sematext:Otel-Contrib-Second-PR
Mar 6, 2025
Merged
Changes from 16 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
40ef42e
Add metrics support for Config
AkhigbeEromo 689d903
Add test for config
AkhigbeEromo df50493
Add basic metrics support
AkhigbeEromo 0bcde39
Add changelog
AkhigbeEromo ad0cdd6
Fix lint and Unit tests
AkhigbeEromo 2880243
Correct collector module version
AkhigbeEromo 78cc7c0
Merge branch 'main' into Otel-Contrib-Second-PR
AkhigbeEromo dc30f2e
Update collector module version
AkhigbeEromo 3a4c43e
Merge branch 'main' into Otel-Contrib-Second-PR
AkhigbeEromo 8f3d2f7
Merge branch 'main' into Otel-Contrib-Second-PR
AkhigbeEromo f40edcf
Merge branch 'main' into Otel-Contrib-Second-PR
AkhigbeEromo 66f5869
Merge branch 'main' into Otel-Contrib-Second-PR
AkhigbeEromo c3b0fc3
Update collector module version
AkhigbeEromo 2d4a90c
Remove deprecated component
AkhigbeEromo 59a0b09
Update Collector Module Version
AkhigbeEromo dc4098d
Merge branch 'main' into Otel-Contrib-Second-PR
AkhigbeEromo d41025c
Remove default metrics endpoint and app token
AkhigbeEromo 05a1524
Move Queue Settings to cover both metrics and logs
AkhigbeEromo fdb3910
Update exporter/sematextexporter/config.go
AkhigbeEromo 532ae2e
Update README.md
AkhigbeEromo aeced5d
Remove default for region
AkhigbeEromo 5c3960e
Fix lint issues
AkhigbeEromo 3af5124
Merge branch 'main' into Otel-Contrib-Second-PR
AkhigbeEromo 475e5ce
Update module version
AkhigbeEromo 0a35131
Update README.md
AkhigbeEromo 44ad551
Update config.go
AkhigbeEromo ca70f1d
Update module version
AkhigbeEromo 2d1396d
Merge branch 'main' into Otel-Contrib-Second-PR
AkhigbeEromo 5ada085
Merge branch 'main' into Otel-Contrib-Second-PR
AkhigbeEromo 40a1ece
Update go.mod
AkhigbeEromo 2253617
Update go.sum
AkhigbeEromo 3c1ee0c
Merge branch 'main' into Otel-Contrib-Second-PR
AkhigbeEromo c0a9896
Update exporter/sematextexporter/go.sum
AkhigbeEromo 3ecbc2a
Update exporter/sematextexporter/go.mod
AkhigbeEromo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: new_component | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: sematextexporter | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: basic metrics implementation | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [36465] | ||
|
||
# (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: [user] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package sematextexporter | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cenkalti/backoff/v4" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
"go.opentelemetry.io/collector/config/configopaque" | ||
"go.opentelemetry.io/collector/config/configretry" | ||
"go.opentelemetry.io/collector/confmap/confmaptest" | ||
"go.opentelemetry.io/collector/confmap/xconfmap" | ||
"go.opentelemetry.io/collector/exporter/exporterhelper" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sematextexporter/internal/metadata" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
t.Parallel() | ||
|
||
content, err := os.ReadFile(filepath.Join("testdata", "config.yaml")) | ||
require.NoError(t, err) | ||
|
||
contentStr := strings.ReplaceAll(string(content), "<METRICS_APP_TOKEN>", metricsAppToken) | ||
|
||
tmpConfigPath := filepath.Join("testdata", "config_tmp.yaml") | ||
err = os.WriteFile(tmpConfigPath, []byte(contentStr), 0o600) | ||
require.NoError(t, err) | ||
defer os.Remove(tmpConfigPath) | ||
cm, err := confmaptest.LoadConf(tmpConfigPath) | ||
require.NoError(t, err) | ||
tests := []struct { | ||
id component.ID | ||
expected component.Config | ||
}{ | ||
{ | ||
id: component.NewIDWithName(metadata.Type, "default-config"), | ||
expected: createDefaultConfig(), | ||
}, | ||
{ | ||
id: component.NewIDWithName(metadata.Type, "override-config"), | ||
expected: &Config{ | ||
ClientConfig: confighttp.ClientConfig{ | ||
Timeout: 500 * time.Millisecond, | ||
Headers: map[string]configopaque.String{"User-Agent": "OpenTelemetry -> Sematext"}, | ||
}, | ||
MetricsConfig: MetricsConfig{ | ||
MetricsEndpoint: usMetricsEndpoint, | ||
QueueSettings: exporterhelper.QueueConfig{ | ||
Enabled: true, | ||
NumConsumers: 3, | ||
QueueSize: 10, | ||
}, | ||
AppToken: metricsAppToken, | ||
MetricsSchema: "telegraf-prometheus-v2", | ||
PayloadMaxLines: 72, | ||
PayloadMaxBytes: 27, | ||
}, | ||
|
||
BackOffConfig: configretry.BackOffConfig{ | ||
Enabled: true, | ||
InitialInterval: 1 * time.Second, | ||
MaxInterval: 3 * time.Second, | ||
MaxElapsedTime: 10 * time.Second, | ||
RandomizationFactor: backoff.DefaultRandomizationFactor, | ||
Multiplier: backoff.DefaultMultiplier, | ||
}, | ||
Region: usRegion, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.id.String(), func(t *testing.T) { | ||
factory := NewFactory() | ||
cfg := factory.CreateDefaultConfig() | ||
|
||
sub, err := cm.Sub(tt.id.String()) | ||
require.NoError(t, err) | ||
require.NoError(t, sub.Unmarshal(cfg)) | ||
|
||
assert.NoError(t, xconfmap.Validate(cfg)) | ||
assert.Equal(t, tt.expected, cfg) | ||
}) | ||
} | ||
} | ||
|
||
func TestConfigValidation(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
config *Config | ||
expectError bool | ||
}{ | ||
{ | ||
name: "Valid configuration 1", | ||
config: &Config{ | ||
Region: usRegion, | ||
MetricsConfig: MetricsConfig{ | ||
AppToken: metricsAppToken, | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Valid configuration 2", | ||
config: &Config{ | ||
Region: euRegion, | ||
MetricsConfig: MetricsConfig{ | ||
AppToken: metricsAppToken, | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Invalid region", | ||
config: &Config{ | ||
Region: "ASIA", | ||
MetricsConfig: MetricsConfig{ | ||
AppToken: metricsAppToken, | ||
}, | ||
}, | ||
expectError: true, | ||
}, | ||
{ | ||
name: "Invalid metrics AppToken", | ||
config: &Config{ | ||
Region: usRegion, | ||
MetricsConfig: MetricsConfig{ | ||
AppToken: "short-token", | ||
}, | ||
}, | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := tt.config.Validate() | ||
if tt.expectError { | ||
assert.Error(t, err, "Expected an error for invalid configuration") | ||
} else { | ||
assert.NoError(t, err, "Expected no error for valid configuration") | ||
} | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.