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
22 changes: 21 additions & 1 deletion src/commands/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,30 @@ export async function usage(opts: { from?: string; to?: string; json?: boolean;
}
}

// pure: platform path for a compute deploy-events request (used by `insta logs --deploy`).
export function deployEventsPath(projectId: string, opts: { group?: string; branch?: string; limit?: string; instance?: string }): string {
return `/projects/${projectId}/deploy-events${qs({ group: opts.group, branch: opts.branch, limit: opts.limit, instance: opts.instance })}`
}

// pure: render one deploy event as a log-style line.
export function deployEventLine(ev: { ts?: string; origin?: string; type?: string; status?: string; instance?: string }): string {
const inst = ev.instance ? ` (${ev.instance})` : ''
return `${ev.ts ?? ''} [${ev.origin ?? ''}] ${ev.type ?? ''}: ${ev.status ?? ''}${inst}`
}

// insta logs <db|compute> [group]
export async function logs(component: string, group: string | undefined, opts: { branch?: string; limit?: string; region?: string; instance?: string; json?: boolean }): Promise<void> {
export async function logs(component: string, group: string | undefined, opts: { branch?: string; limit?: string; region?: string; instance?: string; json?: boolean; deploy?: boolean }): Promise<void> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Agent-facing command references remain stale: README omits --deploy, and the required skills/insta/cli-reference.md update is absent from this change. Document the new flag and its compute-only deploy-event behavior with the implementation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/commands/metrics.ts, line 93:

<comment>Agent-facing command references remain stale: README omits `--deploy`, and the required `skills/insta/cli-reference.md` update is absent from this change. Document the new flag and its compute-only deploy-event behavior with the implementation.</comment>

<file context>
@@ -78,10 +78,30 @@ export async function usage(opts: { from?: string; to?: string; json?: boolean;
+
 // insta logs <db|compute> [group]
-export async function logs(component: string, group: string | undefined, opts: { branch?: string; limit?: string; region?: string; instance?: string; json?: boolean }): Promise<void> {
+export async function logs(component: string, group: string | undefined, opts: { branch?: string; limit?: string; region?: string; instance?: string; json?: boolean; deploy?: boolean }): Promise<void> {
   const api = await ApiClient.load()
   const p = await requireProject()
</file context>

const api = await ApiClient.load()
const p = await requireProject()
if (opts.deploy) {
if (component !== 'compute') return info('deploy events are only available for compute')
Comment on lines +96 to +97

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: When --deploy is used, the --region option is silently ignored: deploy-events don't support region filtering, but the option is still accepted without any feedback to the user. Someone familiar with runtime logs might pass --region expecting it to narrow deploy events too, and get no indication that it was dropped. Consider either warning when --deploy and --region are combined, or omitting --region from help text when deploy mode is active (though commander doesn't support dynamic options easily, so a warning in the handler is the practical path).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/commands/metrics.ts, line 96:

<comment>When `--deploy` is used, the `--region` option is silently ignored: deploy-events don't support region filtering, but the option is still accepted without any feedback to the user. Someone familiar with runtime logs might pass `--region` expecting it to narrow deploy events too, and get no indication that it was dropped. Consider either warning when `--deploy` and `--region` are combined, or omitting `--region` from help text when deploy mode is active (though commander doesn't support dynamic options easily, so a warning in the handler is the practical path).</comment>

<file context>
@@ -78,10 +78,30 @@ export async function usage(opts: { from?: string; to?: string; json?: boolean;
+export async function logs(component: string, group: string | undefined, opts: { branch?: string; limit?: string; region?: string; instance?: string; json?: boolean; deploy?: boolean }): Promise<void> {
   const api = await ApiClient.load()
   const p = await requireProject()
+  if (opts.deploy) {
+    if (component !== 'compute') return info('deploy events are only available for compute')
+    const res = await api.request('GET', deployEventsPath(p.projectId, { group, branch: opts.branch ?? p.branch, limit: opts.limit, instance: opts.instance }))
</file context>
Suggested change
if (opts.deploy) {
if (component !== 'compute') return info('deploy events are only available for compute')
if (opts.deploy) {
if (opts.region) info('note: --region is not applicable to deploy events, ignoring')
if (component !== 'compute') return info('deploy events are only available for compute')

const res = await api.request('GET', deployEventsPath(p.projectId, { group, branch: opts.branch ?? p.branch, limit: opts.limit, instance: opts.instance }))
if (opts.json) return printJson(res)
if (res.note) info(`note: ${res.note}`)
if (!res.events?.length) return info('(no deploy events)')
for (const ev of res.events) info(deployEventLine(ev))
return
}
const res = await api.request('GET', `/projects/${p.projectId}/logs${qs({ component, group, branch: opts.branch ?? p.branch, limit: opts.limit, region: opts.region, instance: opts.instance })}`)
if (opts.json) return printJson(res)
if (res.note) info(`note: ${res.note}`)
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ program.command('regions').description('List regions available for postgres/comp
program.command('metrics <target> [group]').description('Service metrics (target: db|compute)')
.option('--branch <b>').option('--from <unix>').option('--to <unix>').option('--step <s>').option('--json')
.action(guard((target, group, o) => obs.metrics(target, group, o)))
program.command('logs <target> [group]').description('Service runtime logs (target: db|compute)')
.option('--branch <b>').option('--limit <n>').option('--region <r>').option('--instance <i>').option('--json')
program.command('logs <target> [group]').description('Service logs (runtime by default; --deploy = compute deploy events; target: db|compute)')
.option('--branch <b>').option('--limit <n>').option('--region <r>').option('--instance <i>').option('--deploy', 'show compute deploy events (machine lifecycle) instead of runtime logs').option('--json')
.action(guard((target, group, o) => obs.logs(target, group, o)))
program.command('usage').description('Usage for the current billing cycle by billing dimension (org by default; --proj for one project)')
.option('--from <unix>').option('--to <unix>').option('--proj [id]', 'show one project (the linked one, or a given id) instead of the whole org').option('--json')
Expand Down
24 changes: 24 additions & 0 deletions test/logs-deploy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// `insta logs --deploy` targets /deploy-events and renders each machine event as one line.
import { describe, it, expect } from 'vitest'
import { deployEventsPath, deployEventLine } from '../src/commands/metrics.js'

describe('deployEventsPath', () => {
it('targets /deploy-events with defined params in order', () => {
expect(deployEventsPath('p1', { group: 'api', branch: 'main', limit: '50' }))
.toBe('/projects/p1/deploy-events?group=api&branch=main&limit=50')
})
it('omits undefined/empty params', () => {
expect(deployEventsPath('p1', {})).toBe('/projects/p1/deploy-events')
})
})

describe('deployEventLine', () => {
it('renders [origin] type: status with the instance suffix', () => {
expect(deployEventLine({ ts: 'T', origin: 'flyd', type: 'start', status: 'started', instance: 'm-1' }))
.toBe('T [flyd] start: started (m-1)')
})
it('omits the instance suffix when absent', () => {
expect(deployEventLine({ ts: 'T', origin: 'user', type: 'launch', status: 'created' }))
.toBe('T [user] launch: created')
})
})
Loading