Skip to content

Commit

Permalink
fix(workflows): fix some logging issues in run workflows command
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Jun 24, 2020
1 parent c90c928 commit 6383558
Show file tree
Hide file tree
Showing 34 changed files with 116 additions and 116 deletions.
8 changes: 4 additions & 4 deletions garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ export class ActionRouter implements TypeGuard {
const envLog = log.info({ msg: chalk.white("Cleaning up environments..."), status: "active" })
const environmentStatuses: EnvironmentStatusMap = {}

const providers = await this.garden.resolveProviders()
const providers = await this.garden.resolveProviders(log)
await Bluebird.each(Object.values(providers), async (provider) => {
await this.cleanupEnvironment({ pluginName: provider.name, log: envLog })
environmentStatuses[provider.name] = await this.getEnvironmentStatus({ pluginName: provider.name, log: envLog })
Expand Down Expand Up @@ -687,7 +687,7 @@ export class ActionRouter implements TypeGuard {

// TODO: find a nicer way to do this (like a type-safe wrapper function)
private async commonParams(handler: WrappedActionHandler<any, any>, log: LogEntry): Promise<PluginActionParamsBase> {
const provider = await this.garden.resolveProvider(handler.pluginName)
const provider = await this.garden.resolveProvider(log, handler.pluginName)

return {
ctx: this.garden.getPluginContext(provider),
Expand Down Expand Up @@ -789,7 +789,7 @@ export class ActionRouter implements TypeGuard {
if (!runtimeContextIsEmpty && (await getRuntimeTemplateReferences(module)).length > 0) {
log.silly(`Resolving runtime template strings for service '${service.name}'`)

const providers = await this.garden.resolveProviders()
const providers = await this.garden.resolveProviders(log)
const graph = await this.garden.getConfigGraph(log, runtimeContext)
service = graph.getService(service.name)
module = service.module
Expand Down Expand Up @@ -849,7 +849,7 @@ export class ActionRouter implements TypeGuard {
if (runtimeContext && (await getRuntimeTemplateReferences(module)).length > 0) {
log.silly(`Resolving runtime template strings for task '${task.name}'`)

const providers = await this.garden.resolveProviders()
const providers = await this.garden.resolveProviders(log)
const graph = await this.garden.getConfigGraph(log, runtimeContext)
task = graph.getTask(task.name)
module = task.module
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/get/get-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class GetStatusCommand extends Command {
async action({ garden, log, opts }: CommandParams): Promise<CommandResult<StatusCommandResult>> {
const actions = await garden.getActionRouter()

const envStatus = await garden.getEnvironmentStatus()
const envStatus = await garden.getEnvironmentStatus(log)
const serviceStatuses = await actions.getServiceStatuses({ log })

let result: StatusCommandResult = {
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class PluginsCommand extends Command<Args> {
printHeader(log, title, "gear")
}

const provider = await garden.resolveProvider(args.plugin)
const provider = await garden.resolveProvider(log, args.plugin)
const ctx = garden.getPluginContext(provider)

let modules: Module[] = []
Expand Down
42 changes: 21 additions & 21 deletions garden-service/src/commands/run/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ export class RunWorkflowCommand extends Command<Args, {}> {
const metadata = {
workflowStep: { index },
}
const stepHeaderLog = log.placeholder({ indent: 1, metadata })
const stepBodyLog = log.placeholder({ indent: 1, metadata })
const stepFooterLog = log.placeholder({ indent: 1, metadata })
const stepHeaderLog = outerLog.placeholder({ indent: 1, metadata })
const stepBodyLog = outerLog.placeholder({ indent: 1, metadata })
const stepFooterLog = outerLog.placeholder({ indent: 1, metadata })
garden.log.setState({ metadata })
let stepResult: CommandResult
const inheritedOpts = cloneDeep(opts)
Expand Down Expand Up @@ -146,7 +146,7 @@ export class RunWorkflowCommand extends Command<Args, {}> {
})
printResult({ startedAt, log: outerLog, workflow, success: false })

logErrors(log, [err], index, steps.length, step.description)
logErrors(outerLog, [err], index, steps.length, step.description)
return { result, errors: [err] }
}

Expand All @@ -161,7 +161,7 @@ export class RunWorkflowCommand extends Command<Args, {}> {

if (stepResult.errors) {
garden.events.emit("workflowStepError", { index })
logErrors(log, stepResult.errors, index, steps.length, step.description)
logErrors(outerLog, stepResult.errors, index, steps.length, step.description)
return { result, errors: stepResult.errors }
}

Expand Down Expand Up @@ -201,14 +201,17 @@ function getStepName(index: number, name?: string) {
export function printStepHeader(log: LogEntry, stepIndex: number, stepCount: number, stepDescription?: string) {
const maxWidth = Math.min(getTerminalWidth(), 120)
let text = `Running step ${formattedStepDescription(stepIndex, stepCount, stepDescription)}`
const bar = repeat("═", maxWidth)
const header = chalk.cyan(dedent`
\n${wordWrap(text, maxWidth)}
${bar}\n
`)
const header = dedent`
${chalk.cyan.bold(wordWrap(text, maxWidth))}
${getSeparatorBar(maxWidth)}
`
log.info(header)
}

function getSeparatorBar(width: number) {
return chalk.white(repeat("═", width))
}

export function printStepDuration({
log,
stepIndex,
Expand All @@ -229,14 +232,8 @@ export function printStepDuration({
${chalk.white(durationSecs)} Sec
`
const maxWidth = Math.min(getTerminalWidth(), 120)
const bar = repeat("═", maxWidth)
log.info(
chalk.cyan(dedent`
${bar}
${text}
\n\n
`)
)

log.info(`${getSeparatorBar(maxWidth)}\n${chalk.cyan.bold(text)}\n\n`)
}

export function formattedStepDescription(stepIndex: number, stepCount: number, stepDescription?: string) {
Expand Down Expand Up @@ -265,11 +262,14 @@ function printResult({
const completedAt = new Date().valueOf()
const totalDuration = ((completedAt - startedAt) / 1000).toFixed(2)

const resultColor = success ? chalk.magenta : chalk.red
const resultColor = success ? chalk.magenta.bold : chalk.red.bold
const resultMessage = success ? "completed successfully" : "failed"

log.info(
resultColor(`Workflow ${chalk.white.bold(workflow.name)} ${resultMessage}. `) +
chalk.magenta(`Total time elapsed: ${chalk.white.bold(totalDuration)} Sec.`)
)
log.info("")
log.info(resultColor(`Workflow ${chalk.white(workflow.name)} completed.`))
log.info(chalk.magenta(`Total time elapsed: ${chalk.white(totalDuration)} Sec.`))
}

export async function runStepCommand({
Expand Down
26 changes: 13 additions & 13 deletions garden-service/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ export class Garden {
return names ? findByNames(names, this.providerConfigs, "provider") : this.providerConfigs
}

async resolveProvider(name: string) {
async resolveProvider(log: LogEntry, name: string) {
this.log.silly(`Resolving provider ${name}`)
if (name === "_default") {
return defaultProvider
Expand All @@ -505,7 +505,7 @@ export class Garden {
return this.resolvedProviders[name]
}

const providers = await this.resolveProviders(false, [name])
const providers = await this.resolveProviders(log, false, [name])
const provider = providers[name]

if (!provider) {
Expand All @@ -523,7 +523,7 @@ export class Garden {
return provider
}

async resolveProviders(forceInit = false, names?: string[]): Promise<ProviderMap> {
async resolveProviders(log: LogEntry, forceInit = false, names?: string[]): Promise<ProviderMap> {
let providers: Provider[] = []

await this.asyncLock.acquire("resolve-providers", async () => {
Expand All @@ -542,9 +542,9 @@ export class Garden {
return
}

this.log.silly(`Resolving providers`)
log.silly(`Resolving providers`)

const log = this.log.info({
log = log.info({
section: "providers",
msg: "Getting status...",
status: "active",
Expand Down Expand Up @@ -630,7 +630,7 @@ export class Garden {
log.setSuccess({ msg: chalk.green("Done"), append: true })
}

this.log.silly(`Resolved providers: ${providers.map((p) => p.name).join(", ")}`)
log.silly(`Resolved providers: ${providers.map((p) => p.name).join(", ")}`)
})

return keyBy(providers, "name")
Expand Down Expand Up @@ -660,8 +660,8 @@ export class Garden {
/**
* Returns the reported status from all configured providers.
*/
async getEnvironmentStatus() {
const providers = await this.resolveProviders()
async getEnvironmentStatus(log: LogEntry) {
const providers = await this.resolveProviders(log)
return mapValues(providers, (p) => p.status)
}

Expand Down Expand Up @@ -692,8 +692,8 @@ export class Garden {
return Object.values(keys ? pickKeys(this.moduleConfigs, keys, "module config") : this.moduleConfigs)
}

async getOutputConfigContext(modules: Module[], runtimeContext: RuntimeContext) {
const providers = await this.resolveProviders()
async getOutputConfigContext(log: LogEntry, modules: Module[], runtimeContext: RuntimeContext) {
const providers = await this.resolveProviders(log)
return new OutputConfigContext({
garden: this,
resolvedProviders: providers,
Expand All @@ -708,9 +708,9 @@ export class Garden {
* For long-running processes, you need to call this again when any module or configuration has been updated.
*/
async getConfigGraph(log: LogEntry, runtimeContext?: RuntimeContext) {
const providers = await this.resolveProviders()
const providers = await this.resolveProviders(log)
const configs = await this.getRawModuleConfigs()
this.log.silly(`Resolving module configs`)
log.silly(`Resolving module configs`)
// Resolve the project module configs
const tasks = configs.map(
(moduleConfig) =>
Expand Down Expand Up @@ -1151,7 +1151,7 @@ export class Garden {
"name"
)

providers = Object.values(await this.resolveProviders()).map((p) => {
providers = Object.values(await this.resolveProviders(log)).map((p) => {
return {
...omit(p, ["tools"]),
dependencies: mapValues(p.dependencies, (d) => omit(d, ["tools"])),
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export async function resolveProjectOutputs(garden: Garden, log: LogEntry): Prom
taskResults,
})

const configContext = await garden.getOutputConfigContext(modules, runtimeContext)
const configContext = await garden.getOutputConfigContext(log, modules, runtimeContext)

return resolveTemplateStrings(garden.rawOutputs, configContext)
}
2 changes: 1 addition & 1 deletion garden-service/src/plugins/kubernetes/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export async function prepareSystem({
}

const sysGarden = await getSystemGarden(k8sCtx, variables || {}, log)
const sysProvider = <KubernetesProvider>await sysGarden.resolveProvider(provider.name)
const sysProvider = <KubernetesProvider>await sysGarden.resolveProvider(log, provider.name)
const systemNamespace = await getSystemNamespace(sysProvider, log)
const sysApi = await KubeApi.factory(log, sysProvider)

Expand Down
2 changes: 1 addition & 1 deletion garden-service/test/integ/src/plugins/kubernetes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("KubeApi", () => {
before(async () => {
const root = getDataDir("test-projects", "container")
garden = await makeTestGarden(root)
provider = (await garden.resolveProvider("local-kubernetes")) as Provider<KubernetesConfig>
provider = (await garden.resolveProvider(garden.log, "local-kubernetes")) as Provider<KubernetesConfig>
api = await KubeApi.factory(garden.log, provider)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe("pull-image plugin command", () => {
const init = async (environmentName: string) => {
garden = await getContainerTestGarden(environmentName)
graph = await garden.getConfigGraph(garden.log)
provider = <KubernetesProvider>await garden.resolveProvider("local-kubernetes")
containerProvider = <ContainerProvider>await garden.resolveProvider("container")
provider = <KubernetesProvider>await garden.resolveProvider(garden.log, "local-kubernetes")
containerProvider = <ContainerProvider>await garden.resolveProvider(garden.log, "container")
ctx = garden.getPluginContext(provider)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ describe("kubernetes build flow", () => {
const init = async (environmentName: string) => {
garden = await getContainerTestGarden(environmentName)
graph = await garden.getConfigGraph(garden.log)
provider = <KubernetesProvider>await garden.resolveProvider("local-kubernetes")
containerProvider = <ContainerProvider>await garden.resolveProvider("container")
provider = <KubernetesProvider>await garden.resolveProvider(garden.log, "local-kubernetes")
containerProvider = <ContainerProvider>await garden.resolveProvider(garden.log, "container")
ctx = garden.getPluginContext(provider)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function getContainerTestGarden(environmentName: string = defaultEn

if (needsInit) {
// Load the test authentication for private registries
const localProvider = <KubernetesProvider>await localInstance.resolveProvider("local-kubernetes")
const localProvider = <KubernetesProvider>await localInstance.resolveProvider(localInstance.log, "local-kubernetes")
const api = await KubeApi.factory(garden.log, localProvider)

try {
Expand Down Expand Up @@ -87,7 +87,7 @@ export async function getContainerTestGarden(environmentName: string = defaultEn
await api.upsert({ kind: "Secret", namespace: "default", obj: credentialHelperAuth, log: garden.log })
}

const provider = <KubernetesProvider>await garden.resolveProvider("local-kubernetes")
const provider = <KubernetesProvider>await garden.resolveProvider(garden.log, "local-kubernetes")
const ctx = garden.getPluginContext(provider)

if (needsInit) {
Expand All @@ -107,7 +107,7 @@ describe("kubernetes container module handlers", () => {

before(async () => {
garden = await makeTestGarden(root)
provider = <KubernetesProvider>await garden.resolveProvider("local-kubernetes")
provider = <KubernetesProvider>await garden.resolveProvider(garden.log, "local-kubernetes")
namespace = garden.projectName
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("kubernetes container deployment handlers", () => {

const init = async (environmentName: string) => {
garden = await getContainerTestGarden(environmentName)
provider = <KubernetesProvider>await garden.resolveProvider("local-kubernetes")
provider = <KubernetesProvider>await garden.resolveProvider(garden.log, "local-kubernetes")
api = await KubeApi.factory(garden.log, provider)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("kubernetes", () => {
const root = getDataDir("test-projects", "container")
garden = await makeTestGarden(root)
graph = await garden.getConfigGraph(garden.log)
provider = await garden.resolveProvider("local-kubernetes")
provider = await garden.resolveProvider(garden.log, "local-kubernetes")
ctx = garden.getPluginContext(provider)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("runContainerTask", () => {

before(async () => {
garden = await getContainerTestGarden()
provider = <KubernetesProvider>await garden.resolveProvider("local-kubernetes")
provider = <KubernetesProvider>await garden.resolveProvider(garden.log, "local-kubernetes")
})

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("Helm common functions", () => {

before(async () => {
garden = await getHelmTestGarden()
const provider = await garden.resolveProvider("local-kubernetes")
const provider = await garden.resolveProvider(garden.log, "local-kubernetes")
ctx = garden.getPluginContext(provider)
log = garden.log
graph = await garden.getConfigGraph(garden.log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("configureHelmModule", () => {

before(async () => {
garden = await getHelmTestGarden()
const provider = await garden.resolveProvider("local-kubernetes")
const provider = await garden.resolveProvider(garden.log, "local-kubernetes")
ctx = garden.getPluginContext(provider)
await garden.resolveModules({ log: garden.log })
moduleConfigs = cloneDeep((<any>garden).moduleConfigs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("deployHelmService", () => {

before(async () => {
garden = await getHelmTestGarden()
provider = <KubernetesProvider>await garden.resolveProvider("local-kubernetes")
provider = <KubernetesProvider>await garden.resolveProvider(garden.log, "local-kubernetes")
ctx = <KubernetesPluginContext>garden.getPluginContext(provider)
const graph = await garden.getConfigGraph(garden.log)
await buildHelmModules(garden, graph)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe("configureHotReload", () => {

before(async () => {
garden = await getHelmTestGarden()
provider = <KubernetesProvider>await garden.resolveProvider("local-kubernetes")
provider = <KubernetesProvider>await garden.resolveProvider(garden.log, "local-kubernetes")
ctx = garden.getPluginContext(provider)
})

Expand Down
4 changes: 2 additions & 2 deletions garden-service/test/integ/src/plugins/kubernetes/helm/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("runHelmTask", () => {
const key = testTask.getKey()

// Clear any existing task result
const provider = await garden.resolveProvider("local-kubernetes")
const provider = await garden.resolveProvider(garden.log, "local-kubernetes")
const ctx = garden.getPluginContext(provider)
await clearTaskResult({ ctx, log: garden.log, module: task.module, task, taskVersion: version })

Expand Down Expand Up @@ -84,7 +84,7 @@ describe("runHelmTask", () => {
})

// Clear any existing task result
const provider = await garden.resolveProvider("local-kubernetes")
const provider = await garden.resolveProvider(garden.log, "local-kubernetes")
const ctx = garden.getPluginContext(provider)
await clearTaskResult({ ctx, log: garden.log, module: task.module, task, taskVersion: version })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("validateKubernetesModule", () => {

before(async () => {
garden = await getKubernetesTestGarden()
const provider = await garden.resolveProvider("local-kubernetes")
const provider = await garden.resolveProvider(garden.log, "local-kubernetes")
ctx = garden.getPluginContext(provider)
await garden.resolveModules({ log: garden.log })
moduleConfigs = cloneDeep((<any>garden).moduleConfigs)
Expand Down
Loading

0 comments on commit 6383558

Please sign in to comment.