Skip to content

Commit

Permalink
feat(cloud): stream command metadata
Browse files Browse the repository at this point in the history
When logged in, we now stream a command metadata event.
  • Loading branch information
s-chand authored and edvald committed Jul 29, 2021
1 parent dd67389 commit de925e4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
19 changes: 12 additions & 7 deletions core/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ${renderCommands(commands)}
`
}

private async initFileWriters(logger: Logger, root: string, gardenDirPath: string) {
private async initFileWriters(logger: Logger, gardenDirPath: string) {
if (this.fileWritersInitialized) {
return
}
Expand Down Expand Up @@ -204,12 +204,14 @@ ${renderCommands(commands)}
})
const dashboardEventStream = new DashboardEventStream({ log, sessionId })

const commandInfo = {
name: command.getFullName(),
args: parsedArgs,
opts: optionsWithAliasValues(command, parsedOpts),
}

const contextOpts: GardenOpts = {
commandInfo: {
name: command.getFullName(),
args: parsedArgs,
opts: optionsWithAliasValues(command, parsedOpts),
},
commandInfo,
disablePortForwards,
environmentName,
log,
Expand Down Expand Up @@ -288,11 +290,14 @@ ${renderCommands(commands)}
},
],
})
if (streamEvents) {
bufferedEventStream.streamEvent("commandInfo", commandInfo)
}
}

// Register log file writers. We need to do this after the Garden class is initialised because
// the file writers depend on the project root.
await this.initFileWriters(logger, garden.projectRoot, garden.gardenDirPath)
await this.initFileWriters(logger, garden.gardenDirPath)
analytics = await AnalyticsHandler.init(garden, log)
analytics.trackCommand(command.getFullName())

Expand Down
1 change: 0 additions & 1 deletion core/src/enterprise/buffered-event-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ export class BufferedEventStream {
try {
await Bluebird.map(this.targets, (target) => {
if (target.enterprise && this.enterpriseApi?.domain) {
this.log.silly(`Flushing ${description} to GE /${path}`)
// Need to cast so the compiler doesn't complain that the two returns from the map
// aren't equivalent. Shouldn't matter in this case since we're not collecting the return value.
return this.enterpriseApi.post<any>(path, {
Expand Down
5 changes: 5 additions & 0 deletions core/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { NamespaceStatus, RunStatus } from "./types/plugin/base"
import { Omit } from "./util/util"
import { AuthTokenResponse } from "./enterprise/api"
import { BuildState } from "./types/plugin/module/build"
import { CommandInfo } from "./plugin-context"

export type GardenEventListener<T extends EventName> = (payload: Events[T]) => void

Expand Down Expand Up @@ -115,6 +116,9 @@ export interface Events extends LoggerEvents {
}
moduleRemoved: {}

// Command/project metadata events
commandInfo: CommandInfo

// TaskGraph events
taskPending: {
addedAt: Date
Expand Down Expand Up @@ -253,6 +257,7 @@ export const eventNames: EventName[] = [
"moduleConfigChanged",
"moduleSourcesChanged",
"moduleRemoved",
"commandInfo",
"taskPending",
"taskProcessing",
"taskComplete",
Expand Down
2 changes: 1 addition & 1 deletion core/src/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { isString, omit } from "lodash"
import { isString } from "lodash"

export interface GardenError {
type: string
Expand Down

0 comments on commit de925e4

Please sign in to comment.