-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: Remove the need for external tools for managing ElasticSearch #6291
base: main
Are you sure you want to change the base?
Changes from all commits
2199d38
e2e5859
02e2826
aeac08a
fa71243
d14a1d6
00dc807
6a4a0d2
51ab560
e40a5f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,23 @@ const ( | |
IndexPrefixSeparator = "-" | ||
) | ||
|
||
// IndexCleaner struct for configuring index cleaning | ||
type IndexCleaner struct { | ||
// Enabled specifies whether the index cleaner functionality is enabled. | ||
// when set to true, the index cleaner will periodically run based on the specified frequency. | ||
Enabled bool `mapstructure:"enabled"` | ||
// Frequency defines the interval at which the index cleaner runs. | ||
Frequency time.Duration `mapstructure:"frequency" validate:"gt=0"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add comment describing the arg |
||
} | ||
|
||
// Rollover struct for configuring roll over | ||
type Rollover struct { | ||
// Enabled specifies whether the rollover functionality is enabled. | ||
Enabled bool `mapstructure:"enabled"` | ||
// Frequency specifies the interval at which the rollover process runs. | ||
Frequency time.Duration `mapstructure:"frequency" validate:"gt=0"` | ||
} | ||
|
||
// IndexOptions describes the index format and rollover frequency | ||
type IndexOptions struct { | ||
// Priority contains the priority of index template (ESv8 only). | ||
|
@@ -136,6 +153,12 @@ type Configuration struct { | |
Tags TagsAsFields `mapstructure:"tags_as_fields"` | ||
// Enabled, if set to true, enables the namespace for storage pointed to by this configuration. | ||
Enabled bool `mapstructure:"-"` | ||
|
||
// ---- ES-specific config ---- | ||
// IndexCleaner holds the configuration for the Elasticsearch index Cleaner. | ||
IndexCleaner IndexCleaner `mapstructure:"index_cleaner"` | ||
// Rollover holds the configuration for the Elasticsearh roll over. | ||
Rollover Rollover `mapstructure:"rollover"` | ||
} | ||
|
||
// TagsAsFields holds configuration for tag schema. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package es | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewEsMappingsCommand defines the new CLI command to run esmapping-generator | ||
func NewEsMappingsCommand() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "es-mappings", | ||
Short: "Print Elasticsearch index mappings to stdout", | ||
Run: func(_ *cobra.Command, _ []string) { | ||
if _, err := os.Stat("./cmd/esmapping-generator"); os.IsNotExist(err) { | ||
log.Fatalf("esmapping-generator not found: %v", err) | ||
} | ||
|
||
// Run the esmapping-generator command | ||
execCmd := exec.Command("go", "run", "./cmd/esmapping-generator") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you imagine this working in production if someone runs Jaeger as a container image? Where would they get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you guide me here little There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you guide me here little There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. first, I suggest you focus on one tool at a time, start with the cleaner only. The logic of the cleaner is already implemented in Go, we can call it directly as a library from the ES implementation. You can reuse all the sub-commands defined in cmd/es-cleaner, but you may have to move them out of main() into a reusable package (that would be a standalone refactoring and should be its own PR). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one more thing - I think the easiest too to start with is es-mapping, because it's purely an on-demand command run with no need to set up periodic jobs. I was wrong in the comment above - I don't think sub-commands will be needed once the cleaner/rollover are integrated into the main binary, because the only reason those sub-commands exist today is to allow the script to be run as externally managed cron job, so it needs to do different things. But if it's run as internal periodic job, it's one combined functionality. |
||
output, err := execCmd.CombinedOutput() | ||
if err != nil { | ||
log.Printf("Error executing esmapping-generator: %v\nOutput: %s", err, output) | ||
return | ||
} | ||
fmt.Println("esmapping-generator executed successfully") | ||
fmt.Printf("%s\n", output) | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package es | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"log" | ||
"os/exec" | ||
"time" | ||
|
||
"github.com/jaegertracing/jaeger/pkg/es/config" | ||
) | ||
|
||
type CleanerConfigWrapper struct { | ||
*config.Configuration | ||
} | ||
|
||
func (cfg *CleanerConfigWrapper) RunCleaner() { | ||
if !cfg.IndexCleaner.Enabled { | ||
log.Println("Cleaner is disabled, skipping...") | ||
return | ||
} | ||
|
||
ticker := time.NewTicker(cfg.IndexCleaner.Frequency) | ||
defer ticker.Stop() | ||
|
||
for range ticker.C { | ||
log.Println("Running index cleaner...") | ||
|
||
// Call for existing cmd/es-index-cleaner logic here | ||
err := cfg.runESIndexCleaner() | ||
if err != nil { | ||
log.Printf("Error running es-index-cleaner: %v", err) | ||
} | ||
} | ||
} | ||
|
||
// runESIndexCleaner runs the cmd/es-index-cleaner command. | ||
func (cfg *CleanerConfigWrapper) runESIndexCleaner() error { | ||
if len(cfg.Servers) == 0 { | ||
return errors.New("elasticsearch server URL is missing in configuration") | ||
} | ||
|
||
cmd := exec.Command("./cmd/es-index-cleaner") | ||
|
||
err := cmd.Run() | ||
if err != nil { | ||
return fmt.Errorf("failed to run es-index-cleaner: %w", err) | ||
} | ||
|
||
log.Println("Index cleaner executed successfully.") | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package es | ||
|
||
import ( | ||
"log" | ||
"os/exec" | ||
"time" | ||
|
||
"github.com/jaegertracing/jaeger/pkg/es/config" | ||
) | ||
|
||
type RolloverConfigWrapper struct { | ||
*config.Configuration | ||
} | ||
|
||
// RunRollover schedules and runs the rollover process based on the configured frequency. | ||
func (cfg *RolloverConfigWrapper) RunRollover() { | ||
if !cfg.Rollover.Enabled { | ||
log.Println("Rollover is disabled, skipping...") | ||
return | ||
} | ||
|
||
ticker := time.NewTicker(cfg.Rollover.Frequency) | ||
defer ticker.Stop() | ||
|
||
for range ticker.C { | ||
log.Println("Running index rollover...") | ||
|
||
cmd := exec.Command("./cmd/es-rollover") | ||
err := cmd.Run() | ||
|
||
if err != nil { | ||
log.Printf("Error running es-rollover: %v", err) | ||
} else { | ||
log.Println("Index rollover executed successfully.") | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you create another PR (to merge before this one) that changes the
RolloverFrequency
field type totime.Duration
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay!