Skip to content

Commit 497ed84

Browse files
authored
Merge branch 'main' into add_k8s_events_kube_stack
2 parents 1f59db2 + 26a5543 commit 497ed84

File tree

11 files changed

+296
-85
lines changed

11 files changed

+296
-85
lines changed

.buildkite/pipeline.agentless-app-release.yaml

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,14 @@
11
env:
22
VERSION: "${BUILDKITE_COMMIT:0:12}"
33
steps:
4-
- label: "Packaging: Service Container linux/amd64"
5-
key: packaging-service-container-amd64
6-
env:
7-
PACKAGES: "docker"
8-
PLATFORMS: "linux/amd64"
9-
DOCKER_VARIANTS: "service"
10-
command: |
11-
.buildkite/scripts/steps/integration-package.sh
12-
artifact_paths:
13-
- "build/distributions/elastic-agent-service-git-*.docker.tar.gz"
14-
agents:
15-
provider: "gcp"
16-
machineType: "c2-standard-16"
17-
diskSizeGb: 400
18-
19-
- label: "Packaging: Service Container linux/arm64"
20-
key: packaging-service-container-arm64
21-
env:
22-
PACKAGES: "docker"
23-
PLATFORMS: "linux/arm64"
24-
DOCKER_VARIANTS: "service"
25-
command: |
26-
.buildkite/scripts/steps/integration-package.sh
27-
artifact_paths:
28-
- "build/distributions/elastic-agent-service-git-*.docker.tar.gz"
29-
agents:
30-
provider: "aws"
31-
instanceType: "t4g.2xlarge"
32-
imagePrefix: "core-ubuntu-2204-aarch64"
33-
diskSizeGb: 400
34-
35-
# wait for packaging to be done
36-
- wait: ~
37-
38-
- label: "Publish to internal registry"
4+
- label: "Mirror Elastic-Agent Snapshot DRA to internal registry"
395
key: "mirror-elastic-agent"
406
command: ".buildkite/scripts/steps/ecp-internal-release.sh"
417
agents:
428
image: docker.elastic.co/ci-agent-images/serverless-helm-builder:0.0.2@sha256:d00e8a7a0ab3618cfaacb0a7b1e1b06ee29728eb2b44de602374bd8f6b9b92ac
439

10+
11+
4412
# wait for metadata to be set
4513
- wait: ~
4614

.buildkite/pipeline.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,3 @@ steps:
374374
build:
375375
commit: "${BUILDKITE_COMMIT}"
376376
branch: "${BUILDKITE_BRANCH}"
377-
378-
# wait for packaging to be done
379-
- wait: ~
380-
381-
- label: "Publish to serverless"
382-
branches: main
383-
trigger: "agentless-serverless-release"

.buildkite/scripts/steps/ecp-internal-release.sh

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set -eu
2020
_SELF=$(dirname $0)
2121
source "${_SELF}/../common.sh"
2222

23+
2324
# annotate create temp markdown file if not exists
2425
# this file will be later used to annotate the build
2526
# it appends to the file the message passed as argument
@@ -32,9 +33,19 @@ write_annotation() {
3233
cat $BUILDKITE_ANNOTATE_FILE | buildkite-agent annotate --style info
3334
}
3435

