Skip to content

Commit

Permalink
Use DisableLogsFieldSearch flag to deduce es logs field mapping in te…
Browse files Browse the repository at this point in the history
…mplate

Signed-off-by: Parvesh Chaudhary <parveshchaudhary111@gmail.com>

Co-authored-by: Raghav Gupta <ragaws1674@gmail.com>
  • Loading branch information
pc-coder and raghav1674 committed Sep 8, 2024
1 parent 257a562 commit 5793145
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 229 deletions.
2 changes: 1 addition & 1 deletion cmd/es-rollover/app/init/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c Action) getMapping(version uint, templateName string) (string, error) {
UseILM: c.Config.UseILM,
ILMPolicyName: c.Config.ILMPolicyName,
EsVersion: version,
LogsFieldsType: mappings.ParseFieldType(c.Config.DisableLogsFieldSearch),
DisableLogsFieldSearch: c.Config.DisableLogsFieldSearch,
}
return mappingBuilder.GetMapping(templateName)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/esmapping-generator/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Options struct {
IndexPrefix string
UseILM string // using string as util is being used in python and using bool leads to type issues.
ILMPolicyName string
DisableLogsFieldSearch string
DisableLogsFieldSearch string // using string as util is being used in python and using bool leads to type issues.
}

const (
Expand Down
20 changes: 12 additions & 8 deletions cmd/esmapping-generator/app/renderer/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ func GetMappingAsString(builder es.TemplateBuilder, opt *app.Options) (string, e
if err != nil {
return "", err
}
disableLogsFieldSearch, err := strconv.ParseBool(opt.DisableLogsFieldSearch)
if err != nil {
return "", err
}

mappingBuilder := mappings.MappingBuilder{
TemplateBuilder: builder,
Shards: opt.Shards,
Replicas: opt.Replicas,
EsVersion: opt.EsVersion,
IndexPrefix: opt.IndexPrefix,
UseILM: enableILM,
ILMPolicyName: opt.ILMPolicyName,
LogsFieldsType: mappings.ParseFieldType(opt.DisableLogsFieldSearch),
TemplateBuilder: builder,
Shards: opt.Shards,
Replicas: opt.Replicas,
EsVersion: opt.EsVersion,
IndexPrefix: opt.IndexPrefix,
UseILM: enableILM,
ILMPolicyName: opt.ILMPolicyName,
DisableLogsFieldSearch: disableLogsFieldSearch,
}
return mappingBuilder.GetMapping(opt.Mapping)
}
Expand Down
54 changes: 19 additions & 35 deletions cmd/esmapping-generator/app/renderer/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ func Test_getMappingAsString(t *testing.T) {
IndexPrefix: "test-",
UseILM: "true",
ILMPolicyName: "jaeger-test-policy",
DisableLogsFieldSearch: "false",
DisableLogsFieldSearch: "true",
},
wantedMapping: &mappings.MappingBuilder{
EsVersion: 7,
Shards: 5,
Replicas: 1,
IndexPrefix: "test-",
UseILM: true,
ILMPolicyName: "jaeger-test-policy",
LogsFieldsType: mappings.NestedFieldType,
EsVersion: 7,
Shards: 5,
Replicas: 1,
IndexPrefix: "test-",
UseILM: true,
ILMPolicyName: "jaeger-test-policy",
DisableLogsFieldSearch: true,
},
want: "ES version 7",
},
Expand All @@ -79,13 +79,13 @@ func Test_getMappingAsString(t *testing.T) {
DisableLogsFieldSearch: "false",
},
wantedMapping: &mappings.MappingBuilder{
EsVersion: 7,
Shards: 5,
Replicas: 1,
IndexPrefix: "test-",
UseILM: false,
ILMPolicyName: "jaeger-test-policy",
LogsFieldsType: mappings.ObjectFieldType,
EsVersion: 7,
Shards: 5,
Replicas: 1,
IndexPrefix: "test-",
UseILM: false,
ILMPolicyName: "jaeger-test-policy",
DisableLogsFieldSearch: false,
},
wantErr: errors.New("parse error"),
},
Expand All @@ -100,16 +100,8 @@ func Test_getMappingAsString(t *testing.T) {
UseILM: "foo",
ILMPolicyName: "jaeger-test-policy",
},
wantedMapping: &mappings.MappingBuilder{
EsVersion: 7,
Shards: 5,
Replicas: 1,
IndexPrefix: "test-",
UseILM: false,
ILMPolicyName: "jaeger-test-policy",
LogsFieldsType: mappings.ObjectFieldType,
},
wantErr: errors.New("strconv.ParseBool: parsing \"foo\": invalid syntax"),
wantedMapping: &mappings.MappingBuilder{},
wantErr: errors.New("strconv.ParseBool: parsing \"foo\": invalid syntax"),
},
{
name: "Parse bool error for DisableLogsFieldSearch",
Expand All @@ -123,16 +115,8 @@ func Test_getMappingAsString(t *testing.T) {
ILMPolicyName: "jaeger-test-policy",
DisableLogsFieldSearch: "foo",
},
wantedMapping: &mappings.MappingBuilder{
EsVersion: 7,
Shards: 5,
Replicas: 1,
IndexPrefix: "test-",
UseILM: false,
ILMPolicyName: "jaeger-test-policy",
LogsFieldsType: mappings.ObjectFieldType,
},
wantErr: errors.New("strconv.ParseBool: parsing \"foo\": invalid syntax"),
wantedMapping: &mappings.MappingBuilder{},
wantErr: errors.New("strconv.ParseBool: parsing \"foo\": invalid syntax"),
},
}
for _, tt := range tests {
Expand Down
1 change: 1 addition & 0 deletions plugin/storage/es/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func mappingBuilderFromConfig(cfg *config.Configuration) mappings.MappingBuilder
PrioritySpanTemplate: cfg.PrioritySpanTemplate,
PriorityServiceTemplate: cfg.PriorityServiceTemplate,
PriorityDependenciesTemplate: cfg.PriorityDependenciesTemplate,
DisableLogsFieldSearch: cfg.DisableLogsFieldSearch,
}
}

Expand Down
58 changes: 0 additions & 58 deletions plugin/storage/es/mappings/fieldType.go

This file was deleted.

109 changes: 0 additions & 109 deletions plugin/storage/es/mappings/fieldType_test.go

This file was deleted.

12 changes: 10 additions & 2 deletions plugin/storage/es/mappings/jaeger-span-6.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,22 @@
"type":"integer"
},
"logs":{
"type":"{{ .LogsFieldsType }}",
{{- if .DisableLogsFieldSearch }}
"type":"object",
{{- else }}
"type":"nested",
{{- end }}
"dynamic":false,
"properties":{
"timestamp":{
"type":"long"
},
"fields":{
"type":"{{ .LogsFieldsType }}",
{{- if .DisableLogsFieldSearch }}
"type":"object",
{{- else }}
"type":"nested",
{{- end }}
"dynamic":false,
"properties":{
"key":{
Expand Down
12 changes: 10 additions & 2 deletions plugin/storage/es/mappings/jaeger-span-7.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,22 @@
"type":"integer"
},
"logs":{
"type":"{{ .LogsFieldsType }}",
{{- if .DisableLogsFieldSearch }}
"type":"object",
{{- else }}
"type":"nested",
{{- end }}
"dynamic":false,
"properties":{
"timestamp":{
"type":"long"
},
"fields":{
"type":"{{ .LogsFieldsType }}",
{{- if .DisableLogsFieldSearch }}
"type":"object",
{{- else }}
"type":"nested",
{{- end }}
"dynamic":false,
"properties":{
"key":{
Expand Down
12 changes: 10 additions & 2 deletions plugin/storage/es/mappings/jaeger-span-8.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,22 @@
"type": "integer"
},
"logs": {
"type": "{{ .LogsFieldsType }}",
{{- if .DisableLogsFieldSearch }}
"type": "object",
{{- else }}
"type": "nested",
{{- end }}
"dynamic": false,
"properties": {
"timestamp": {
"type": "long"
},
"fields": {
"type": "{{ .LogsFieldsType }}",
{{- if .DisableLogsFieldSearch }}
"type": "object",
{{- else }}
"type": "nested",
{{- end }}
"dynamic": false,
"properties": {
"key": {
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/mappings/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type MappingBuilder struct {
IndexPrefix string
UseILM bool
ILMPolicyName string
LogsFieldsType FieldType
DisableLogsFieldSearch bool
}

// GetMapping returns the rendered mapping based on elasticsearch version
Expand Down
Loading

0 comments on commit 5793145

Please sign in to comment.