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] Seperated the parts of ES-Rollover Config common with ES Config #6516

Closed
wants to merge 3 commits into from

Conversation

Manik2708
Copy link
Contributor

Which problem is this PR solving?

Supporting PR of #6500

Description of the changes

How was this change tested?

  • Unit Tests

Checklist

@Manik2708 Manik2708 requested a review from a team as a code owner January 9, 2025 09:38
@Manik2708 Manik2708 requested a review from mahadzaryab1 January 9, 2025 09:38
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.28%. Comparing base (980dc31) to head (6e98255).
Report is 12 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6516   +/-   ##
=======================================
  Coverage   96.27%   96.28%           
=======================================
  Files         372      373    +1     
  Lines       21283    21301   +18     
=======================================
+ Hits        20491    20509   +18     
  Misses        605      605           
  Partials      187      187           
Flag Coverage Δ
badger_v1 10.64% <0.00%> (-0.03%) ⬇️
badger_v2 2.77% <0.00%> (-0.01%) ⬇️
cassandra-4.x-v1-manual 16.53% <0.00%> (-0.05%) ⬇️
cassandra-4.x-v2-auto 2.70% <0.00%> (-0.01%) ⬇️
cassandra-4.x-v2-manual 2.70% <0.00%> (-0.01%) ⬇️
cassandra-5.x-v1-manual 16.53% <0.00%> (-0.05%) ⬇️
cassandra-5.x-v2-auto 2.70% <0.00%> (-0.01%) ⬇️
cassandra-5.x-v2-manual 2.70% <0.00%> (-0.01%) ⬇️
elasticsearch-6.x-v1 20.18% <0.00%> (-0.06%) ⬇️
elasticsearch-7.x-v1 20.25% <0.00%> (-0.07%) ⬇️
elasticsearch-8.x-v1 20.42% <0.00%> (-0.05%) ⬇️
elasticsearch-8.x-v2 2.77% <0.00%> (+<0.01%) ⬆️
grpc_v1 12.27% <0.00%> (-0.05%) ⬇️
grpc_v2 9.06% <0.00%> (-0.04%) ⬇️
kafka-3.x-v1 10.33% <0.00%> (-0.03%) ⬇️
kafka-3.x-v2 2.77% <0.00%> (-0.01%) ⬇️
memory_v2 2.77% <0.00%> (-0.01%) ⬇️
opensearch-1.x-v1 20.30% <0.00%> (-0.05%) ⬇️
opensearch-2.x-v1 20.29% <0.00%> (-0.07%) ⬇️
opensearch-2.x-v2 2.76% <0.00%> (-0.02%) ⬇️
tailsampling-processor 0.51% <0.00%> (-0.01%) ⬇️
unittests 95.15% <100.00%> (+<0.01%) ⬆️

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.

Signed-off-by: Manik2708 <[email protected]>
pkg/es/config/esrollovercfg.go Show resolved Hide resolved
pkg/es/config/config.go Outdated Show resolved Hide resolved
@@ -202,6 +202,31 @@ type BearerTokenAuthentication struct {
AllowFromContext bool `mapstructure:"from_context"`
}

