-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update elastic-agent-libs to v0.9.9 and add tests to ensure Beats always logs as JSON to a file when no logging is explicitly configured.
- Loading branch information
Showing
5 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12969,11 +12969,11 @@ SOFTWARE | |
|
||
-------------------------------------------------------------------------------- | ||
Dependency : github.com/elastic/elastic-agent-libs | ||
Version: v0.9.8 | ||
Version: v0.9.9 | ||
Licence type (autodetected): Apache-2.0 | ||
-------------------------------------------------------------------------------- | ||
|
||
Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected].8/LICENSE: | ||
Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected].9/LICENSE: | ||
|
||
Apache License | ||
Version 2.0, January 2004 | ||
|
@@ -55932,6 +55932,35 @@ Contents of probable licence file $GOMODCACHE/gopkg.in/jcmturner/[email protected]/L | |
limitations under the License. | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
Dependency : gopkg.in/mcuadros/go-syslog.v2 | ||
Version: v2.3.0 | ||
Licence type (autodetected): MIT | ||
-------------------------------------------------------------------------------- | ||
|
||
Contents of probable licence file $GOMODCACHE/gopkg.in/mcuadros/[email protected]/LICENSE: | ||
|
||
Copyright (c) 2013 Máximo Cuadros | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
Dependency : gopkg.in/tomb.v1 | ||
Version: v1.0.0-20141024135613-dd632973f1e7 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// 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. | ||
|
||
package integration | ||
|
||
import ( | ||
"bufio" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/elastic/beats/v7/libbeat/tests/integration" | ||
) | ||
|
||
var filebeatBasicConfig = ` | ||
filebeat.inputs: | ||
- type: filestream | ||
id: "test-filebeat-can-log" | ||
paths: | ||
- %s | ||
path.home: %s | ||
output.discard.enabled: true | ||
` | ||
|
||
func TestFilebeatRunsAndLogsJSONToFile(t *testing.T) { | ||
filebeat := integration.NewBeat( | ||
t, | ||
"filebeat", | ||
"../../filebeat.test", | ||
) | ||
filebeat.RemoveAllCLIArgs() | ||
|
||
tempDir := filebeat.TempDir() | ||
|
||
// 1. Generate the log file path, but do not write data to it | ||
logFilePath := path.Join(tempDir, "log.log") | ||
|
||
// 2. Create the log file | ||
integration.GenerateLogFile(t, logFilePath, 10, false) | ||
|
||
// 3. Write configuration file ans start Filebeat | ||
filebeat.WriteConfigFile(fmt.Sprintf(filebeatBasicConfig, logFilePath, tempDir)) | ||
filebeat.Start() | ||
|
||
// We're not interested in data ingestion, we just want to ensure Filebeat can run | ||
// and logs to file when no logging is explicitly configured | ||
|
||
// The default logs home path is `path.logs: ${path.home}/logs` | ||
logFileName := fmt.Sprintf("filebeat-%s.ndjson", time.Now().Format("20060102")) | ||
filebeatLogFile := filepath.Join(tempDir, "logs", logFileName) | ||
|
||
var f *os.File | ||
var err error | ||
require.Eventuallyf(t, func() bool { | ||
fmt.Println(".") | ||
f, err = os.Open(filebeatLogFile) | ||
if err != nil { | ||
return false | ||
} | ||
return true | ||
}, 10*time.Second, time.Millisecond, "could not read log file '%s'", filebeatLogFile) | ||
defer f.Close() | ||
|
||
r := bufio.NewScanner(f) | ||
count := 0 | ||
for r.Scan() { | ||
line := r.Bytes() | ||
m := map[string]any{} | ||
if err := json.Unmarshal(line, &m); err != nil { | ||
t.Fatalf("line %d is not a valid JSON: %s", count, err) | ||
} | ||
count++ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters