Skip to content

Commit 3220869

Browse files
authored
Merge branch 'main' into dependabot/go_modules/github.com/elastic/elastic-agent-libs-0.9.8
2 parents 89c6c9e + c5e9707 commit 3220869

File tree

8 files changed

+82
-60
lines changed

8 files changed

+82
-60
lines changed

.buildkite/scripts/steps/integration_tests.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ MAGE_SUBTARGET="${3:-""}"
99

1010

1111
# Override the agent package version using a string with format <major>.<minor>.<patch>
12-
# NOTE: use only after version bump when the new version is not yet available, for example:
13-
# OVERRIDE_AGENT_PACKAGE_VERSION="8.10.3" otherwise OVERRIDE_AGENT_PACKAGE_VERSION="".
14-
OVERRIDE_AGENT_PACKAGE_VERSION="8.14.0"
12+
# There is a time when the snapshot is not built yet, so we cannot use the latest version automatically
13+
# This file is managed by an automation (mage integration:UpdateAgentPackageVersion) that check if the snapshot is ready.
14+
OVERRIDE_AGENT_PACKAGE_VERSION="$(cat .package-version)"
1515

1616
if [[ -n "$OVERRIDE_AGENT_PACKAGE_VERSION" ]]; then
1717
OVERRIDE_TEST_AGENT_VERSION=${OVERRIDE_AGENT_PACKAGE_VERSION}"-SNAPSHOT"
+9-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#!/bin/bash
22
set -e
33

4+
package_version=$(mage integration:updatePackageVersion)
45
version_requirements=$(mage integration:updateVersions)
5-
changes=$(git status -s -uno .agent-versions.json)
6+
changes=$(git status -s -uno .agent-versions.json .package-version)
67
if [ -z "$changes" ]
78
then
8-
echo "The versions file didn't change, skipping..."
9+
echo "The version files didn't change, skipping..."
910
else
10-
echo "The versions file changed"
11+
echo "The version file(s) changed"
12+
git diff -p
1113
open=$(gh pr list --repo "$GITHUB_REPOSITORY" --label="update-versions" --limit 1 --state open --base "$GITHUB_REF_NAME")
1214
if [ -n "$open" ]
1315
then
1416
echo "Another PR for $GITHUB_REF_NAME is in review, skipping..."
1517
exit 0
1618
fi
17-
git diff -p
18-
git add ".agent-versions.json"
19+
git add .agent-versions.json .package-version
1920

2021
nl=$'\n' # otherwise the new line character is not recognized properly
21-
commit_desc="This file is used for picking agent versions in integration tests.${nl}${nl}The file's content is based on responses from https://www.elastic.co/api/product_versions and https://snapshots.elastic.co${nl}${nl}The current update is generated based on the following requirements:${nl}${nl}\`\`\`json${nl}${version_requirements}${nl}\`\`\`"
22+
commit_desc="These files are used for picking agent versions in integration tests.${nl}${nl}The content is based on responses from https://www.elastic.co/api/product_versions and https://snapshots.elastic.co${nl}${nl}The current update is generated based on the following requirements:${nl}${nl}Package version: ${package_version}${nl}${nl}\`\`\`json${nl}${version_requirements}${nl}\`\`\`"
2223

23-
git commit -m "[$GITHUB_REF_NAME][Automation] Update .agent-versions.json" -m "$commit_desc"
24+
git commit -m "[$GITHUB_REF_NAME][Automation] Update versions" -m "$commit_desc"
2425
git push --set-upstream origin "update-agent-versions-$GITHUB_RUN_ID"
2526
pr=$(gh pr create \
2627
--base "$GITHUB_REF_NAME" \
@@ -33,5 +34,5 @@ else
3334
--label 'backport-skip' \
3435
--repo $GITHUB_REPOSITORY)
3536
echo "pr=$pr" >> "$GITHUB_OUTPUT" # set the step output for Slack notifications
36-
echo "Created a PR with the file update: $pr"
37+
echo "Created a PR with the an update: $pr"
3738
fi

.github/workflows/bump-agent-versions.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
version: v1.13.0
4040
install-only: true
4141

42-
- name: Update versions file
42+
- name: Update versions
4343
id: update
4444
env:
4545
GH_TOKEN: ${{ env.GITHUB_TOKEN }}
@@ -51,7 +51,7 @@ jobs:
5151
url: ${{ secrets.VAULT_ADDR }}
5252
roleId: ${{ secrets.VAULT_ROLE_ID }}
5353
secretId: ${{ secrets.VAULT_SECRET_ID }}
54-
message: ":traffic_cone: Elastic Agent versions file update failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
54+
message: ":traffic_cone: Elastic Agent version update failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
5555
channel: "#ingest-notifications"
5656

