Skip to content

Commit 44b055a

Browse files
authored
Improve error messaging if no Kibana endpoint is configured. (#1114)
Fixes two issues that lead to confusing errors being shown: - The `agent_policy` resource did not throw an error if getting the stack version fails - When getting the stack version fails, it only returned the http connection error, not actually stating what it was trying to do. In combination this will now lead to an error like ``` Error: failed to get version from Kibana API. Please ensure a working 'kibana' endpoint is configured. Error: Get "http://localhost:5601/api/status": dial tcp [::1]:5601: connect: connection refused ``
1 parent bf9ad55 commit 44b055a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

internal/clients/api_client.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,14 @@ func (a *ApiClient) ServerVersion(ctx context.Context) (*version.Version, diag.D
363363
func (a *ApiClient) versionFromKibana() (*version.Version, diag.Diagnostics) {
364364
kibClient, err := a.GetKibanaClient()
365365
if err != nil {
366-
return nil, diag.FromErr(err)
366+
return nil, diag.Errorf("failed to get version from Kibana API: %s, "+
367+
"please ensure a working 'kibana' endpoint is configured", err.Error())
367368
}
368369

369370
status, err := kibClient.KibanaStatus.Get()
370371
if err != nil {
371-
return nil, diag.FromErr(err)
372+
return nil, diag.Errorf("failed to get version from Kibana API: %s, "+
373+
"Please ensure a working 'kibana' endpoint is configured", err.Error())
372374
}
373375

374376
vMap, ok := status["version"].(map[string]interface{})

internal/fleet/agent_policy/update.go

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func (r *agentPolicyResource) Update(ctx context.Context, req resource.UpdateReq
2424

2525
sVersion, e := r.client.ServerVersion(ctx)
2626
if e != nil {
27+
for _, a := range e {
28+
resp.Diagnostics.AddError(a.Summary, a.Detail)
29+
}
2730
return
2831
}
2932

0 commit comments

Comments
 (0)