Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion worker/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const KV_PREFIX_HISTORY = "history";
export const KV_PREFIX_UUID = "uuid";
export const KV_MAX_PROCESS_ENTRIES = 800;

export const SCHEMA_VERSION_QUEUE = 13;
export const SCHEMA_VERSION_QUEUE = 14;
export const SCHEMA_VERSION_ANALYTICS = 3;

export const BRANDS_DOMAINS_URL =
Expand Down Expand Up @@ -115,6 +115,14 @@ export interface QueueData {
energy: {
count_configured: number;
};
recorder: {
engines: {
[engine: string]: {
count_configured: number;
versions: Record<string, number>;
};
};
};
}

export interface Queue {
Expand Down Expand Up @@ -195,6 +203,7 @@ export interface IncomingPayload {
user_count?: number;
certificate?: boolean;
energy?: { configured: boolean };
recorder?: { engine: string; version: string };
uuid: string;
version: string;
}
Expand Down Expand Up @@ -248,6 +257,9 @@ export const createQueueData = (): QueueData => ({
energy: {
count_configured: 0,
},
recorder: {
engines: {},
},
});

export const generateUuidMetadata = (
Expand Down
18 changes: 18 additions & 0 deletions worker/src/handlers/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,23 @@ function combineEntryData(
data.certificate_count_configured++;
}

if (entrydata.recorder) {
if (!data.recorder.engines[entrydata.recorder.engine]) {
data.recorder.engines[entrydata.recorder.engine] = {
versions: {},
count_configured: 0,
};
}
data.recorder.engines[entrydata.recorder.engine].count_configured++;
data.recorder.engines[entrydata.recorder.engine].versions[
entrydata.recorder.version
] = bumpValue(
data.recorder.engines[entrydata.recorder.engine].versions[
entrydata.recorder.version
]
);
}

return data;
}

Expand Down Expand Up @@ -542,5 +559,6 @@ const processQueueData = (data: QueueData) => {
energy: {
count_configured: data.energy.count_configured,
},
recorder: data.recorder,
};
};
5 changes: 5 additions & 0 deletions worker/src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const defaultTrue = coerce(boolean(), nullable(boolean()), (value) =>
value === null ? true : value
);

const stringLowerCase = coerce(string(), string(), (value) =>
value.toLowerCase()
);

export const IncomingPayloadStruct = object({
addon_count: optional(number()),
addons: optional(
Expand Down Expand Up @@ -73,6 +77,7 @@ export const IncomingPayloadStruct = object({
object({ board: string(), version: optional(nullable(string())) })
),
energy: optional(object({ configured: boolean() })),
recorder: optional(object({ engine: stringLowerCase, version: string() })),
certificate: optional(boolean()),
user_count: optional(number()),
uuid: size(string(), 32, 32),
Expand Down
11 changes: 7 additions & 4 deletions worker/tests/utils/validate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe("createIncomingPayload", function () {
region: "XX",
state_count: 1,
energy: { configured: true },
recorder: { engine: "Awesome_Engine", version: "123" },
supervisor: { healthy: false, supported: true, arch: "amd64" },
user_count: 1,
certificate: true,
Expand All @@ -84,29 +85,31 @@ describe("createIncomingPayload", function () {
expect(fullPayload.uuid).toBe(BASE_PAYLOAD.uuid);
expect(fullPayload.installation_type).toBe(BASE_PAYLOAD.installation_type);
expect(fullPayload.version).toBe(BASE_PAYLOAD.version);
expect(fullPayload.energy.configured).toBeTruthy();
expect(fullPayload.energy!.configured).toBeTruthy();
expect(fullPayload.recorder!.engine).toBe("awesome_engine");
expect(fullPayload.recorder!.version).toBe("123");

const payloadWithoutArch = createIncomingPayload({
...payload,
supervisor: { healthy: false, supported: true },
});

expect(payloadWithoutArch.supervisor.arch).not.toBeDefined();
expect(payloadWithoutArch.supervisor!.arch).not.toBeDefined();
});

it("Default true", function () {
const payload = createIncomingPayload({
...BASE_PAYLOAD,
addons: [{ ...ADDON, protected: null }],
});
expect(payload.addons[0].protected).toBe(true);
expect(payload.addons![0].protected).toBe(true);
});

it("Default false", function () {
const payload = createIncomingPayload({
...BASE_PAYLOAD,
addons: [{ ...ADDON, auto_update: null }],
});
expect(payload.addons[0].auto_update).toBe(false);
expect(payload.addons![0].auto_update).toBe(false);
});
});