-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
646 additions
and
451 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,26 @@ | ||
// Copyright (c) 2025 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package generator | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/esmapping-generator/app" | ||
"github.com/jaegertracing/jaeger/cmd/esmapping-generator/app/renderer" | ||
"github.com/jaegertracing/jaeger/pkg/es" | ||
"github.com/jaegertracing/jaeger/plugin/storage/es/mappings" | ||
) | ||
|
||
func GenerateMappings(options app.Options) (string, error) { | ||
if _, err := mappings.MappingTypeFromString(options.Mapping); err != nil { | ||
return "", fmt.Errorf("invalid mapping type '%s': please pass either 'jaeger-service' or 'jaeger-span' as the mapping type %w", options.Mapping, err) | ||
} | ||
|
||
parsedMapping, err := renderer.GetMappingAsString(es.TextTemplateBuilder{}, &options) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to render mapping to string: %w", err) | ||
} | ||
|
||
return parsedMapping, nil | ||
} |
87 changes: 87 additions & 0 deletions
87
cmd/esmapping-generator/generator/esmapping_generator_test.go
This file contains 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,87 @@ | ||
// Copyright (c) 2025 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package generator | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/crossdock/crossdock-go/assert" | ||
"github.com/crossdock/crossdock-go/require" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/esmapping-generator/app" | ||
"github.com/jaegertracing/jaeger/pkg/testutils" | ||
) | ||
|
||
func TestGenerateMappings(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
options app.Options | ||
expectErr bool | ||
}{ | ||
{ | ||
name: "valid jaeger-span mapping", | ||
options: app.Options{ | ||
Mapping: "jaeger-span", | ||
EsVersion: 7, | ||
Shards: 5, | ||
Replicas: 1, | ||
IndexPrefix: "jaeger-index", | ||
UseILM: "false", | ||
ILMPolicyName: "jaeger-ilm-policy", | ||
}, | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "valid jaeger-service mapping", | ||
options: app.Options{ | ||
Mapping: "jaeger-service", | ||
EsVersion: 7, | ||
Shards: 5, | ||
Replicas: 1, | ||
IndexPrefix: "jaeger-service-index", | ||
UseILM: "true", | ||
ILMPolicyName: "service-ilm-policy", | ||
}, | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "invalid mapping type", | ||
options: app.Options{ | ||
Mapping: "invalid-mapping", | ||
}, | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "missing mapping flag", | ||
options: app.Options{ | ||
Mapping: "", | ||
}, | ||
expectErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result, err := GenerateMappings(tt.options) | ||
if tt.expectErr { | ||
require.Error(t, err, "Expected an error") | ||
} else { | ||
require.NoError(t, err, "Did not expect an error") | ||
|
||
var parsed map[string]interface{} | ||
err = json.Unmarshal([]byte(result), &parsed) | ||
require.NoError(t, err, "Expected valid JSON output") | ||
|
||
assert.NotEmpty(t, parsed["index_patterns"], "Expected index_patterns to be present") | ||
assert.NotEmpty(t, parsed["mappings"], "Expected mappings to be present") | ||
assert.NotEmpty(t, parsed["settings"], "Expected settings to be present") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
testutils.VerifyGoLeaks(m) | ||
} |
This file contains 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 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 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 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 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 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 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 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 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.