Skip to content

Commit 067d1c8

Browse files
Add additional_parameters to diagnostics action (#3333)
Add an optional parameter to the RequestDiagnostics action. This parameter is a list of strings (enum) that has a single value "CPU". If this parameter is specified, the agent should collect a CPU trace.
1 parent 59facd6 commit 067d1c8

6 files changed

+101
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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: enchancement
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Add additional_parameters to diagnostics actions
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+
21+
# Affected component; a word indicating the component this changeset affects.
22+
component:
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
pr: 3333
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
#issue: https://github.com/owner/repo/1234

internal/pkg/api/handleCheckin.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,20 @@ func convertActionData(aType ActionType, raw json.RawMessage) (ad Action_Data, e
707707
}
708708
err = ad.FromActionUpgrade(d)
709709
return
710-
case REQUESTDIAGNOSTICS, UNENROLL: // Action types with no data
710+
case REQUESTDIAGNOSTICS:
711+
d := ActionRequestDiagnostics{}
712+
// NOTE: action data was added to diagnostics actions in #3333
713+
// fleet ui creates actions without a data attribute and fleet-server needs to be backwards compatible with these actions.
714+
if raw == nil {
715+
return
716+
}
717+
err = json.Unmarshal(raw, &d)
718+
if err != nil {
719+
return
720+
}
721+
err = ad.FromActionRequestDiagnostics(d)
722+
return
723+
case UNENROLL: // Action types with no data
711724
return ad, nil
712725
default:
713726
return ad, fmt.Errorf("data conversion unsupported action type: %s", aType)

internal/pkg/api/handleCheckin_test.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ func TestConvertActionData(t *testing.T) {
8989
aType: REQUESTDIAGNOSTICS,
9090
expect: Action_Data{},
9191
hasErr: false,
92+
}, {
93+
name: "request diagnostics action empty data",
94+
aType: REQUESTDIAGNOSTICS,
95+
raw: json.RawMessage(`{}`),
96+
expect: Action_Data{json.RawMessage(`{}`)},
97+
hasErr: false,
98+
}, {
99+
name: "request diagnostics with additional cpu metric",
100+
aType: REQUESTDIAGNOSTICS,
101+
raw: json.RawMessage(`{"additional_metrics": ["CPU"]}`),
102+
expect: Action_Data{json.RawMessage(`{"additional_metrics":["CPU"]}`)},
103+
hasErr: false,
92104
}, {
93105
name: "unenroll action",
94106
aType: UNENROLL,
@@ -126,44 +138,50 @@ func TestConvertActions(t *testing.T) {
126138
token: "",
127139
}, {
128140
name: "single action",
129-
actions: []model.Action{{ActionID: "1234", Type: "REQUEST_DIAGNOSTICS"}},
141+
actions: []model.Action{{ActionID: "1234", Type: "REQUEST_DIAGNOSTICS", Data: json.RawMessage(`{}`)}},
130142
resp: []Action{{
131143
AgentId: "agent-id",
132144
Id: "1234",
133145
Type: REQUESTDIAGNOSTICS,
146+
Data: Action_Data{json.RawMessage(`{}`)},
134147
}},
135148
token: "",
136149
}, {
137150
name: "single action signed",
138-
actions: []model.Action{{ActionID: "1234", Signed: &model.Signed{Data: "eyJAdGltZXN0YW==", Signature: "U6NOg4ssxpFV="}, Type: "REQUEST_DIAGNOSTICS"}},
151+
actions: []model.Action{{ActionID: "1234", Signed: &model.Signed{Data: "eyJAdGltZXN0YW==", Signature: "U6NOg4ssxpFV="}, Type: "REQUEST_DIAGNOSTICS", Data: json.RawMessage(`{}`)}},
139152
resp: []Action{{
140153
AgentId: "agent-id",
141154
Id: "1234",
142155
Type: REQUESTDIAGNOSTICS,
143156
Signed: &ActionSignature{Data: "eyJAdGltZXN0YW==", Signature: "U6NOg4ssxpFV="},
157+
Data: Action_Data{json.RawMessage(`{}`)},
144158
}},
145159
token: "",
146160
}, {name: "multiple actions",
147161
actions: []model.Action{
148162
{
149163
ActionID: "1234",
150164
Type: "REQUEST_DIAGNOSTICS",
165+
Data: json.RawMessage(`{}`),
151166
},
152167
{
153168
ActionID: "5678",
154169
Type: "REQUEST_DIAGNOSTICS",
170+
Data: json.RawMessage(`{}`),
155171
Signed: &model.Signed{Data: "eyJAdGltZXN0YX==", Signature: "U6NOg4ssxpFQ="},
156172
},
157173
},
158174
resp: []Action{{
159175
AgentId: "agent-id",
160176
Id: "1234",
161177
Type: REQUESTDIAGNOSTICS,
178+
Data: Action_Data{json.RawMessage(`{}`)},
162179
}, {
163180
AgentId: "agent-id",
164181
Id: "5678",
165182
Signed: &ActionSignature{Data: "eyJAdGltZXN0YX==", Signature: "U6NOg4ssxpFQ="},
166183
Type: REQUESTDIAGNOSTICS,
184+
Data: Action_Data{json.RawMessage(`{}`)},
167185
}},
168186
token: "",
169187
}}

internal/pkg/api/openapi.gen.go

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

model/openapi.yml

+11-4
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,14 @@ components:
286286
download_rate:
287287
description: The artifact download rate as bytes per second.
288288
type: number
289-
format: double
289+
format: double
290290
retry_error_msg:
291291
description: The error message that is a result of a retryable upgrade download failure.
292-
type: string
292+
type: string
293293
retry_until:
294294
description: The RFC3339 timestamp of the deadline the upgrade download is retried until.
295295
type: string
296-
format: date-time
296+
format: date-time
297297
upgrade_metadata_failed:
298298
description: Upgrade metadata for an upgrade that has failed.
299299
required:
@@ -549,7 +549,14 @@ components:
549549
# unenroll actions have no `data` attribute
550550
actionRequestDiagnostics:
551551
description: The REQUEST_DIAGNOSTICS action data.
552-
# diagnostics actions have no `data` attribute
552+
properties:
553+
additional_metrics:
554+
description: list optional additional metrics.
555+
type: array
556+
items:
557+
type: string
558+
enum:
559+
- CPU
553560
actionPolicyReassign:
554561
description: The POLICY_REASSIGN action data.
555562
type: object

pkg/api/types.gen.go

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)