Skip to content

Commit

Permalink
Merge branch 'main' into chore/flag-autoscaling-v2beta2
Browse files Browse the repository at this point in the history
  • Loading branch information
prashant-shahi authored Sep 8, 2023
2 parents e1d1ae6 + 639d4da commit 1528480
Show file tree
Hide file tree
Showing 36 changed files with 272 additions and 134 deletions.
27 changes: 27 additions & 0 deletions .chloggen/awsemf_stdoutpanic.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: bug_fix

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix possible panic in when configuration option `awsemf.output_destination:stdout` is set

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

# (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: []
27 changes: 27 additions & 0 deletions .chloggen/pkg-stanza-encoding-2.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: pkg/stanza

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Move tokenize.SplitterConfig.Encoding to fileconsumer.Config.Encoding

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

# (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]
29 changes: 29 additions & 0 deletions .chloggen/pkg-stanza-trim-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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: pkg/stanza

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Extract whitespace trim configuration into trim.Config

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

# (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: |
- PreserveLeading and PreserveTrailing removed from tokenize.SplitterConfig.
- PreserveLeadingWhitespaces and PreserveTrailingWhitespaces removed from tcp.BaseConfig and udp.BaseConfig.
# 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]
27 changes: 27 additions & 0 deletions .chloggen/prometheus-suffixes-default.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: prometheusexporters

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Append prometheus type and unit suffixes by default in prometheus exporters.

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

# (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: Suffixes can be disabled by setting add_metric_suffixes to false on the exporter.

# 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]
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ linters-settings:

linters:
enable:
- decorder
- depguard
- errcheck
- errorlint
Expand Down
2 changes: 1 addition & 1 deletion cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ require (
github.com/coreos/go-oidc v2.2.1+incompatible // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cskr/pubsub v1.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/denisenkom/go-mssqldb v0.12.2 // indirect
Expand Down
3 changes: 2 additions & 1 deletion cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ require (
github.com/coreos/go-oidc v2.2.1+incompatible // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cskr/pubsub v1.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/denisenkom/go-mssqldb v0.12.2 // indirect
Expand Down
3 changes: 2 additions & 1 deletion cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,17 @@ func (emf *emfExporter) pushMetricsData(_ context.Context, md pmetric.Metrics) e

for _, groupedMetric := range groupedMetrics {
cWMetric := translateGroupedMetricToCWMetric(groupedMetric, emf.config)
putLogEvent := translateCWMetricToEMF(cWMetric, emf.config)
putLogEvent, err := translateCWMetricToEMF(cWMetric, emf.config)
if err != nil {
return err
}
// Currently we only support two options for "OutputDestination".
if strings.EqualFold(outputDestination, outputDestinationStdout) {
fmt.Println(*putLogEvent.InputLogEvent.Message)
if putLogEvent != nil &&
putLogEvent.InputLogEvent != nil &&
putLogEvent.InputLogEvent.Message != nil {
fmt.Println(*putLogEvent.InputLogEvent.Message)
}
} else if strings.EqualFold(outputDestination, outputDestinationCloudWatch) {
logGroup := groupedMetric.metadata.logGroup
logStream := groupedMetric.metadata.logStream
Expand Down
6 changes: 3 additions & 3 deletions exporter/awsemfexporter/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func groupedMetricToCWMeasurementsWithFilters(groupedMetric *groupedMetric, conf
}

// translateCWMetricToEMF converts CloudWatch Metric format to EMF.
func translateCWMetricToEMF(cWMetric *cWMetrics, config *Config) *cwlogs.Event {
func translateCWMetricToEMF(cWMetric *cWMetrics, config *Config) (*cwlogs.Event, error) {
// convert CWMetric into map format for compatible with PLE input
fieldMap := cWMetric.fields

Expand Down Expand Up @@ -433,7 +433,7 @@ func translateCWMetricToEMF(cWMetric *cWMetrics, config *Config) *cwlogs.Event {

pleMsg, err := json.Marshal(fieldMap)
if err != nil {
return nil
return nil, err
}

metricCreationTime := cWMetric.timestampMs
Expand All @@ -443,5 +443,5 @@ func translateCWMetricToEMF(cWMetric *cWMetrics, config *Config) *cwlogs.Event {
)
logEvent.GeneratedTime = time.Unix(0, metricCreationTime*int64(time.Millisecond))

return logEvent
return logEvent, nil
}
6 changes: 4 additions & 2 deletions exporter/awsemfexporter/metric_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ func TestTranslateCWMetricToEMF(t *testing.T) {
measurements: tc.measurements,
}

emfLogEvent := translateCWMetricToEMF(cloudwatchMetric, config)
emfLogEvent, err := translateCWMetricToEMF(cloudwatchMetric, config)
require.NoError(t, err)

assert.Equal(t, tc.expectedEMFLogEvent, *emfLogEvent.InputLogEvent.Message)
})
Expand Down Expand Up @@ -2174,7 +2175,8 @@ func BenchmarkTranslateCWMetricToEMF(b *testing.B) {

b.ResetTimer()
for n := 0; n < b.N; n++ {
translateCWMetricToEMF(met, &Config{})
_, err := translateCWMetricToEMF(met, &Config{})
require.NoError(b, err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ require (
github.com/coreos/go-oidc v2.2.1+incompatible // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cskr/pubsub v1.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/denisenkom/go-mssqldb v0.12.2 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 17 additions & 12 deletions pkg/stanza/fileconsumer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/tokenize"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/trim"
)

const (
defaultMaxLogSize = 1024 * 1024
defaultMaxConcurrentFiles = 1024
defaultEncoding = "utf-8"
)

var allowFileDeletion = featuregate.GlobalRegistry().MustRegister(
Expand All @@ -51,6 +53,7 @@ func NewConfig() *Config {
IncludeFilePathResolved: false,
PollInterval: 200 * time.Millisecond,
Splitter: tokenize.NewSplitterConfig(),
Encoding: defaultEncoding,
StartAt: "end",
FingerprintSize: fingerprint.DefaultSize,
MaxLogSize: defaultMaxLogSize,
Expand All @@ -74,6 +77,8 @@ type Config struct {
MaxBatches int `mapstructure:"max_batches,omitempty"`
DeleteAfterRead bool `mapstructure:"delete_after_read,omitempty"`
Splitter tokenize.SplitterConfig `mapstructure:",squash,omitempty"`
TrimConfig trim.Config `mapstructure:",squash,omitempty"`
Encoding string `mapstructure:"encoding,omitempty"`
Header *HeaderConfig `mapstructure:"header,omitempty"`
}

Expand All @@ -88,8 +93,13 @@ func (c Config) Build(logger *zap.SugaredLogger, emit emit.Callback) (*Manager,
return nil, err
}

enc, err := decode.LookupEncoding(c.Encoding)
if err != nil {
return nil, err
}

// Ensure that splitter is buildable
factory := splitter.NewMultilineFactory(c.Splitter, int(c.MaxLogSize))
factory := splitter.NewMultilineFactory(c.Splitter, enc, int(c.MaxLogSize), c.TrimConfig.Func())
if _, err := factory.Build(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -130,13 +140,13 @@ func (c Config) buildManager(logger *zap.SugaredLogger, emit emit.Callback, fact
return nil, fmt.Errorf("invalid start_at location '%s'", c.StartAt)
}

enc, err := decode.LookupEncoding(c.Encoding)
if err != nil {
return nil, fmt.Errorf("failed to find encoding: %w", err)
}

var hCfg *header.Config
if c.Header != nil {
enc, err := decode.LookupEncoding(c.Splitter.Encoding)
if err != nil {
return nil, fmt.Errorf("failed to create encoding: %w", err)
}

hCfg, err = header.NewConfig(c.Header.Pattern, c.Header.MetadataOperators, enc)
if err != nil {
return nil, fmt.Errorf("failed to build header config: %w", err)
Expand All @@ -148,11 +158,6 @@ func (c Config) buildManager(logger *zap.SugaredLogger, emit emit.Callback, fact
return nil, err
}

enc, err := decode.LookupEncoding(c.Splitter.Encoding)
if err != nil {
return nil, err
}

return &Manager{
SugaredLogger: logger.With("component", "fileconsumer"),
cancel: func() {},
Expand Down Expand Up @@ -220,7 +225,7 @@ func (c Config) validate() error {
return errors.New("`max_batches` must not be negative")
}

enc, err := decode.LookupEncoding(c.Splitter.Encoding)
enc, err := decode.LookupEncoding(c.Encoding)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/stanza/fileconsumer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@ func TestUnmarshal(t *testing.T) {
Name: "encoding_lower",
Expect: func() *mockOperatorConfig {
cfg := NewConfig()
cfg.Splitter.Encoding = "utf-16le"
cfg.Encoding = "utf-16le"
return newMockOperatorConfig(cfg)
}(),
},
{
Name: "encoding_upper",
Expect: func() *mockOperatorConfig {
cfg := NewConfig()
cfg.Splitter.Encoding = "UTF-16lE"
cfg.Encoding = "UTF-16lE"
return newMockOperatorConfig(cfg)
}(),
},
Expand Down Expand Up @@ -486,7 +486,7 @@ func TestBuild(t *testing.T) {
{
"InvalidEncoding",
func(f *Config) {
f.Splitter.Encoding = "UTF-3233"
f.Encoding = "UTF-3233"
},
require.Error,
nil,
Expand Down Expand Up @@ -681,7 +681,7 @@ func TestBuildWithSplitFunc(t *testing.T) {
{
"InvalidEncoding",
func(f *Config) {
f.Splitter.Encoding = "UTF-3233"
f.Encoding = "UTF-3233"
},
require.Error,
nil,
Expand Down
6 changes: 3 additions & 3 deletions pkg/stanza/fileconsumer/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func TestReadUsingNopEncoding(t *testing.T) {
cfg := NewConfig().includeDir(tempDir)
cfg.StartAt = "beginning"
cfg.MaxLogSize = 8
cfg.Splitter.Encoding = "nop"
cfg.Encoding = "nop"
operator, emitCalls := buildTestManager(t, cfg)

// Create a file, then start
Expand Down Expand Up @@ -421,7 +421,7 @@ func TestNopEncodingDifferentLogSizes(t *testing.T) {
cfg := NewConfig().includeDir(tempDir)
cfg.StartAt = "beginning"
cfg.MaxLogSize = tc.maxLogSize
cfg.Splitter.Encoding = "nop"
cfg.Encoding = "nop"
operator, emitCalls := buildTestManager(t, cfg)

// Create a file, then start
Expand Down Expand Up @@ -1289,7 +1289,7 @@ func TestEncodings(t *testing.T) {
tempDir := t.TempDir()
cfg := NewConfig().includeDir(tempDir)
cfg.StartAt = "beginning"
cfg.Splitter.Encoding = tc.encoding
cfg.Encoding = tc.encoding
operator, emitCalls := buildTestManager(t, cfg)

// Populate the file
Expand Down
Loading

0 comments on commit 1528480

Please sign in to comment.