Files
temporal/schema/embed.go
Rob Holland 1dc6264f4f Add Elasticsearch CLI tool (#8296)
## What changed?

- Revive and update original PR #2977 for Elasticsearch CLI tool

Replaces manual curl invocations with a proper CLI tool that leverages
Temporal's built-in Elasticsearch auth providers and provides better
error handling and logging.

## How did you test it?
- [x] built
- [x] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks

None, net new.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Introduces `temporal-elasticsearch-tool` for ES schema/index
management and ping, extends ES client APIs, embeds ES schema, and
updates Makefile to use the tool.
> 
> - **Tools**:
> - New `temporal-elasticsearch-tool` CLI with commands: `setup-schema`,
`update-schema`, `create-index`, `drop-index`, `ping`; supports AWS auth
and uses embedded schema files.
> - Adds entrypoint `cmd/tools/elasticsearch`, README, and basic tests.
> - **Elasticsearch Client**:
> - Extends `CLIClient` with `ClusterPutSettings`, `IndexPutTemplate`,
`IndexPutMapping`, `Ping` and implements them (v7) using raw requests
where needed; allows custom HTTP client from config (e.g., AWS-signed).
> - **Schema**:
> - Embeds ES v7 cluster settings and index template
(`schema.Embedded...` accessors).
> - **Build/Makefile**:
> - Adds build target and binary cleanup for
`temporal-elasticsearch-tool`; updates `install-schema-es` and
`install-schema-xdc` to use the CLI instead of curl.
> - Includes binary in `.goreleaser.yml`; excludes it in
`.dockerignore`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
b37864809a. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-02 10:52:21 +01:00

67 lines
1.7 KiB
Go

package schema
import (
"embed"
"io/fs"
"path/filepath"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/log/tag"
)
//go:embed *
var assets embed.FS
// Assets returns a file system with the contents of the schema directory
func Assets() fs.FS {
return assets
}
// PathsByDir returns a list of paths to directories within the schema subdirectory that have versioned schemas in them
func PathsByDir(dbSubDir string) []string {
logger := log.NewCLILogger()
efs := Assets()
dirs := make([]string, 0)
err := fs.WalkDir(efs, dbSubDir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
if d.Name() == "versioned" {
dirs = append(dirs, filepath.ToSlash(filepath.Dir(path)))
return fs.SkipDir
}
}
return nil
})
if err != nil {
logger.Error("error walking embedded schema file system tree, could not generate valid paths", tag.Error(err))
}
return dirs
}
func PathsByDB(dbName string) []string {
if dbName == "sql" {
return append(PathsByDir("mysql"), PathsByDir("postgresql")...)
}
return PathsByDir(dbName)
}
// ElasticsearchClusterSettings returns the embedded cluster settings for Elasticsearch v7
func ElasticsearchClusterSettings() (string, error) {
data, err := assets.ReadFile("elasticsearch/visibility/cluster_settings_v7.json")
if err != nil {
return "", err
}
return string(data), nil
}
// ElasticsearchIndexTemplate returns the embedded index template for Elasticsearch v7 (latest version)
func ElasticsearchIndexTemplate() (string, error) {
data, err := assets.ReadFile("elasticsearch/visibility/index_template_v7.json")
if err != nil {
return "", err
}
return string(data), nil
}