Skip to content

Commit

Permalink
respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
leehinman committed Oct 13, 2023
1 parent 70dfb96 commit 505fa7c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
66 changes: 40 additions & 26 deletions libbeat/cmd/instance/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,25 @@ func (r *outputReloaderMock) Reload(

func TestPromoteOutputQueueSettings(t *testing.T) {
tests := map[string]struct {
input []byte
memEvents int
expectValidationError bool
input []byte
memEvents int
}{
"blank": {input: []byte(""),
memEvents: 4096},
"defaults": {input: []byte(`
"blank": {
input: []byte(""),
memEvents: 4096,
},
"defaults": {
input: []byte(`
name: mockbeat
output:
elasticsearch:
hosts:
- "localhost:9200"
`),
memEvents: 4096},
"topLevelQueue": {input: []byte(`
memEvents: 4096,
},
"topLevelQueue": {
input: []byte(`
name: mockbeat
queue:
mem:
Expand All @@ -298,8 +302,10 @@ output:
hosts:
- "localhost:9200"
`),
memEvents: 8096},
"outputLevelQueue": {input: []byte(`
memEvents: 8096,
},
"outputLevelQueue": {
input: []byte(`
name: mockbeat
output:
elasticsearch:
Expand All @@ -309,7 +315,8 @@ output:
mem:
events: 8096
`),
memEvents: 8096},
memEvents: 8096,
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
Expand All @@ -318,10 +325,6 @@ output:

config := beatConfig{}
err = cfg.Unpack(&config)
if tc.expectValidationError {
require.Error(t, err)
return
}
require.NoError(t, err)

err = promoteOutputQueueSettings(&config)
Expand All @@ -339,18 +342,22 @@ func TestValidateBeatConfig(t *testing.T) {
input []byte
expectValidationError string
}{
"blank": {input: []byte(""),
"blank": {
input: []byte(""),
expectValidationError: "",
},
"defaults": {input: []byte(`
"defaults": {
input: []byte(`
name: mockbeat
output:
elasticsearch:
hosts:
- "localhost:9200"
`),
expectValidationError: ""},
"topAndOutputLevelQueue": {input: []byte(`
expectValidationError: "",
},
"topAndOutputLevelQueue": {
input: []byte(`
name: mockbeat
queue:
mem:
Expand All @@ -363,8 +370,10 @@ output:
mem:
events: 8096
`),
expectValidationError: "top level queue and output level queue settings defined, only one is allowed accessing config"},
"managementTopLevelDiskQueue": {input: []byte(`
expectValidationError: "top level queue and output level queue settings defined, only one is allowed accessing config",
},
"managementTopLevelDiskQueue": {
input: []byte(`
name: mockbeat
management:
enabled: true
Expand All @@ -376,8 +385,10 @@ output:
hosts:
- "localhost:9200"
`),
expectValidationError: "disk queue is not supported when management is enabled accessing config"},
"managementOutputLevelDiskQueue": {input: []byte(`
expectValidationError: "disk queue is not supported when management is enabled accessing config",
},
"managementOutputLevelDiskQueue": {
input: []byte(`
name: mockbeat
management:
enabled: true
Expand All @@ -389,8 +400,10 @@ output:
disk:
max_size: 1G
`),
expectValidationError: "disk queue is not supported when management is enabled accessing config"},
"managementFalseOutputLevelDiskQueue": {input: []byte(`
expectValidationError: "disk queue is not supported when management is enabled accessing config",
},
"managementFalseOutputLevelDiskQueue": {
input: []byte(`
name: mockbeat
management:
enabled: false
Expand All @@ -402,7 +415,8 @@ output:
disk:
max_size: 1G
`),
expectValidationError: ""},
expectValidationError: "",
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions libbeat/outputs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
func Fail(err error) (Group, error) { return Group{}, err }

// Success create a valid output Group response for a set of client instances.
// The first argument is expected to contain a queue config.Namespace.
func Success(cfg config.Namespace, batchSize, retry int, clients ...Client) (Group, error) {
var q queue.QueueFactory
if cfg.IsSet() && cfg.Config().Enabled() {
Expand Down Expand Up @@ -73,6 +74,7 @@ func NetworkClients(netclients []NetworkClient) []Client {
}

// SuccessNet create a valid output Group and creates client instances
// The first argument is expected to contain a queue config.Namespace.
func SuccessNet(cfg config.Namespace, loadbalance bool, batchSize, retry int, netclients []NetworkClient) (Group, error) {

if !loadbalance {
Expand Down

0 comments on commit 505fa7c

Please sign in to comment.