5757
# if a PR was created as a result of this job, we notify on the Slack channel
@@ -61,5 +61,5 @@ jobs:
6161
url: ${{ secrets.VAULT_ADDR }}
6262
roleId: ${{ secrets.VAULT_ROLE_ID }}
6363
secretId: ${{ secrets.VAULT_SECRET_ID }}
64-
message: "Update for Elastic Agent versions file has been created: ${{ steps.update.outputs.pr }}"
64+
message: "Update for Elastic Agent versions has been created: ${{ steps.update.outputs.pr }}"
6565
channel: "#ingest-notifications"

.package-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.14.0

internal/pkg/agent/application/actions/handlers/handler_action_settings.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,21 @@ func (h *Settings) handleLogLevel(ctx context.Context, logLevel string, acker ac
7575
} else if err := acker.Commit(ctx); err != nil {
7676
h.log.Errorf("failed to commit acker after acknowledging action with id '%s'", action.ActionID)
7777
}
78-
h.log.Infof("Settings action done, setting agent log level to %s", logLevel)
7978

8079
if lvl != nil {
80+
h.log.Infof("Settings action done, setting agent log level to %s", logLevel)
8181
return h.logLevelSetter.SetLogLevel(ctx, lvl)
8282
}
8383

8484
if h.fallbackLogLevel != nil {
85+
h.log.Infof("Settings action done, setting agent log level to policy default %s", h.fallbackLogLevel)
8586
// use fallback log level
8687
return h.logLevelSetter.SetLogLevel(ctx, h.fallbackLogLevel)
8788
}
8889

8990
// use default log level
9091
defaultLogLevel := logger.DefaultLogLevel
92+
h.log.Infof("Settings action done, setting agent log level to default %s", defaultLogLevel)
9193
return h.logLevelSetter.SetLogLevel(ctx, &defaultLogLevel)
9294
}
9395

magefile.go

+28
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,34 @@ func (Integration) UpdateVersions(ctx context.Context) error {
20452045
return nil
20462046
}
20472047

