Skip to content

Commit

Permalink
[Agent] Remove the hard version between Fleet and the Elastic Agent. (#…
Browse files Browse the repository at this point in the history
…17764)

* Remove the hard version between Fleet and the Elastic Agent.

This remove the check that Kibana was doing to enforce that the remove
version match the current version of Kibana. Instead the Fleet API
should take the agent header version and ensure we can support it.

This allow the Kibana side to control the communication and the upgrade
more gracefully.

Fixes: #17761
  • Loading branch information
ph authored Apr 17, 2020
1 parent b3576ca commit c40a841
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 33 deletions.
2 changes: 2 additions & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
- Fixed merge of config {pull}17399[17399]
- Handle abs paths on windows correctly {pull}17461[17461]
- Improved cancellation of agent {pull}17318[17318]
- Remove the kbn-version on each request to the Kibana API. {pull}17764[17764]
- Fixed process spawning on Windows {pull}17751[17751]


==== New features

- Generate index name in a format type-dataset-namespace {pull}16903[16903]
Expand Down
1 change: 0 additions & 1 deletion x-pack/elastic-agent/pkg/fleetapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type clienter interface {

var baseRoundTrippers = func(rt http.RoundTripper) (http.RoundTripper, error) {
rt = NewFleetUserAgentRoundTripper(rt, release.Version())
rt = kibana.NewEnforceKibanaVersionRoundTripper(rt, release.Version())
return rt, nil
}

Expand Down
31 changes: 0 additions & 31 deletions x-pack/elastic-agent/pkg/fleetapi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,12 @@ import (
"github.com/stretchr/testify/require"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/kibana"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release"
)

func TestHTTPClient(t *testing.T) {
ctx := context.Background()

t.Run("Ensure we validate the remote Kibana version is higher or equal", withServer(
func(t *testing.T) *http.ServeMux {
msg := `{ message: "hello" }`
mux := http.NewServeMux()
mux.HandleFunc("/echo-hello", authHandler(func(w http.ResponseWriter, r *http.Request) {
v := r.Header.Get("kbn-version")
assert.Equal(t, release.Version(), v)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, msg)
}, "abc123"))
return mux
}, func(t *testing.T, host string) {
cfg := &kibana.Config{
Host: host,
}

l, err := logger.New()
client, err := NewAuthWithConfig(l, "abc123", cfg)
require.NoError(t, err)
resp, err := client.Send(ctx, "GET", "/echo-hello", nil, nil, nil)
require.NoError(t, err)

body, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, `{ message: "hello" }`, string(body))
},
))

t.Run("API Key is valid", withServer(
func(t *testing.T) *http.ServeMux {
msg := `{ message: "hello" }`
Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/kibana/round_trippers.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (r *EnforceKibanaVersionRoundTripper) RoundTrip(req *http.Request) (*http.R
}

// NewEnforceKibanaVersionRoundTripper enforce the remove endpoint to be a a certain version, if the
// remove kibana is not equal or superior on the requested version the call will fail.
// remote kibana is not equal the call will fail.
func NewEnforceKibanaVersionRoundTripper(wrapped http.RoundTripper, version string) http.RoundTripper {
return &EnforceKibanaVersionRoundTripper{rt: wrapped, version: version}
}
Expand Down

0 comments on commit c40a841

Please sign in to comment.