Skip to content

Commit

Permalink
[Elastic Agent] Update log message to contain fleet-server instead of…
Browse files Browse the repository at this point in the history
… Kibana (elastic#25365)

Quite a few log and error messages contained Kibana but instead it was referring to fleet-server now. This PR updates these log messages and modifies parts of the code to also refer to fleet-server. This should improve the user experience and reduce confusion when looking at logs.
  • Loading branch information
ruflin authored Apr 28, 2021
1 parent 87a8c85 commit 1d998f4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (h *PolicyChange) Handle(ctx context.Context, a fleetapi.Action, acker stor
}

h.log.Debugf("handlerPolicyChange: emit configuration for action %+v", a)
err = h.handleKibanaHosts(ctx, c)
err = h.handleFleetServerHosts(ctx, c)
if err != nil {
return err
}
Expand All @@ -95,8 +95,8 @@ func (h *PolicyChange) Handle(ctx context.Context, a fleetapi.Action, acker stor
return acker.Ack(ctx, action)
}

func (h *PolicyChange) handleKibanaHosts(ctx context.Context, c *config.Config) (err error) {
// do not update kibana host from policy; no setters provided with local Fleet Server
func (h *PolicyChange) handleFleetServerHosts(ctx context.Context, c *config.Config) (err error) {
// do not update fleet-server host from policy; no setters provided with local Fleet Server
if len(h.setters) == 0 {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/agent/cmd/enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func addEnrollFlags(cmd *cobra.Command) {
cmd.Flags().BoolP("fleet-server-insecure-http", "", false, "Expose Fleet Server over HTTP (not recommended; insecure)")
cmd.Flags().StringP("certificate-authorities", "a", "", "Comma separated list of root certificate for server verifications")
cmd.Flags().StringP("ca-sha256", "p", "", "Comma separated list of certificate authorities hash pins used for certificate verifications")
cmd.Flags().BoolP("insecure", "i", false, "Allow insecure connection to Kibana")
cmd.Flags().BoolP("insecure", "i", false, "Allow insecure connection to fleet-server")
cmd.Flags().StringP("staging", "", "", "Configures agent to download artifacts from a staging build")
}

Expand Down
4 changes: 2 additions & 2 deletions x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (e *enrollCmdOption) remoteConfig() (remote.Config, error) {
return remote.Config{}, err
}
if cfg.Protocol == remote.ProtocolHTTP && !e.Insecure {
return remote.Config{}, fmt.Errorf("connection to Kibana is insecure, strongly recommended to use a secure connection (override with --insecure)")
return remote.Config{}, fmt.Errorf("connection to fleet-server is insecure, strongly recommended to use a secure connection (override with --insecure)")
}

// Add any SSL options from the CLI.
Expand Down Expand Up @@ -382,7 +382,7 @@ func (c *enrollCmd) enroll(ctx context.Context, persistentConfig map[string]inte
resp, err := cmd.Execute(ctx, r)
if err != nil {
return errors.New(err,
"fail to execute request to Kibana",
"fail to execute request to fleet-server",
errors.TypeNetwork)
}

Expand Down
14 changes: 7 additions & 7 deletions x-pack/elastic-agent/pkg/fleetapi/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func init() {
}
}

// NewAuthWithConfig returns a Kibana client that will:
// NewAuthWithConfig returns a fleet-server client that will:
//
// - Send the API Key on every HTTP request.
// - Ensure a minimun version of Kibana is required.
// - Ensure a minimun version of fleet-server is required.
// - Send the Fleet User Agent on every HTTP request.
func NewAuthWithConfig(log *logger.Logger, apiKey string, cfg remote.Config) (*remote.Client, error) {
return remote.NewWithConfig(log, cfg, func(rt http.RoundTripper) (http.RoundTripper, error) {
Expand All @@ -80,14 +80,14 @@ func NewAuthWithConfig(log *logger.Logger, apiKey string, cfg remote.Config) (*r
})
}

// NewWithConfig takes a Kibana configuration and create a kibana.client with the appropriate tripper.
// NewWithConfig takes a fleet-server configuration and create a remote.client with the appropriate tripper.
func NewWithConfig(log *logger.Logger, cfg remote.Config) (*remote.Client, error) {
return remote.NewWithConfig(log, cfg, baseRoundTrippers)
}

// ExtractError extracts error from a fleet response
// ExtractError extracts error from a fleet-server response
func ExtractError(resp io.Reader) error {
// Lets try to extract a high level Kibana error.
// Lets try to extract a high level fleet-server error.
e := &struct {
StatusCode int `json:"statusCode"`
Error string `json:"error"`
Expand All @@ -104,10 +104,10 @@ func ExtractError(resp io.Reader) error {
// System errors doesn't return a message, fleet code can return a Message key which has more
// information.
if len(e.Message) == 0 {
return fmt.Errorf("status code: %d, Kibana returned an error: %s", e.StatusCode, e.Error)
return fmt.Errorf("status code: %d, fleet-server returned an error: %s", e.StatusCode, e.Error)
}
return fmt.Errorf(
"status code: %d, Kibana returned an error: %s, message: %s",
"status code: %d, fleet-server returned an error: %s, message: %s",
e.StatusCode,
e.Error,
e.Message,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/elastic-agent/pkg/fleetapi/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func TestHTTPClient(t *testing.T) {
// case since we might deal with different format or error I make sense to test this method in
// isolation.
func TestExtract(t *testing.T) {
// The error before is returned when an exception or an internal occur in Kibana, they
// The error before is returned when an exception or an internal occur in fleet-server, they
// are not only generated by the Fleet app.
t.Run("standard high level kibana errors", func(t *testing.T) {
t.Run("standard high level fleet-server errors", func(t *testing.T) {
err := ExtractError(strings.NewReader(`{ "statusCode": 500, "Internal Server Error"}`))
assert.True(t, strings.Index(err.Error(), "500") > 0)
assert.True(t, strings.Index(err.Error(), "Internal Server Error") > 0)
Expand Down
3 changes: 2 additions & 1 deletion x-pack/elastic-agent/pkg/remote/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func NewWithConfig(log *logger.Logger, cfg Config, wrapper wrapperFunc) (*Client

url, err := common.MakeURL(string(cfg.Protocol), p, host, usedDefaultPort)
if err != nil {
return nil, errors.Wrap(err, "invalid Kibana endpoint")
return nil, errors.Wrap(err, "invalid fleet-server endpoint")
}
clients[i] = &requestClient{
request: prefixRequestFactory(url),
Expand Down Expand Up @@ -177,6 +177,7 @@ func (c *Client) Send(
// Content-Type / Accepted type can be override from the called.
req.Header.Set("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
// TODO: Make this header specific to fleet-server or remove it
req.Header.Set("kbn-xsrf", "1") // Without this Kibana will refuse to answer the request.

// copy headers.
Expand Down

0 comments on commit 1d998f4

Please sign in to comment.