2048+
// UpdatePackageVersion update the file that contains the latest available snapshot version
2049+
func (Integration) UpdatePackageVersion(ctx context.Context) error {
2050+
const packageVersionFilename = ".package-version"
2051+
2052+
sc := snapshots.NewSnapshotsClient()
2053+
versions, err := sc.FindLatestSnapshots(ctx, []string{"master"})
2054+
if err != nil {
2055+
return fmt.Errorf("failed to fetch a manifest for the latest snapshot: %w", err)
2056+
}
2057+
if len(versions) != 1 {
2058+
return fmt.Errorf("expected a single version, got %v", versions)
2059+
}
2060+
packageVersion := versions[0].CoreVersion()
2061+
file, err := os.OpenFile(packageVersionFilename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
2062+
if err != nil {
2063+
return fmt.Errorf("failed to open %s for write: %w", packageVersionFilename, err)
2064+
}
2065+
defer file.Close()
2066+
_, err = file.WriteString(packageVersion)
2067+
if err != nil {
2068+
return fmt.Errorf("failed to write the package version file %s: %w", packageVersionFilename, err)
2069+
}
2070+
2071+
fmt.Println(packageVersion)
2072+
2073+
return nil
2074+
}
2075+
20482076
var stateDir = ".integration-cache"
20492077
var stateFile = "state.yml"
20502078

pkg/testing/tools/estools/elasticsearch.go

+19-36
Original file line numberDiff line numberDiff line change
@@ -375,21 +375,17 @@ func CheckForErrorsInLogs(ctx context.Context, client elastictransport.Interface
375375
// CheckForErrorsInLogsWithContext checks to see if any error-level lines exist
376376
// excludeStrings can be used to remove any particular error strings from logs
377377
func CheckForErrorsInLogsWithContext(ctx context.Context, client elastictransport.Interface, namespace string, excludeStrings []string) (Documents, error) {
378-
queryRaw := map[string]interface{}{
379-
"query": map[string]interface{}{
380-
"bool": map[string]interface{}{
381-
"must": []map[string]interface{}{
382-
{
383-
"match": map[string]interface{}{
384-
"log.level": "error",
385-
},
386-
},
387-
{
388-
"term": map[string]interface{}{
389-
"data_stream.namespace": map[string]interface{}{
390-
"value": namespace,
391-
},
392-
},
378+
filters := map[string]interface{}{
379+
"must": []map[string]interface{}{
380+
{
381+
"match": map[string]interface{}{
382+
"log.level": "error",
383+
},
384+
},
385+
{
386+
"term": map[string]interface{}{
387+
"data_stream.namespace": map[string]interface{}{
388+
"value": namespace,
393389
},
394390
},
395391
},
@@ -405,27 +401,14 @@ func CheckForErrorsInLogsWithContext(ctx context.Context, client elastictranspor
405401
},
406402
})
407403
}
408-
queryRaw = map[string]interface{}{
409-
"query": map[string]interface{}{
410-
"bool": map[string]interface{}{
411-
"must": []map[string]interface{}{
412-
{
413-
"match": map[string]interface{}{
414-
"log.level": "error",
415-
},
416-
},
417-
{
418-
"term": map[string]interface{}{
419-
"data_stream.namespace": map[string]interface{}{
420-
"value": namespace,
421-
},
422-
},
423-
},
424-
},
425-
"must_not": excludeStatements,
426-
},
427-
},
428-
}
404+
405+
filters["must_not"] = excludeStatements
406+
}
407+
408+
queryRaw := map[string]interface{}{
409+
"query": map[string]interface{}{
410+
"bool": filters,
411+
},
429412
}
430413

431414
var buf bytes.Buffer

testing/integration/logs_ingestion_test.go

+16-9
Original file line numberDiff line numberDiff line change
@@ -274,21 +274,28 @@ func testMonitoringLogsAreShipped(
274274
"Failed to initialize artifact",
275275
"Failed to apply initial policy from on disk configuration",
276276
"elastic-agent-client error: rpc error: code = Canceled desc = context canceled", // can happen on restart
277-
"add_cloud_metadata: received error failed requesting openstack metadata: Get \\\"https://169.254.169.254/2009-04-04/meta-data/instance-id\\\": dial tcp 169.254.169.254:443: connect: connection refused", // okay for the openstack metadata to not work
278-
"add_cloud_metadata: received error failed requesting openstack metadata: Get \\\"https://169.254.169.254/2009-04-04/meta-data/hostname\\\": dial tcp 169.254.169.254:443: connect: connection refused", // okay for the cloud metadata to not work
279-
"add_cloud_metadata: received error failed requesting openstack metadata: Get \\\"https://169.254.169.254/2009-04-04/meta-data/placement/availability-zone\\\": dial tcp 169.254.169.254:443: connect: connection refused", // okay for the cloud metadata to not work
280-
"add_cloud_metadata: received error failed requesting openstack metadata: Get \\\"https://169.254.169.254/2009-04-04/meta-data/instance-type\\\": dial tcp 169.254.169.254:443: connect: connection refused", // okay for the cloud metadata to not work
281-
"add_cloud_metadata: received error failed with http status code 404", // okay for the cloud metadata to not work
282-
"add_cloud_metadata: received error failed fetching EC2 Identity Document: not found, Signing", // okay for the cloud metadata to not work
283-
"add_cloud_metadata: received error failed fetching EC2 Identity Document: operation error ec2imds: GetInstanceIdentityDocument, http response error StatusCode: 404, request to EC2 IMDS failed", // okay for the cloud metadata to not work
284-
"failed to invoke rollback watcher: failed to start Upgrade Watcher: fork/exec /var/lib/elastic-agent/elastic-agent: no such file or directory", // on debian this happens probably need to fix.
277+
"add_cloud_metadata: received error failed requesting openstack metadata", // okay for the cloud metadata to not work
278+
"add_cloud_metadata: received error failed with http status code 404", // okay for the cloud metadata to not work
279+
"add_cloud_metadata: received error failed fetching EC2 Identity Document", // okay for the cloud metadata to not work
280+
"failed to invoke rollback watcher: failed to start Upgrade Watcher", // on debian this happens probably need to fix.
281+
"falling back to IMDSv1: operation error ec2imds: getToken", // okay for the cloud metadata to not work
285282
})
286283
})
287284
t.Logf("error logs: Got %d documents", len(docs.Hits.Hits))
285+
messages := make([]string, 0, len(docs.Hits.Hits))
288286
for _, doc := range docs.Hits.Hits {
289287
t.Logf("%#v", doc.Source)
288+
message, ok := doc.Source["message"]
289+
if !ok {
290+
continue
291+
}
292+
messageStr, ok := message.(string)
293+
if !ok {
294+
continue
295+
}
296+
messages = append(messages, messageStr)
290297
}
291-
require.Empty(t, docs.Hits.Hits)
298+
require.Emptyf(t, docs.Hits.Hits, "list of error messages is expected to be empty, found:\n%s", strings.Join(messages, ", \n"))
292299

293300
// Stage 3: Make sure we have message confirming central management is running
294301
t.Log("Making sure we have message confirming central management is running")

0 commit comments

Comments
 (0)