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

Check missing server URL in ES OTEL client #2411

Merged
merged 2 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions cmd/opentelemetry/app/internal/esclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/jaegertracing/jaeger/pkg/es/config"
)

var errMissingURL = fmt.Errorf("missing Elasticsearch URL")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: errors.New() is a more idiomatic approach for completely static error messages


// ElasticsearchClient exposes Elasticsearch API used by Jaeger.
// This is not a general purpose ES client implementation.
// The exposed APIs are the bare minimum that is used by Jaeger project to store and query data.
Expand Down Expand Up @@ -171,6 +173,10 @@ type AggregationResponse struct {

// NewElasticsearchClient returns an instance of Elasticsearch client
func NewElasticsearchClient(params config.Configuration, logger *zap.Logger) (ElasticsearchClient, error) {
if len(params.Servers) == 0 {
return nil, errMissingURL
}

roundTripper, err := config.GetHTTPRoundTripper(&params, logger)
if err != nil {
return nil, err
Expand Down
7 changes: 7 additions & 0 deletions cmd/opentelemetry/app/internal/esclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,10 @@ func testMultiSearch(t *testing.T, clientFactory func(tripper http.RoundTripper)
})
}
}

func TestGetClient_err_missingURL(t *testing.T) {
client, err := NewElasticsearchClient(config.Configuration{}, zap.NewNop())
require.Error(t, err)
assert.EqualError(t, err, errMissingURL.Error())
assert.Nil(t, client)
}