Skip to content

Commit d47f166

Browse files
authored
Fix validation of the persist field of observability logs and traces (#11118)
1 parent 55657eb commit d47f166

File tree

4 files changed

+94
-5
lines changed

4 files changed

+94
-5
lines changed

.changeset/violet-carrots-press.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@cloudflare/workers-utils": patch
3+
"wrangler": patch
4+
---
5+
6+
Fix validation of the `persist` field of observability `logs` and `traces` configuration

packages/workers-utils/src/config/validation.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4373,6 +4373,15 @@ const validateObservability: ValidatorFn = (diagnostics, field, value) => {
43734373
"string"
43744374
) && isValid;
43754375

4376+
isValid =
4377+
validateOptionalProperty(
4378+
diagnostics,
4379+
field,
4380+
"logs.persist",
4381+
val.logs.persist,
4382+
"boolean"
4383+
) && isValid;
4384+
43764385
isValid =
43774386
validateAdditionalProperties(diagnostics, field, Object.keys(val.logs), [
43784387
"enabled",
@@ -4413,12 +4422,21 @@ const validateObservability: ValidatorFn = (diagnostics, field, value) => {
44134422
"string"
44144423
) && isValid;
44154424

4425+
isValid =
4426+
validateOptionalProperty(
4427+
diagnostics,
4428+
field,
4429+
"traces.persist",
4430+
val.traces.persist,
4431+
"boolean"
4432+
) && isValid;
4433+
44164434
isValid =
44174435
validateAdditionalProperties(
44184436
diagnostics,
44194437
field,
44204438
Object.keys(val.traces),
4421-
["enabled", "head_sampling_rate", "destinations"]
4439+
["enabled", "head_sampling_rate", "destinations", "persist"]
44224440
) && isValid;
44234441
}
44244442

packages/wrangler/src/__tests__/config/configuration.test.ts

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,19 @@ describe("normalizeAndValidateConfig()", () => {
10491049
observability: {
10501050
enabled: true,
10511051
head_sampling_rate: 1,
1052+
logs: {
1053+
enabled: true,
1054+
head_sampling_rate: 1,
1055+
invocation_logs: true,
1056+
destinations: ["test"],
1057+
persist: true,
1058+
},
1059+
traces: {
1060+
enabled: true,
1061+
head_sampling_rate: 1,
1062+
destinations: ["test"],
1063+
persist: true,
1064+
},
10521065
},
10531066
};
10541067

@@ -1136,6 +1149,19 @@ describe("normalizeAndValidateConfig()", () => {
11361149
observability: {
11371150
enabled: "INVALID",
11381151
head_sampling_rate: "INVALID",
1152+
logs: {
1153+
enabled: "INVALID",
1154+
head_sampling_rate: "INVALID",
1155+
destinations: "INVALID",
1156+
persist: "INVALID",
1157+
invocation_logs: "INVALID",
1158+
},
1159+
traces: {
1160+
enabled: "INVALID",
1161+
head_sampling_rate: "INVALID",
1162+
destinations: "INVALID",
1163+
persist: "INVALID",
1164+
},
11391165
},
11401166
} as unknown as RawEnvironment;
11411167

@@ -1208,9 +1234,18 @@ describe("normalizeAndValidateConfig()", () => {
12081234
- Expected \\"logpush\\" to be of type boolean but got \\"INVALID\\".
12091235
- Expected \\"upload_source_maps\\" to be of type boolean but got \\"INVALID\\".
12101236
- Expected \\"observability.enabled\\" to be of type boolean but got \\"INVALID\\".
1211-
- Expected \\"observability.logs.enabled\\" to be of type boolean but got undefined.
1212-
- Expected \\"observability.traces.enabled\\" to be of type boolean but got undefined.
1213-
- Expected \\"observability.head_sampling_rate\\" to be of type number but got \\"INVALID\\"."
1237+
- Expected \\"observability.logs.enabled\\" to be of type boolean but got \\"INVALID\\".
1238+
- Expected \\"observability.traces.enabled\\" to be of type boolean but got \\"INVALID\\".
1239+
- Expected \\"observability.head_sampling_rate\\" to be of type number but got \\"INVALID\\".
1240+
- Expected \\"observability.logs.enabled\\" to be of type boolean but got \\"INVALID\\".
1241+
- Expected \\"observability.logs.head_sampling_rate\\" to be of type number but got \\"INVALID\\".
1242+
- Expected \\"observability.logs.invocation_logs\\" to be of type boolean but got \\"INVALID\\".
1243+
- Expected \\"logs.destinations\\" to be an array of strings but got \\"INVALID\\"
1244+
- Expected \\"observability.logs.persist\\" to be of type boolean but got \\"INVALID\\".
1245+
- Expected \\"observability.traces.enabled\\" to be of type boolean but got \\"INVALID\\".
1246+
- Expected \\"observability.traces.head_sampling_rate\\" to be of type number but got \\"INVALID\\".
1247+
- Expected \\"traces.destinations\\" to be an array of strings but got \\"INVALID\\"
1248+
- Expected \\"observability.traces.persist\\" to be of type boolean but got \\"INVALID\\"."
12141249
`);
12151250
});
12161251

@@ -6682,6 +6717,36 @@ describe("normalizeAndValidateConfig()", () => {
66826717
`);
66836718
});
66846719

6720+
it("should not warn on full observability config", () => {
6721+
const { diagnostics } = normalizeAndValidateConfig(
6722+
{
6723+
observability: {
6724+
enabled: true,
6725+
head_sampling_rate: 1,
6726+
logs: {
6727+
enabled: true,
6728+
head_sampling_rate: 1,
6729+
invocation_logs: true,
6730+
destinations: ["test"],
6731+
persist: true,
6732+
},
6733+
traces: {
6734+
enabled: true,
6735+
head_sampling_rate: 1,
6736+
destinations: ["test"],
6737+
persist: true,
6738+
},
6739+
},
6740+
} as unknown as RawConfig,
6741+
undefined,
6742+
undefined,
6743+
{ env: undefined }
6744+
);
6745+
6746+
expect(diagnostics.hasWarnings()).toBe(false);
6747+
expect(diagnostics.hasErrors()).toBe(false);
6748+
});
6749+
66856750
it("should error on invalid observability.logs", () => {
66866751
const { diagnostics } = normalizeAndValidateConfig(
66876752
{

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14096,7 +14096,7 @@ export default{
1409614096
`);
1409714097
});
1409814098

14099-
it("should allow uploading workers with nested observability logs setting", async () => {
14099+
it("should allow uploading workers with nested observability traces setting", async () => {
1410014100
writeWranglerConfig({
1410114101
observability: {
1410214102
enabled: true,

0 commit comments

Comments
 (0)