-
Notifications
You must be signed in to change notification settings - Fork 624
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
[proposal] Remove interfaces and functions from go-elasticsearch.Config #713
Comments
How about: Introduce a new type StaticConfig struct {
Addresses []string `json:"addresses"`
}
myConfig := StaticConfig{}
client := elasticsearch.New(
WithStaticConfig(myConfig),
) With this, the user sets static config from the specified format. If they want to specify function configs, which can't be specified from anything static, they can use other functional options: client := elasticsearch.New(
WithRetryOnError(func(*http.Request, error) bool {
return false
}),
) Within the |
What I'm missing from the suggested |
With Go 1.23 a new The biggest critic and request for change with this issue is the removal of functions and interfaces from go-elasticsearch.Config. These functions and interfaces are the reason various implementations use very different ways to achieve the same - some kind of backoff algorithm. The newly added |
Status Quo
go-elasticsearch.Config defines how one can interact with Elasticsearch. At the moment this struct holds a mix of types, functions and interfaces.
Functions:
go-elasticsearch/elasticsearch.go
Line 89 in 624594e
go-elasticsearch/elasticsearch.go
Line 103 in 624594e
go-elasticsearch/elasticsearch.go
Line 110 in 624594e
Interfaces:
go-elasticsearch/elasticsearch.go
Lines 106 to 107 in 624594e
Problem
The functions and interfaces in go-elasticsearch.Config prevent users of elastic/go-elasticsearch to directly use go-elasticsearch.Config. The direct reuse of go-elasticsearch.Config is prevented, because it can not be configured, usually via
YAML
, and services are required to allow users to configure the connection to Elasticsearch. Common dependencies to handle configuration within the Elastic ecosystem are elastic/go-ucfg and elastic/elastic-agent-libs/config. As it is not possible to configure interfaces and/or functions withYAML
, services that have to use go-elasticsearch.Config come up with their reimplemenation of go-elasticsearch.Config:None of these reimplementations of go-elasticsearch.Config fully cover all parts of go-elasticsearch.Config , lead to duplicate code and might introduce subtile bugs. In addition, configuring the retry functionality is different from service to service and prevents the reuse of configurations.
Proposal
Remove interfaces and functions from go-elasticsearch.Config. One option to keep functionality is, is to introduce Getter/Setter.
The suggested proposal is a breaking change and not backwards compatible.
The text was updated successfully, but these errors were encountered: