Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use enum instead of strings for ES mappings #6068

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Saumya40-codes
Copy link

@Saumya40-codes Saumya40-codes commented Oct 7, 2024

Which problem is this PR solving?

Description of the changes

  • Currently in plugin/storage/es/mappings/mapping.go we are using bare string inorder to for the file mapping. This PR refractors this approach to use enums instead of string

How was this change tested?

  • running go test

Checklist

Signed-off-by: Saumya Shah <saumyabshah90@gmail.com>
Signed-off-by: Saumya Shah <saumyabshah90@gmail.com>
Signed-off-by: Saumya Shah <saumyabshah90@gmail.com>
@Saumya40-codes Saumya40-codes changed the title [hygiene] Refactor ES mappings to use enum instead of strings refactor: use enum instead of strings for ES mappings Oct 8, 2024
Signed-off-by: Saumya Shah <saumyabshah90@gmail.com>
Signed-off-by: Saumya Shah <saumyabshah90@gmail.com>
@Saumya40-codes Saumya40-codes marked this pull request as ready for review October 8, 2024 14:32
@Saumya40-codes Saumya40-codes requested a review from a team as a code owner October 8, 2024 14:32
@dosubot dosubot bot added the area/storage label Oct 8, 2024
@Saumya40-codes
Copy link
Author

anything im missing out on here @yurishkuro ?

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

Attention: Patch coverage is 70.14925% with 20 lines in your changes missing coverage. Please review.

Project coverage is 96.81%. Comparing base (3551cf7) to head (28dc4e5).

Files with missing lines Patch % Lines
cmd/es-rollover/app/init/action.go 44.44% 9 Missing and 1 partial ⚠️
cmd/esmapping-generator/app/renderer/render.go 70.00% 5 Missing and 1 partial ⚠️
plugin/storage/es/mappings/mapping.go 86.20% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6068      +/-   ##
==========================================
- Coverage   96.92%   96.81%   -0.12%     
==========================================
  Files         349      349              
  Lines       16598    16650      +52     
==========================================
+ Hits        16087    16119      +32     
- Misses        328      345      +17     
- Partials      183      186       +3     
Flag Coverage Δ
badger_v1 7.97% <0.00%> (-0.02%) ⬇️
badger_v2 1.81% <0.00%> (-0.01%) ⬇️
cassandra-4.x-v1 15.75% <0.00%> (-0.04%) ⬇️
cassandra-4.x-v2 1.74% <0.00%> (-0.01%) ⬇️
cassandra-5.x-v1 15.75% <0.00%> (-0.04%) ⬇️
cassandra-5.x-v2 1.74% <0.00%> (-0.01%) ⬇️
elasticsearch-6.x-v1 18.80% <62.06%> (+0.10%) ⬆️
elasticsearch-7.x-v1 18.87% <62.06%> (+0.11%) ⬆️
elasticsearch-8.x-v1 19.05% <62.06%> (+0.10%) ⬆️
elasticsearch-8.x-v2 1.80% <0.00%> (-0.02%) ⬇️
grpc_v1 9.35% <0.00%> (-0.01%) ⬇️
grpc_v2 7.09% <0.00%> (-0.03%) ⬇️
kafka-v1 9.67% <0.00%> (-0.03%) ⬇️
kafka-v2 1.81% <0.00%> (-0.01%) ⬇️
memory_v2 1.81% <0.00%> (+<0.01%) ⬆️
opensearch-1.x-v1 18.90% <62.06%> (+0.11%) ⬆️
opensearch-2.x-v1 18.92% <62.06%> (+0.12%) ⬆️
opensearch-2.x-v2 1.81% <0.00%> (+<0.01%) ⬆️
tailsampling-processor 0.46% <0.00%> (-0.01%) ⬇️
unittests 95.60% <70.14%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

{mapping: SpanMapping, esVersion: 6},
{mapping: ServiceMapping, esVersion: 8},
{mapping: ServiceMapping, esVersion: 7},
{mapping: DependenciesMapping, esVersion: 6},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{mapping: DependenciesMapping, esVersion: 6},
{mapping: ServiceMapping, esVersion: 6},

case SamplingMapping:
return "jaeger-sampling", nil
default:
return "", fmt.Errorf("Unknown mapping type %d", mt)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String() methods usually do not return errors. You can return "unknown" string.

return ok
}

// stringToMappingType converts a string to a MappingType
func stringToMappingType(val string) (mappings.MappingType, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this translation can be co-located with the MappingType definition:

func MappingTypeFromString(val string) (MappingType, error)

"jaeger-service": {},
"jaeger-dependencies": {},
"jaeger-sampling": {},
var supportedMappings = map[mappings.MappingType]struct{}{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os this still needed?

return "", err
}

return mappingBuilder.GetMapping(mappingType)
}

// IsValidOption checks if passed option is a valid index template.
func IsValidOption(val string) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this function is needed. Wherever it's called the called can instead do

if m, err := MappingTypeFromString(val); err == nil {
  // 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[hygiene] Use enum instead of a string
2 participants