Skip to content

Commit 932ebff

Browse files
improvement(aec): add more detail to env update events (#7830)
Co-authored-by: Jon Edvald <edvald@gmail.com>
1 parent 9a97521 commit 932ebff

File tree

6 files changed

+24
-38
lines changed

6 files changed

+24
-38
lines changed

core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"types": "build/src/index.d.ts",
2727
"dependencies": {
2828
"@bufbuild/protobuf": "2.8.0",
29-
"@buf/garden_grow-platform.bufbuild_es": "2.8.0-20251110103340-a7d565dfe8c7.1",
29+
"@buf/garden_grow-platform.bufbuild_es": "2.8.0-20251119201656-897f960f13d3.1",
3030
"@codenamize/codenamize": "^1.1.1",
3131
"@connectrpc/connect": "2.1.0",
3232
"@connectrpc/connect-node": "2.0.4",

core/src/cloud/api/grpc-event-converter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export class GrpcEventConverter {
221221
aecAgentInfo: payload.aecAgentInfo,
222222
projectId: payload.projectId,
223223
timestamp: timestampFromDate(new Date(payload.timestamp)),
224+
lastDeployed: payload.lastDeployed,
224225
actionTriggered: payload.actionTriggered
225226
? aecEnvironmentUpdateActionTriggeredMap[payload.actionTriggered]
226227
: undefined,
@@ -230,6 +231,7 @@ export class GrpcEventConverter {
230231
inProgress: payload.inProgress,
231232
error: payload.error,
232233
success: payload.success,
234+
resource: payload.resource,
233235
}),
234236
}),
235237
]

core/src/events/events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ export interface AecAgentEnvironmentUpdate {
316316
error: boolean
317317
actionTriggered?: AecAction
318318
success?: boolean
319+
resource: string[]
319320
}
320321

321322
export type EventName = keyof Events

core/src/plugins/kubernetes/commands/aec-agent.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,22 @@ async function handler({ ctx, log, args, garden }: PluginCommandParams<Kubernete
251251
return { result }
252252
}
253253

254-
function emitEnvironmentStatus(events: EventBus, event: EventPayload<"aecAgentEnvironmentUpdate">) {
254+
function emitEnvironmentStatus(
255+
events: EventBus,
256+
namespaceName: string,
257+
event: Omit<EventPayload<"aecAgentEnvironmentUpdate">, "resource" | "timestamp">
258+
) {
255259
const key = `${event.projectId}-${event.environmentType}-${event.environmentName}`
256260
const lastStatus = lastEnvironmentStatus[key]
257261
if (lastStatus === event.statusDescription) {
258262
return
259263
}
260264
lastEnvironmentStatus[key] = event.statusDescription
261-
events.emit("aecAgentEnvironmentUpdate", event)
265+
events.emit("aecAgentEnvironmentUpdate", {
266+
...event,
267+
timestamp: new Date().toISOString(),
268+
resource: [`namespace/${namespaceName}`],
269+
})
262270
}
263271

264272
async function cleanupLoop({
@@ -332,8 +340,7 @@ async function cleanupLoop({
332340

333341
// Skip sending events if the namespace is not configured for AEC
334342
if (result.aecConfigured) {
335-
emitEnvironmentStatus(events, {
336-
timestamp: new Date().toISOString(),
343+
emitEnvironmentStatus(events, namespaceName, {
337344
aecAgentInfo,
338345
projectId,
339346
environmentType,
@@ -350,8 +357,7 @@ async function cleanupLoop({
350357
} catch (e) {
351358
const msg = `Unexpected error: ${e}`
352359
nsLog.error({ msg })
353-
emitEnvironmentStatus(events, {
354-
timestamp: new Date().toISOString(),
360+
emitEnvironmentStatus(events, namespaceName, {
355361
aecAgentInfo,
356362
projectId,
357363
environmentType,
@@ -658,8 +664,7 @@ export async function checkAndCleanupNamespace({
658664
log.info({ msg: `Pausing workloads...` })
659665

660666
if (!dryRun) {
661-
emitEnvironmentStatus(events, {
662-
timestamp: new Date().toISOString(),
667+
emitEnvironmentStatus(events, namespaceName, {
663668
aecAgentInfo,
664669
projectId,
665670
environmentType,
@@ -709,8 +714,7 @@ export async function checkAndCleanupNamespace({
709714
log.info({ msg: `Cleaning up namespace` })
710715

711716
if (!dryRun) {
712-
emitEnvironmentStatus(events, {
713-
timestamp: new Date().toISOString(),
717+
emitEnvironmentStatus(events, namespaceName, {
714718
aecAgentInfo,
715719
projectId,
716720
environmentType,

core/test/unit/src/cloud/grpc-event-stream.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ describe("GrpcEventStream", () => {
178178
inProgress: false,
179179
error: false,
180180
success: false,
181+
resource: ["namespace/fake-namespace-name"],
181182
})
182183
await bufferedEventStream.close()
183184
expect(receivedEvents.length).to.equal(1)

package-lock.json

Lines changed: 5 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)