35-
BUILD_VERSION="$(jq -r '.version' .package-version)"
36-
DOCKER_TAG="git-${VERSION}"
3736
PRIVATE_REPO="docker.elastic.co/observability-ci/ecp-elastic-agent-service"
37+
SNAPSHOT_DRA_URL=https://snapshots.elastic.co/latest/master.json
38+
39+
DRA_RESULT=$(curl -s -X GET "$SNAPSHOT_DRA_URL")
40+
echo "$DRA_RESULT"
41+
BUILD_ID=$(echo "$DRA_RESULT" | jq '.build_id' | tr -d '"')
42+
BUILD_VERSION=$(echo "$DRA_RESULT" | jq '.version' | tr -d '"')
43+
44+
MANIFEST_URL="https://snapshots.elastic.co/$BUILD_ID/agent-package/agent-artifacts-$BUILD_VERSION.json"
45+
GIT_COMMIT=$(curl -s -X GET "$MANIFEST_URL" | jq '.projects["elastic-agent-core"]["commit_hash"]' | tr -d '"')
46+
GIT_SHORT_COMMIT=$(echo "$GIT_COMMIT" | cut -c1-12)
47+
48+
DOCKER_TAG="git-${GIT_SHORT_COMMIT}"
3849
PRIVATE_IMAGE="${PRIVATE_REPO}:${DOCKER_TAG}"
3950

4051
# TODO: let's avoid accessing vault directly but use the vault plugin itself
@@ -46,19 +57,13 @@ DOCKER_REGISTRY="docker.elastic.co"
4657
DOCKER_USERNAME_SECRET=$(retry 5 vault kv get -field user "${DOCKER_REGISTRY_SECRET_PATH}")
4758
DOCKER_PASSWORD_SECRET=$(retry 5 vault kv get -field password "${DOCKER_REGISTRY_SECRET_PATH}")
4859
skopeo login --username "${DOCKER_USERNAME_SECRET}" --password "${DOCKER_PASSWORD_SECRET}" "${DOCKER_REGISTRY}"
49-
50-
# download the amd64 and arm64 builds of the image from the previous steps
51-
buildkite-agent artifact download "build/distributions/**" . --step "packaging-service-container-amd64"
52-
buildkite-agent artifact download "build/distributions/**" . --step "packaging-service-container-arm64"
53-
54-
# copy the images into the private image location
55-
skopeo copy --all "docker-archive:./build/distributions/elastic-agent-service-$DOCKER_TAG-$BUILD_VERSION-linux-amd64.docker.tar.gz" "docker://$PRIVATE_IMAGE"
56-
skopeo copy --all "docker-archive:./build/distributions/elastic-agent-service-$DOCKER_TAG-$BUILD_VERSION-linux-arm64.docker.tar.gz" "docker://$PRIVATE_IMAGE"
60+
skopeo copy --all "docker://docker.elastic.co/cloud-release/elastic-agent-service:$BUILD_ID-SNAPSHOT" "docker://$PRIVATE_IMAGE"
5761

5862
annotate "* Image: $PRIVATE_IMAGE"
59-
annotate "* Short commit: $VERSION"
60-
annotate "* Commit: https://github.com/elastic/elastic-agent/commit/$VERSION"
63+
annotate "* Short commit: $GIT_SHORT_COMMIT"
64+
annotate "* Commit: https://github.com/elastic/elastic-agent/commit/$GIT_COMMIT"
65+
annotate "* Manifest: $MANIFEST_URL"
6166

62-
buildkite-agent meta-data set "git-short-commit" "$VERSION"
67+
buildkite-agent meta-data set "git-short-commit" "$GIT_SHORT_COMMIT"
6368

6469
write_annotation
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: feature
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Add agent_policy_id and policy_revision_idx to checkin requests
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
description: |
20+
Add agent_policy_id and policy_revision_idx attributes to checkin requests.
21+
These attributes are used to inform fleet-server of the policy id and revision that the agent is currently running.
22+
Add a feature flag to disable sending acks for POLICY_CHANGE actions on a future release.
23+
24+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
25+
component: elastic-agent
26+
27+
# PR URL; optional; the PR number that added the changeset.
28+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
29+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
30+
# Please provide it if you are adding a fragment for a different PR.
31+
pr: https://github.com/elastic/elastic-agent/pull/9931
32+
33+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
34+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
35+
issue: https://github.com/elastic/elastic-agent/issues/6446

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/elastic/elastic-agent/internal/pkg/fleetapi/client"
3030
"github.com/elastic/elastic-agent/internal/pkg/remote"
3131
"github.com/elastic/elastic-agent/pkg/core/logger"
32+
"github.com/elastic/elastic-agent/pkg/features"
3233
)
3334

