Skip to content

Commit

Permalink
[8.x](backport #42202) Update elastic-agent-libs to v0.18.0 (#42211)
Browse files Browse the repository at this point in the history
* Update elastic-agent-libs to v0.18.0 (#42202)

Co-authored-by: Julien Lind <julien.lind@elastic.co>
(cherry picked from commit ef29005)

# Conflicts:
#	go.mod
#	go.sum

* Fix backport

---------

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
Co-authored-by: michel-laterman <michel.laterman@elastic.co>
Co-authored-by: Julien Lind <julien.lind@elastic.co>
  • Loading branch information
4 people authored Jan 9, 2025
1 parent 5f67e46 commit c2a6a48
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 52 deletions.
4 changes: 2 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13406,11 +13406,11 @@ SOFTWARE

--------------------------------------------------------------------------------
Dependency : github.com/elastic/elastic-agent-libs
Version: v0.17.5
Version: v0.18.0
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.17.5/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.18.0/LICENSE:

Apache License
Version 2.0, January 2004
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ require (
github.com/elastic/bayeux v1.0.5
github.com/elastic/ebpfevents v0.6.0
github.com/elastic/elastic-agent-autodiscover v0.9.0
github.com/elastic/elastic-agent-libs v0.17.5
github.com/elastic/elastic-agent-libs v0.18.0
github.com/elastic/elastic-agent-system-metrics v0.11.7
github.com/elastic/go-elasticsearch/v8 v8.14.0
github.com/elastic/go-quark v0.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0
github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4=
github.com/elastic/elastic-agent-client/v7 v7.15.0 h1:nDB7v8TBoNuD6IIzC3z7Q0y+7bMgXoT2DsHfolO2CHE=
github.com/elastic/elastic-agent-client/v7 v7.15.0/go.mod h1:6h+f9QdIr3GO2ODC0Y8+aEXRwzbA5W4eV4dd/67z7nI=
github.com/elastic/elastic-agent-libs v0.17.5 h1:oyv5BohMia+49tZnsOmTyRWp5LoZbH8iOmGa7c4TqTs=
github.com/elastic/elastic-agent-libs v0.17.5/go.mod h1:5CR02awPrBr+tfmjBBK+JI+dMmHNQjpVY24J0wjbC7M=
github.com/elastic/elastic-agent-libs v0.18.0 h1:PKG1StgHu2MfOwOryGuAVgNZlZXyvVSDw3SvLUfel+w=
github.com/elastic/elastic-agent-libs v0.18.0/go.mod h1:5CR02awPrBr+tfmjBBK+JI+dMmHNQjpVY24J0wjbC7M=
github.com/elastic/elastic-agent-system-metrics v0.11.7 h1:1xm2okCM0eQZ4jivZgUFSlt6HAn/nPgKB/Fj8eLG6mY=
github.com/elastic/elastic-agent-system-metrics v0.11.7/go.mod h1:nzkrGajQA29YNcfP62gfzhxX9an3/xdQ3RmfQNw9YTI=
github.com/elastic/elastic-transport-go/v8 v8.6.0 h1:Y2S/FBjx1LlCv5m6pWAF2kDJAHoSjSRSJCApolgfthA=
Expand Down
47 changes: 0 additions & 47 deletions libbeat/cmd/instance/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ package instance

import (
"bytes"
"crypto/tls"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/elastic/beats/v7/libbeat/cfgfile"
Expand All @@ -35,7 +33,6 @@ import (
"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/transport/tlscommon"
"github.com/elastic/go-ucfg/yaml"

"github.com/gofrs/uuid/v5"
Expand Down Expand Up @@ -479,50 +476,6 @@ func TestLogSystemInfo(t *testing.T) {
}
}

func TestTLSDefaultVersions(t *testing.T) {
b, err := NewBeat("mockbeat", "testidx", "0.9", false, nil)
require.NoError(t, err)

cfg, err := cfgfile.Load(filepath.Join("testdata", "tls.yml"), nil)
require.NoError(t, err)
err = cfg.Unpack(&b.Config)
require.NoError(t, err)
assert.True(t, b.Config.Output.IsSet())
sslCfg, err := b.Config.Output.Config().Child("ssl", -1)
require.NoError(t, err)
var common tlscommon.Config
err = sslCfg.Unpack(&common)
require.NoError(t, err)
tlsCfg, err := tlscommon.LoadTLSConfig(&common)
require.NoError(t, err)

c := tlsCfg.ToConfig()
assert.Equal(t, uint16(tls.VersionTLS11), c.MinVersion)
assert.Equal(t, uint16(tls.VersionTLS13), c.MaxVersion)
}

func TestTLSVersion10(t *testing.T) {
b, err := NewBeat("mockbeat", "testidx", "0.9", false, nil)
require.NoError(t, err)

cfg, err := cfgfile.Load(filepath.Join("testdata", "tls10.yml"), nil)
require.NoError(t, err)
err = cfg.Unpack(&b.Config)
require.NoError(t, err)
assert.True(t, b.Config.Output.IsSet())
sslCfg, err := b.Config.Output.Config().Child("ssl", -1)
require.NoError(t, err)
var common tlscommon.Config
err = sslCfg.Unpack(&common)
require.NoError(t, err)
tlsCfg, err := tlscommon.LoadTLSConfig(&common)
require.NoError(t, err)

c := tlsCfg.ToConfig()
assert.Equal(t, uint16(tls.VersionTLS10), c.MinVersion)
assert.Equal(t, uint16(tls.VersionTLS10), c.MaxVersion)
}

type mockManager struct {
enabled bool
}
Expand Down
104 changes: 104 additions & 0 deletions libbeat/cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//go:build !integration

package cmd

import (
"crypto/tls"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/cfgfile"
"github.com/elastic/beats/v7/libbeat/cmd/instance"
"github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/transport/tlscommon"
)

type MockBeater struct {
mock.Mock
}

func (m *MockBeater) Run(b *beat.Beat) error {
args := m.Called(b)
return args.Error(0)
}

func (m *MockBeater) Stop() {
m.Called()
}

func genMockCreator(m *MockBeater) beat.Creator {
return func(b *beat.Beat, c *config.C) (beat.Beater, error) {
return m, nil
}
}

func TestGenRootCmdWithSettings_TLSDefaults(t *testing.T) {
mb := &MockBeater{}
settings := instance.Settings{}
_ = GenRootCmdWithSettings(genMockCreator(mb), settings)

t.Run("Test defaults", func(t *testing.T) {
b, err := instance.NewBeat("mockbeat", "testidx", "0.9", false, nil)
require.NoError(t, err)
cfg, err := cfgfile.Load(filepath.Join("instance", "testdata", "tls.yml"), nil)
require.NoError(t, err)
err = cfg.Unpack(&b.Config)
require.NoError(t, err)
assert.True(t, b.Config.Output.IsSet())
sslCfg, err := b.Config.Output.Config().Child("ssl", -1)
require.NoError(t, err)
var common tlscommon.Config
err = sslCfg.Unpack(&common)
require.NoError(t, err)
tlsCfg, err := tlscommon.LoadTLSConfig(&common)
require.NoError(t, err)

c := tlsCfg.ToConfig()
assert.Equal(t, uint16(tls.VersionTLS11), c.MinVersion)
assert.Equal(t, uint16(tls.VersionTLS13), c.MaxVersion)
})

t.Run("Set min TLSv1.0", func(t *testing.T) {
b, err := instance.NewBeat("mockbeat", "testidx", "0.9", false, nil)
require.NoError(t, err)

cfg, err := cfgfile.Load(filepath.Join("instance", "testdata", "tls10.yml"), nil)
require.NoError(t, err)
err = cfg.Unpack(&b.Config)
require.NoError(t, err)
assert.True(t, b.Config.Output.IsSet())
sslCfg, err := b.Config.Output.Config().Child("ssl", -1)
require.NoError(t, err)
var common tlscommon.Config
err = sslCfg.Unpack(&common)
require.NoError(t, err)
tlsCfg, err := tlscommon.LoadTLSConfig(&common)
require.NoError(t, err)

c := tlsCfg.ToConfig()
assert.Equal(t, uint16(tls.VersionTLS10), c.MinVersion)
assert.Equal(t, uint16(tls.VersionTLS10), c.MaxVersion)
})
}

0 comments on commit c2a6a48

Please sign in to comment.