mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-30 14:56:19 +00:00
## 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. --- > [!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]() for commit b37864809ac95a427e74b2a424852992aac2442b. This will update automatically on new commits. Configure [here]().</sup>
63 lines
2.5 KiB
Go
63 lines
2.5 KiB
Go
//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination client_mock.go
|
|
|
|
package client
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/olivere/elastic/v7"
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
)
|
|
|
|
const (
|
|
versionTypeExternal = "external"
|
|
minimumCloseIdleConnectionsInterval = 15 * time.Second
|
|
)
|
|
|
|
type (
|
|
// Client is a wrapper around Elasticsearch client library.
|
|
Client interface {
|
|
Get(ctx context.Context, index string, docID string) (*elastic.GetResult, error)
|
|
Search(ctx context.Context, p *SearchParameters) (*elastic.SearchResult, error)
|
|
Count(ctx context.Context, index string, query elastic.Query) (int64, error)
|
|
CountGroupBy(ctx context.Context, index string, query elastic.Query, aggName string, agg elastic.Aggregation) (*elastic.SearchResult, error)
|
|
RunBulkProcessor(ctx context.Context, p *BulkProcessorParameters) (BulkProcessor, error)
|
|
|
|
// TODO (alex): move this to some admin client (and join with IntegrationTestsClient)
|
|
PutMapping(ctx context.Context, index string, mapping map[string]enumspb.IndexedValueType) (bool, error)
|
|
WaitForYellowStatus(ctx context.Context, index string) (string, error)
|
|
GetMapping(ctx context.Context, index string) (map[string]string, error)
|
|
IndexExists(ctx context.Context, indexName string) (bool, error)
|
|
CreateIndex(ctx context.Context, index string, body map[string]any) (bool, error)
|
|
DeleteIndex(ctx context.Context, indexName string) (bool, error)
|
|
CatIndices(ctx context.Context, target string) (elastic.CatIndicesResponse, error)
|
|
}
|
|
|
|
CLIClient interface {
|
|
Client
|
|
Delete(ctx context.Context, indexName string, docID string, version int64) error
|
|
IndexPutTemplate(ctx context.Context, templateName string, bodyString string) (bool, error)
|
|
IndexPutMapping(ctx context.Context, indexName string, bodyString string) (bool, error)
|
|
ClusterPutSettings(ctx context.Context, bodyString string) (bool, error)
|
|
Ping(ctx context.Context) error
|
|
}
|
|
|
|
IntegrationTestsClient interface {
|
|
Client
|
|
IndexPutTemplate(ctx context.Context, templateName string, bodyString string) (bool, error)
|
|
IndexPutSettings(ctx context.Context, indexName string, bodyString string) (bool, error)
|
|
IndexGetSettings(ctx context.Context, indexName string) (map[string]*elastic.IndicesGetSettingsResponse, error)
|
|
Ping(ctx context.Context) error
|
|
}
|
|
|
|
// SearchParameters holds all required and optional parameters for executing a search.
|
|
SearchParameters struct {
|
|
Index string
|
|
Query elastic.Query
|
|
PageSize int
|
|
Sorter []elastic.Sorter
|
|
SearchAfter []interface{}
|
|
}
|
|
)
|