3435
// PolicyChangeHandler is a handler for POLICY_CHANGE action.
@@ -41,6 +42,7 @@ type PolicyChangeHandler struct {
4142
setters []actions.ClientSetter
4243
policyLogLevelSetter logLevelSetter
4344
coordinator *coordinator.Coordinator
45+
disableAckFn func() bool
4446
// Disabled for 8.8.0 release in order to limit the surface
4547
// https://github.com/elastic/security-team/issues/6501
4648
// // Last known valid signature validation key
@@ -67,6 +69,7 @@ func NewPolicyChangeHandler(
6769
setters: setters,
6870
coordinator: coordinator,
6971
policyLogLevelSetter: policyLogLevelSetter,
72+
disableAckFn: features.DisablePolicyChangeAcks,
7073
}
7174
}
7275

@@ -111,7 +114,7 @@ func (h *PolicyChangeHandler) Handle(ctx context.Context, a fleetapi.Action, ack
111114
return err
112115
}
113116

114-
h.ch <- newPolicyChange(ctx, c, a, acker, false)
117+
h.ch <- newPolicyChange(ctx, c, a, acker, false, h.disableAckFn())
115118
return nil
116119
}
117120

@@ -473,18 +476,19 @@ type policyChange struct {
473476
cfg *config.Config
474477
action fleetapi.Action
475478
acker acker.Acker
476-
commit bool
477479
ackWatcher chan struct{}
480+
disableAck bool
478481
}
479482

480483
func newPolicyChange(
481484
ctx context.Context,
482485
config *config.Config,
483486
action fleetapi.Action,
484487
acker acker.Acker,
485-
commit bool) *policyChange {
488+
makeCh bool,
489+
disableAck bool) *policyChange {
486490
var ackWatcher chan struct{}
487-
if commit {
491+
if makeCh {
488492
// we don't need it otherwise
489493
ackWatcher = make(chan struct{})
490494
}
@@ -493,39 +497,38 @@ func newPolicyChange(
493497
cfg: config,
494498
action: action,
495499
acker: acker,
496-
commit: true,
497500
ackWatcher: ackWatcher,
501+
disableAck: disableAck,
498502
}
499503
}
500504

501505
func (l *policyChange) Config() *config.Config {
502506
return l.cfg
503507
}
504508

509+
// Ack sends an ack for the associated action if the results are expected.
510+
// An ack will be sent for UNENROLL actions, or by POLICY_CHANGE actions if it has not been explicitly disabled.
505511
func (l *policyChange) Ack() error {
506-
if l.action == nil {
512+
if l.disableAck || l.action == nil {
507513
return nil
508514
}
509515
err := l.acker.Ack(l.ctx, l.action)
510516
if err != nil {
511517
return err
512518
}
513-
if l.commit {
514-
err := l.acker.Commit(l.ctx)
515-
if l.ackWatcher != nil && err == nil {
516-
close(l.ackWatcher)
517-
}
518-
return err
519+
err = l.acker.Commit(l.ctx)
520+
if err == nil && l.ackWatcher != nil {
521+
close(l.ackWatcher)
519522
}
520-
return nil
523+
return err
521524
}
522525

523526
// WaitAck waits for policy change to be acked.
524527
// Policy change ack is awaitable only in case commit flag was set.
525528
// Caller is responsible to use any reasonable deadline otherwise
526529
// function call can be endlessly blocking.
527530
func (l *policyChange) WaitAck(ctx context.Context) {
528-
if !l.commit || l.ackWatcher == nil {
531+
if l.ackWatcher == nil {
529532
return
530533
}
531534

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

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestPolicyAcked(t *testing.T) {
105105
agentInfo := &info.AgentInfo{}
106106
nullStore := &storage.NullStore{}
107107

108-
t.Run("Config change should ACK", func(t *testing.T) {
108+
t.Run("Default: Config changes are ACKed", func(t *testing.T) {
109109
ch := make(chan coordinator.ConfigChange, 1)
110110
tacker := &testAcker{}
111111

@@ -119,6 +119,7 @@ func TestPolicyAcked(t *testing.T) {
119119
},
120120
}
121121

122+
// Test default FF value
122123
cfg := configuration.DefaultConfiguration()
123124
handler := NewPolicyChangeHandler(log, agentInfo, cfg, nullStore, ch, nilLogLevelSet(t), &coordinator.Coordinator{})
124125

@@ -129,9 +130,64 @@ func TestPolicyAcked(t *testing.T) {
129130
require.NoError(t, change.Ack())
130131

131132
actions := tacker.Items()
132-
assert.EqualValues(t, 1, len(actions))
133+
assert.Len(t, actions, 1)
133134
assert.Equal(t, actionID, actions[0])
134135
})
136+
t.Run("Config change acks when forced", func(t *testing.T) {
137+
ch := make(chan coordinator.ConfigChange, 1)
138+
tacker := &testAcker{}
139+
140+
config := map[string]interface{}{"hello": "world"}
141+
actionID := "abc123"
142+
action := &fleetapi.ActionPolicyChange{
143+
ActionID: actionID,
144+
ActionType: "POLICY_CHANGE",
145+
Data: fleetapi.ActionPolicyChangeData{
146+
Policy: config,
147+
},
148+
}
149+
150+
cfg := configuration.DefaultConfiguration()
151+
handler := NewPolicyChangeHandler(log, agentInfo, cfg, nullStore, ch, nilLogLevelSet(t), &coordinator.Coordinator{})
152+
handler.disableAckFn = func() bool { return false }
153+
154+
err := handler.Handle(context.Background(), action, tacker)
155+
require.NoError(t, err)
156+
157+
change := <-ch
158+
require.NoError(t, change.Ack())
159+
160+
actions := tacker.Items()
161+
assert.Len(t, actions, 1)
162+
assert.Equal(t, actionID, actions[0])
163+
})
164+
t.Run("Config change do not ack when disabled", func(t *testing.T) {
165+
ch := make(chan coordinator.ConfigChange, 1)
166+
tacker := &testAcker{}
167+
168+
config := map[string]interface{}{"hello": "world"}
169+
actionID := "abc123"
170+
action := &fleetapi.ActionPolicyChange{
171+
ActionID: actionID,
172+
ActionType: "POLICY_CHANGE",
173+
Data: fleetapi.ActionPolicyChangeData{
174+
Policy: config,
175+
},
176+
}
177+
178+
cfg := configuration.DefaultConfiguration()
179+
handler := NewPolicyChangeHandler(log, agentInfo, cfg, nullStore, ch, nilLogLevelSet(t), &coordinator.Coordinator{})
180+
handler.disableAckFn = func() bool { return true }
181+
182+
err := handler.Handle(context.Background(), action, tacker)
183+
require.NoError(t, err)
184+
185+
change := <-ch
186+
require.NoError(t, change.Ack())
187+
188+
actions := tacker.Items()
189+
assert.Empty(t, actions)
190+
})
135191
}
136192

137193
func TestPolicyChangeHandler_handlePolicyChange_FleetClientSettings(t *testing.T) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (h *Unenroll) handle(ctx context.Context, a fleetapi.Action, acker acker.Ac
9393
}
9494

9595
// Generate empty policy change, this removing all the running components
96-
unenrollPolicy := newPolicyChange(ctx, config.New(), a, acker, true)
96+
unenrollPolicy := newPolicyChange(ctx, config.New(), a, acker, true, false)
9797
h.ch <- unenrollPolicy
9898

9999
// backup action for future start to avoid starting fleet gateway loop

0 commit comments

Comments
 (0)