Skip to content

Commit cd726d3

Browse files
[8.18](backport #45747) Does not emit warning log if V2 config do not have an ID (#45877)
Inputs V2 CheckConfig was emitting warning logs for every input without an ID. This commit fixes it by not requiring an ID to exist when calling CheckConfig. (cherry picked from commit 240c010) * Fix merge conflicts --------- Co-authored-by: Tiago Queiroz <[email protected]>
1 parent d1ae291 commit cd726d3

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
122122
- Journald input now works on Docker containers (except Wolfi) {issue}41278[41278] {issue}44040[44040] {pull}44056[44056]
123123
- Fix endpoint path typo in Okta entity analytics provider. {pull}44147[44147]
124124
- Fixed a websocket panic scenario which would occur after exhausting max retries. {pull}44342[44342]
125+
- Fix wrongly emitted missing input ID warning {issue}42969[42969] {pull}45747[45747]
125126
- Fix handling of unnecessary BOM in UTF-8 text received by o365audit input. {issue}44327[44327] {pull}45739[45739]
126127
- Fix reading journald messages with more than 4kb. {issue}45511[45511] {pull}46017[46017]
127128
- Restore the Streaming input on Windows. {pull}46031[46031]

filebeat/input/v2/compat/compat.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,23 @@ func (f *factory) generateCheckConfig(config *conf.C) (*conf.C, error) {
192192
return nil, fmt.Errorf("failed to create new config: %w", err)
193193
}
194194

195-
// let's try to override the `id` field, if it fails, give up
196-
inputID, err := testCfg.String("id", -1)
195+
uid, err := uuid.NewV4()
197196
if err != nil {
198-
return nil, fmt.Errorf("failed to get 'id': %w", err)
197+
return nil, fmt.Errorf("failed to generate check config id: %w", err)
199198
}
200199

201-
id, err := uuid.NewV4()
202-
if err != nil {
203-
return nil, fmt.Errorf("failed to generate check congig id: %w", err)
200+
finalID := uid.String()
201+
// if 'id' is present, use it as a prefix
202+
if testCfg.HasField("id") {
203+
inputID, err := testCfg.String("id", -1)
204+
if err != nil {
205+
return nil, fmt.Errorf("failed to get 'id': %w", err)
206+
}
207+
208+
finalID = inputID + "-" + finalID
204209
}
205-
err = testCfg.SetString("id", -1, inputID+"-"+id.String())
206-
if err != nil {
210+
211+
if err := testCfg.SetString("id", -1, finalID); err != nil {
207212
return nil, fmt.Errorf("failed to set 'id': %w", err)
208213
}
209214

filebeat/input/v2/compat/compat_test.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package compat
2020
import (
2121
"errors"
2222
"fmt"
23+
"strings"
2324
"sync"
2425
"testing"
2526

@@ -193,27 +194,36 @@ func TestGenerateCheckConfig(t *testing.T) {
193194
cfg *conf.C
194195
want *conf.C
195196
wantErr error
196-
assertCfg func(t assert.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool
197+
assertCfg func(t assert.TestingT, expected any, actual *conf.C, msgAndArgs ...any)
197198
}{
198199
{
199-
name: "id is present",
200-
cfg: conf.MustNewConfigFrom("id: some-id"),
201-
assertCfg: assert.NotEqual,
200+
name: "id is present",
201+
cfg: conf.MustNewConfigFrom("id: some-id"),
202+
assertCfg: func(t assert.TestingT, expect any, got *conf.C, msgAndArgs ...any) {
203+
id, _ := got.String("id", -1)
204+
if !strings.HasPrefix(id, "some-id") {
205+
t.Errorf("'id' field must start with the original id, got %q", id)
206+
}
207+
assert.NotEqual(t, expect, got, msgAndArgs)
208+
},
202209
},
203210
{
204-
name: "absent id",
205-
cfg: conf.MustNewConfigFrom(""),
206-
wantErr: errors.New("failed to get 'id'"),
207-
assertCfg: func(t assert.TestingT, _ interface{}, got interface{}, msgAndArgs ...interface{}) bool {
208-
return assert.Nil(t, got, msgAndArgs...)
211+
name: "absent id",
212+
cfg: conf.MustNewConfigFrom(""),
213+
assertCfg: func(t assert.TestingT, expect any, got *conf.C, msgAndArgs ...any) {
214+
if !got.HasField("id") {
215+
t.Errorf("expecting 'id' to be present in %s", conf.DebugString(got, true))
216+
}
217+
assert.NotNil(t, got, msgAndArgs...)
218+
assert.NotEqual(t, expect, got, msgAndArgs)
209219
},
210220
},
211221
{
212222
name: "invalid config",
213223
cfg: nil,
214224
wantErr: errors.New("failed to create new config"),
215-
assertCfg: func(t assert.TestingT, _ interface{}, got interface{}, msgAndArgs ...interface{}) bool {
216-
return assert.Nil(t, got, msgAndArgs...)
225+
assertCfg: func(t assert.TestingT, _ any, got *conf.C, msgAndArgs ...any) {
226+
assert.Nil(t, got, msgAndArgs...)
217227
},
218228
},
219229
}

0 commit comments

Comments
 (0)