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

Feat: Add wait for indices #678

Open
wants to merge 1 commit into
base: rel6
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions monstache.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ type configOptions struct {
ElasticHealth1 int `toml:"elasticsearch-healthcheck-timeout"`
ElasticPKIAuth elasticPKIAuth `toml:"elasticsearch-pki-auth"`
ElasticAPIKey string `toml:"elasticsearch-api-key"`
WaitForIndices stringargs `toml:"wait-for-indices"`
ResumeName string `toml:"resume-name"`
NsRegex string `toml:"namespace-regex"`
NsDropRegex string `toml:"namespace-drop-regex"`
Expand Down Expand Up @@ -1774,6 +1775,7 @@ func (config *configOptions) parseCommandLineFlags() *configOptions {
flag.Var(&config.FileNamespaces, "file-namespace", "A list of file namespaces")
flag.Var(&config.PatchNamespaces, "patch-namespace", "A list of patch namespaces")
flag.Var(&config.Workers, "workers", "A list of worker names")
flag.Var(&config.WaitForIndices, "wait-for-indices", "A list of index names to wait for before starting synchronisation")
flag.BoolVar(&config.EnableHTTPServer, "enable-http-server", false, "True to enable an internal http server")
flag.StringVar(&config.HTTPServerAddr, "http-server-addr", "", "The address the internal http server listens on")
flag.BoolVar(&config.PruneInvalidJSON, "prune-invalid-json", false, "True to omit values which do not serialize to JSON such as +Inf and -Inf and thus cause errors")
Expand Down Expand Up @@ -4361,6 +4363,7 @@ func (ic *indexClient) run() {
ic.startDownload()
ic.startPostProcess()
ic.clusterWait()
ic.waitForIndices()
ic.startListen()
ic.startReadWait()
ic.startExpireCreds()
Expand Down Expand Up @@ -4825,6 +4828,25 @@ func (ic *indexClient) clusterWait() {
}
}

func (ic *indexClient) waitForIndices() {
if len(ic.config.WaitForIndices) > 0 {
for {
exists, err := ic.client.IndexExists(ic.config.WaitForIndices...).Do(context.Background())
if err != nil {
errorLog.Printf("Error waiting for indices %v", ic.config.WaitForIndices)
time.Sleep(5 * time.Second)
continue
}
if !exists {
infoLog.Printf("Waiting for indices %v", ic.config.WaitForIndices)
time.Sleep(5 * time.Second)
continue
}
break
}
}
}

func (ic *indexClient) hasNewEvents() bool {
if ic.lastTs.T > ic.lastTsSaved.T ||
(ic.lastTs.T == ic.lastTsSaved.T && ic.lastTs.I > ic.lastTsSaved.I) {
Expand Down