diff --git a/exporter/opensearchexporter/config.go b/exporter/opensearchexporter/config.go index efeb844fb942..387601d7d51b 100644 --- a/exporter/opensearchexporter/config.go +++ b/exporter/opensearchexporter/config.go @@ -5,7 +5,6 @@ package opensearchexporter // import "github.com/open-telemetry/opentelemetry-co import ( "errors" - "fmt" "strings" "go.opentelemetry.io/collector/config/confighttp" @@ -22,6 +21,9 @@ const ( // defaultBulkAction value is used when component.Config.BulkAction is not set. defaultBulkAction = "create" + + // defaultMappingMode value is used when component.Config.MappingSettings.Mode is not set. + defaultMappingMode = "ss4o" ) // Config defines configuration for OpenSearch exporter. @@ -34,8 +36,8 @@ type Config struct { // The Observability indices would follow the recommended for immutable data stream ingestion pattern using // the data_stream concepts. See https://opensearch.org/docs/latest/dashboards/im-dashboards/datastream/ // Index pattern will follow the next naming template ss4o_{type}-{dataset}-{namespace} - Namespace string `mapstructure:"namespace"` Dataset string `mapstructure:"dataset"` + Namespace string `mapstructure:"namespace"` // BulkAction configures the action for ingesting data. Only `create` and `index` are allowed here. // If not specified, the default value `create` will be used. @@ -43,14 +45,15 @@ type Config struct { } var ( - errConfigNoEndpoint = errors.New("endpoint must be specified") - errDatasetNoValue = errors.New("dataset must be specified") - errNamespaceNoValue = errors.New("namespace must be specified") - errBulkActionInvalid = errors.New("bulk_action can either be `create` or `index`") + errConfigNoEndpoint = errors.New("endpoint must be specified") + errDatasetNoValue = errors.New("dataset must be specified") + errNamespaceNoValue = errors.New("namespace must be specified") + errBulkActionInvalid = errors.New("bulk_action can either be `create` or `index`") + errMappingModeInvalid = errors.New("mapping.mode is invalid") ) type MappingsSettings struct { - // Mode configures the field mappings. + // Mode configures the field mappings. Uses SS4O by default. Mode string `mapstructure:"mode"` // Additional field mappings. @@ -75,38 +78,34 @@ type MappingMode int // Enum values for MappingMode. const ( - MappingNone MappingMode = iota + MappingSS4O MappingMode = iota MappingECS MappingFlattenAttributes ) func (m MappingMode) String() string { switch m { - case MappingNone: - return "" + case MappingSS4O: + return "ss4o" case MappingECS: return "ecs" case MappingFlattenAttributes: return "flatten_attributes" default: - return "" + return "ss4o" } } var mappingModes = func() map[string]MappingMode { table := map[string]MappingMode{} for _, m := range []MappingMode{ - MappingNone, MappingECS, + MappingSS4O, MappingFlattenAttributes, } { table[strings.ToLower(m.String())] = m } - // config aliases - table["no"] = MappingNone - table["none"] = MappingNone - return table }() @@ -123,16 +122,12 @@ func (cfg *Config) Validate() error { multiErr = append(multiErr, errNamespaceNoValue) } - if len(cfg.BulkAction) == 0 { - cfg.BulkAction = "create" - } - if cfg.BulkAction != "create" && cfg.BulkAction != "index" { return errBulkActionInvalid } if _, ok := mappingModes[cfg.MappingsSettings.Mode]; !ok { - return fmt.Errorf("unknown mapping mode %v", cfg.MappingsSettings.Mode) + multiErr = append(multiErr, errMappingModeInvalid) } return multierr.Combine(multiErr...) diff --git a/exporter/opensearchexporter/config_test.go b/exporter/opensearchexporter/config_test.go index c941a880396a..4a6f27ff8e03 100644 --- a/exporter/opensearchexporter/config_test.go +++ b/exporter/opensearchexporter/config_test.go @@ -68,6 +68,9 @@ func TestLoadConfig(t *testing.T) { RandomizationFactor: 0.5, }, BulkAction: defaultBulkAction, + MappingsSettings: MappingsSettings{ + Mode: "ss4o", + }, }, configValidateAssert: assert.NoError, }, diff --git a/exporter/opensearchexporter/encoder.go b/exporter/opensearchexporter/encoder.go index c947bdfccc6e..bc64ea1e9916 100644 --- a/exporter/opensearchexporter/encoder.go +++ b/exporter/opensearchexporter/encoder.go @@ -58,7 +58,7 @@ func (m *encodeModel) encodeLogSSO( schemaURL string, record plog.LogRecord, ) ([]byte, error) { - sso := ssoLog{} + sso := ssoRecord{} sso.Attributes = record.Attributes().AsRaw() sso.Body = record.Body().AsString() diff --git a/exporter/opensearchexporter/factory.go b/exporter/opensearchexporter/factory.go index 44a3a12bc5fe..392d85040d72 100644 --- a/exporter/opensearchexporter/factory.go +++ b/exporter/opensearchexporter/factory.go @@ -34,6 +34,7 @@ func newDefaultConfig() component.Config { Dataset: defaultDataset, BulkAction: defaultBulkAction, RetrySettings: exporterhelper.NewDefaultRetrySettings(), + MappingsSettings: MappingsSettings{Mode: defaultMappingMode}, } } diff --git a/exporter/opensearchexporter/sso_model.go b/exporter/opensearchexporter/sso_model.go index c5bf998a56ce..a9dfa2baa42a 100644 --- a/exporter/opensearchexporter/sso_model.go +++ b/exporter/opensearchexporter/sso_model.go @@ -59,7 +59,7 @@ type ssoSpan struct { TraceState string `json:"traceState"` } -type ssoLog struct { +type ssoRecord struct { Attributes map[string]any `json:"attributes,omitempty"` Body string `json:"body"` InstrumentationScope struct {