type RolloverOptions struct {
// Archive if set to true will handle archive indices also
Archive bool `mapstructure:"archive"`
Copy link
Member

Choose a reason for hiding this comment

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

we're working on removing the explicit knowledge of "archive" from storage implementations. Is this needed? cc @mahadzaryab1

Copy link
Member

Choose a reason for hiding this comment

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

we're very close to cleaning up archive, so I'd like to hold this PR until we merge #6490 and then do archive differently.

pkg/es/config/config.go Show resolved Hide resolved
// Unit is used with lookback to remove indices from read alias e.g, days, weeks, months, years
Unit string `mapstructure:"unit"`
// UnitCount is the count of units for which look-up is performed
UnitCount int `mapstructure:"unit-count"`
Copy link
Member

Choose a reason for hiding this comment

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

  • do we actually support weeks / months / years? Code ptr?
  • can we not simply have this as Duration type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a copy of What used in es-rollover. As the need was not to introduce a major change in rollover but just to include it in binary. So should we change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could raise another PR to see if changing to time.Duration would work

Copy link
Member

Choose a reason for hiding this comment

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

It's ok to have the old command's flags to be a mess, but if we incorporate these into the config which will be used in Jaeger v2 we need to do a clean cut (but backwards compatible).

pkg/es/config/config.go Show resolved Hide resolved
pkg/es/config/config.go Outdated Show resolved Hide resolved
@@ -202,6 +202,31 @@ type BearerTokenAuthentication struct {
AllowFromContext bool `mapstructure:"from_context"`
Copy link
Member

Choose a reason for hiding this comment

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

if you introduce these new types, where are they going to be incorporated into the main Config? We can add them now, I would like to see the full config design.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is going to be encorprated in the config of es.

type Rollover struct {
	// Enabled if set to true will enable the ES Rollover, which will manage the jaeger indices
	// automatically without manually running the cron job
	Enabled bool `mapstructure:"enabled"`
	// Frequency stores the duration after which this job should be performed periodically.
	Frequency time.Duration `mapstructure:"frequency"`
	// LookBackEnabled if set to true will enable the look back process in the rollover job. Look-back process
	// is very similar to Jaeger ES-Cleaner, if cleaning through only ES-Cleaner is required then this
	// can be set to false. See this section of documentation for more context:
	// https://www.jaegertracing.io/docs/2.1/elasticsearch/#index-rollover
	LookBackEnabled bool `mapstructure:"look_back_enabled"`
	// LookBackOptions store the configuration which will be executed if look back is enabled
	LookBackOptions LookBackOptions `mapstructure:"look_back_options"`
	// RollBackConditions stores the conditions on which index writing should be performed
	RollBackOptions RollBackOptions `mapstructure:"roll_back_options"`
	// RolloverOptions store the configuration required for setting up the cron job of rolling over indices
	RolloverOptions RolloverOptions `mapstructure:"rollover_options"`
}


// Config holds configuration for index cleaner binary.
type Config struct {
app.Config
Conditions string
config.RollBackOptions
Copy link
Member

Choose a reason for hiding this comment

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

I am confused by the name "roll back" - what is it we're rolling back? Rollover != rollback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was also confused for the name. I deduced this name from the description of the flag. RolloverConditions would be alright?

Signed-off-by: Manik2708 <[email protected]>
@Manik2708 Manik2708 requested a review from yurishkuro January 9, 2025 20:02
)

type EsRolloverFlagConfig struct {
Prefix string
Copy link
Member

Choose a reason for hiding this comment

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

I am not seeing any usage examples where Prefix is defined to be non-empty. What is it needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is in #6500. The config of es uses a namespace es, so the command needs to be with a prefix.

Prefix string
}

func (e EsRolloverFlagConfig) AddFlagsForRolloverOptions(flags *flag.FlagSet) {
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
func (e EsRolloverFlagConfig) AddFlagsForRolloverOptions(flags *flag.FlagSet) {
func (e EsRolloverFlagConfig) AddFlags(flags *flag.FlagSet) {

flags.Bool(e.Prefix+flagRolloverAdaptiveSampling, defaultAdaptiveSampling, "Enable rollover for adaptive sampling index")
}

func (e EsRolloverFlagConfig) InitRolloverOptionsFromViper(v *viper.Viper) RolloverOptions {
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
func (e EsRolloverFlagConfig) InitRolloverOptionsFromViper(v *viper.Viper) RolloverOptions {
func (e EsRolloverFlagConfig) InitFromViper(v *viper.Viper) RolloverOptions {

return *r
}

func (e EsRolloverFlagConfig) AddFlagsForLookBackOptions(flags *flag.FlagSet) {
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 follow - if these are separate sets of options/flags why do they need to be provided by the same config struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could do in a different struct also but that would be the copy of this same struct. These options/flags doesn't have a prefix but we need to have a prefix when extending the config of es.

// Unit is used with lookback to remove indices from read alias e.g, days, weeks, months, years
Unit string `mapstructure:"unit"`
// UnitCount is the count of units for which look-up is performed
UnitCount int `mapstructure:"unit-count"`
Copy link
Member

Choose a reason for hiding this comment

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

It's ok to have the old command's flags to be a mess, but if we incorporate these into the config which will be used in Jaeger v2 we need to do a clean cut (but backwards compatible).

AdaptiveSampling bool `mapstructure:"include_adaptive_sampling"`
}

// LookBackOptions store the options for a sub-process which is similar to index cleaner of auto rollover of jaeger.
Copy link
Member

Choose a reason for hiding this comment

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

I question why these need to be separate. If I think about the user taking a declarative approach to index rollovers, they would describe the frequency of rotations and how much data to retain, so that the rollover and cleanup are done as a single logical process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of these 3 options will be in same common struct of Rollover. Please see this:

type Rollover struct {
	// Enabled if set to true will enable the ES Rollover, which will manage the jaeger indices
	// automatically without manually running the cron job
	Enabled bool `mapstructure:"enabled"`
	// Frequency stores the duration after which this job should be performed periodically.
	Frequency time.Duration `mapstructure:"frequency"`
	// LookBackEnabled if set to true will enable the look back process in the rollover job. Look-back process
	// is very similar to Jaeger ES-Cleaner, if cleaning through only ES-Cleaner is required then this
	// can be set to false. See this section of documentation for more context:
	// https://www.jaegertracing.io/docs/2.1/elasticsearch/#index-rollover
	LookBackEnabled bool `mapstructure:"look_back_enabled"`
	// LookBackOptions store the configuration which will be executed if look back is enabled
	LookBackOptions LookBackOptions `mapstructure:"look_back_options"`
	// RollBackConditions stores the conditions on which index writing should be performed
	RollBackOptions RollBackOptions `mapstructure:"roll_back_options"`
	// RolloverOptions store the configuration required for setting up the cron job of rolling over indices
	RolloverOptions RolloverOptions `mapstructure:"rollover_options"`
}

I have created different structs because we want to keep the processes of cmd/es-rollover decoupled. Creating a single struct will give options of LookBack to Rollover also.

}

// RollOverConditions store the conditions required for the rollover operation in the auto-rollover cron job of jaeger.
type RollOverConditions struct {
Copy link
Member

Choose a reason for hiding this comment

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

similar to question about LookBackOptions, why is this a separate struct?

// RollOverConditions store the conditions required for the rollover operation in the auto-rollover cron job of jaeger.
type RollOverConditions struct {
// Conditions stores the conditions on which index writing should be performed, for example: "{\"max_age\": \"2d\"}"
Conditions string `mapstructure:"conditions"`
Copy link
Member

Choose a reason for hiding this comment

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

who interprets these conditions? Are they sent to Elasticsearch verbatim? if so let's say so in the comments.

@@ -202,6 +202,31 @@ type BearerTokenAuthentication struct {
AllowFromContext bool `mapstructure:"from_context"`
}

type RolloverOptions struct {
// Archive if set to true will handle archive indices also
Archive bool `mapstructure:"archive"`
Copy link
Member

Choose a reason for hiding this comment

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

we're very close to cleaning up archive, so I'd like to hold this PR until we merge #6490 and then do archive differently.

// Copyright (c) 2025 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package config
Copy link
Member

Choose a reason for hiding this comment

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

The file can be called simply rollover.go - both es and cfg are implied by the package.

@Manik2708 Manik2708 mentioned this pull request Jan 12, 2025
4 tasks
@Manik2708
Copy link
Contributor Author

@yurishkuro As discussed in the comment: #6500 (comment) and also addressing this comment: #6516 (comment) I am thinking of encorporating the config of Rollover and LookBackinto the common config of es-rollover but that will change the command from ./es-rollover lookback --unit=day to ./es-rollover --unit=day lookback. This eventually is not looking good to me, so which approach should we use:

  1. Encorporating the lookback and rollover to common config and removing the structs of LookBack and Rollover.
  2. Keeping these different structs as they are kept in this PR?

@yurishkuro
Copy link
Member

Do you see a strong business reason for rollover and lookback to be separate actions? I.e. why would someone want to rollover the indices but not apply the retention policy by cleaning the old ones? Is it feasible that these actions would run at different intervals?

If it makes sense for them to run separately then it would make sense to have separate configs with separate run-frequency settings.

I am also curious about how these apply per-index. We recently upgraded configuration (only accessible via v2, not supported in v1) where each index can have its own rotation etc. settings.

@Manik2708
Copy link
Contributor Author

Do you see a strong business reason for rollover and lookback to be separate actions? I.e. why would someone want to rollover the indices but not apply the retention policy by cleaning the old ones? Is it feasible that these actions would run at different intervals?

If it makes sense for them to run separately then it would make sense to have separate configs with separate run-frequency settings.

I am also curious about how these apply per-index. We recently upgraded configuration (only accessible via v2, not supported in v1) where each index can have its own rotation etc. settings.

I don't think that seperate rollover frequencies is a good option. We can keep the es-rollover cmd as same, that is leave it on the user when they want to run rollover manually but when integrating with Jaeger binary, I think a common frequency of the cron job as a whole would be more beneficial. I don't see any reason of not running rollover after the init. But as per the blog lookback is an optional step because it is similar to es-index-cleaner so for that we can ask from the user whether to enable look back or not. So if lookback is enabled, periodically this will be the flow: init->rollover->lookback and if it is disabled then init->rollover.

@yurishkuro
Copy link
Member

I am starting to have second thoughts about this whole thing. Both ES and OS already provide automation for index rollover via ILM/ISM. Why do we need to keep maintaining our own custom scripts in the first place?

@Manik2708
Copy link
Contributor Author

I am starting to have second thoughts about this whole thing. Both ES and OS already provide automation for index rollover via ILM/ISM. Why do we need to keep maintaining our own custom scripts in the first place?

Is this what are you saying? https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-index-lifecycle-management.html

@yurishkuro
Copy link
Member

Yes (but for OpenSearch there's ISM, which is similar but not the same).

Since you've been reading about these rollovers, can you propose what might be needed from the Jaeger binary if we only wanted to recommend to users to use ILM/ISM?

@Manik2708
Copy link
Contributor Author

Yes (but for OpenSearch there's ISM, which is similar but not the same).

Since you've been reading about these rollovers, can you propose what might be needed from the Jaeger binary if we only wanted to recommend to users to use ILM/ISM?

Sure, can work on it! Then for now I think I should stop working on this refactoring or using es-rollover in jaeger binary. Let's keep es-rollover as it is and try to use ILM/ISM automatic rollovers in jaeger binary. Am I understanding right?

@yurishkuro
Copy link
Member

Yes, that's correct. Sorry for the churn, it seemed like a good idea originally, but it turned into more longer term maintenance than I feel it's worth. Jaeger project should be focusing on tracing, not on db management, especially when DBs already support automation out of the box.

@Manik2708
Copy link
Contributor Author

@yurishkuro Ok, so closing this PR as these changes doesn't make any sense now. Thanks for giving a direction. Will submit a proposal of enabling the automated rollover using ILM/ISM.

@Manik2708 Manik2708 closed this Jan 13, 2025
@akstron akstron mentioned this pull request Jan 17, 2025
4 tasks
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.

2 participants