Skip to content

Commit 12903b7

Browse files
committed
[exporter/opensearchexporter] add logstashFormat config to opensearch
1 parent cfc923a commit 12903b7

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: opensearchexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Adding logstashFormat config to opensearch
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [38595]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

exporter/opensearchexporter/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var (
5858
errNamespaceNoValue = errors.New("namespace must be specified")
5959
errBulkActionInvalid = errors.New("bulk_action can either be `create` or `index`")
6060
errMappingModeInvalid = errors.New("mapping.mode is invalid")
61-
errIndexFormatInvalid = errors.New("When LogstashFormat.Enabled is set to true, the index_log field is required.")
61+
errIndexFormatInvalid = errors.New("when LogstashFormat.Enabled is set to true, the index_log field is required")
6262
)
6363

6464
type MappingsSettings struct {

exporter/opensearchexporter/config_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ func TestLoadConfig(t *testing.T) {
7575
Multiplier: 1.5,
7676
RandomizationFactor: 0.5,
7777
},
78+
LogstashFormat: LogstashFormatSettings{
79+
Enabled: false,
80+
PrefixSeparator: "-",
81+
DateFormat: "%Y.%m.%d",
82+
},
7883
BulkAction: defaultBulkAction,
7984
MappingsSettings: MappingsSettings{
8085
Mode: "ss4o",

exporter/opensearchexporter/factory_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ package opensearchexporter
55

66
import (
77
"context"
8+
"testing"
9+
810
"github.com/stretchr/testify/assert"
911
"github.com/stretchr/testify/require"
1012
"go.opentelemetry.io/collector/component/componenttest"
1113
"go.opentelemetry.io/collector/exporter/exportertest"
12-
"testing"
1314

1415
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opensearchexporter/internal/metadata"
1516
)

exporter/opensearchexporter/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ package opensearchexporter
55
import (
66
"bytes"
77
"fmt"
8-
"github.com/lestrrat-go/strftime"
98
"time"
9+
10+
"github.com/lestrrat-go/strftime"
1011
)
1112

1213
func GenerateIndexWithLogstashFormat(index string, conf *LogstashFormatSettings, t time.Time) string {

exporter/opensearchexporter/utils_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ func TestGetSuffixTime(t *testing.T) {
2121
defaultCfg.LogsIndex = "logstash"
2222
defaultCfg.LogstashFormat.PrefixSeparator = "."
2323
otelLogsIndex := GenerateIndexWithLogstashFormat(defaultCfg.LogsIndex, &defaultCfg.LogstashFormat, testTime)
24-
//assert.NoError(t, err)
24+
// assert.NoError(t, err)
2525
assert.Equal(t, "logstash.2023.12.02", otelLogsIndex)
2626

2727
defaultCfg.LogstashFormat.DateFormat = "%Y-%m-%d"
28-
//newOtelLogsIndex, err := GenerateIndexWithLogstashFormat(defaultCfg.LogsIndex, &defaultCfg.LogstashFormat, testTime)
29-
//assert.NoError(t, err)
28+
// newOtelLogsIndex, err := GenerateIndexWithLogstashFormat(defaultCfg.LogsIndex, &defaultCfg.LogstashFormat, testTime)
29+
// assert.NoError(t, err)
3030
newOtelLogsIndex := GenerateIndexWithLogstashFormat(defaultCfg.LogsIndex, &defaultCfg.LogstashFormat, testTime)
3131
assert.Equal(t, "logstash.2023-12-02", newOtelLogsIndex)
3232

3333
defaultCfg.LogstashFormat.DateFormat = "%d/%m/%Y"
34-
//newOtelLogsIndexWithSpecDataFormat, err := GenerateIndexWithLogstashFormat(defaultCfg.LogsIndex, &defaultCfg.LogstashFormat, testTime)
35-
//assert.NoError(t, err)
34+
// newOtelLogsIndexWithSpecDataFormat, err := GenerateIndexWithLogstashFormat(defaultCfg.LogsIndex, &defaultCfg.LogstashFormat, testTime)
35+
// assert.NoError(t, err)
3636
newOtelLogsIndexWithSpecDataFormat := GenerateIndexWithLogstashFormat(defaultCfg.LogsIndex, &defaultCfg.LogstashFormat, testTime)
3737
assert.Equal(t, "logstash.02/12/2023", newOtelLogsIndexWithSpecDataFormat)
3838
}

0 commit comments

Comments
 (0)