Skip to content

Commit

Permalink
Remove the hard version between Fleet and the Elastic Agent.
Browse files Browse the repository at this point in the history
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: elastic#17761
  • Loading branch information
ph committed Apr 16, 2020
1 parent 65fafea commit ae31393
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 33 deletions.
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 ae31393

Please sign in to comment.