mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 00:20:51 +00:00
feat: filter the audit log by run (#12190)
* feat: filter the audit log by run Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: update ee-repo-ref Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: say a nested approval lists under its subflow Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: put the run's audit logs in a menu on the left of its actions Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf: open a run's audit logs on the run's own time range Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: include the run's steps and subflows in the run filter Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: name each step and mark mocked or skipped steps in run audit entries Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: show a step's id in the resource cell instead of next to the operation Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep step details in the audit drawer and show its parameters as json Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: update ee-repo-ref to 0bb5b777e634dadd154c0adfe6d26251560f9283 This commit updates the EE repository reference after PR #946 was merged in windmill-ee-private. Previous ee-repo-ref: b2f1890730a3368019183985161744187b5323a7 New ee-repo-ref: 0bb5b777e634dadd154c0adfe6d26251560f9283 Automated by sync-ee-ref workflow. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com> Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
This commit is contained in:
co-authored by
Claude Opus 5.5
windmill-internal-app[bot]
Ruben Fiszel
parent
77fb2eda01
commit
f9448bf25b
@@ -1 +1 @@
|
||||
0d933e22cac4578cb14d8bac36347c75d6736dfe
|
||||
0bb5b777e634dadd154c0adfe6d26251560f9283
|
||||
|
||||
@@ -135,3 +135,80 @@ async fn test_job_run_is_searchable_by_token_and_by_caller(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The run filter must find a run's entries under each key they keep its id in: the run itself
|
||||
/// (`parameters.uuid`), a cancel (`resource`) and a resume (`parameters.job_id`), and only those.
|
||||
#[cfg(all(feature = "enterprise", feature = "private"))]
|
||||
#[sqlx::test(migrations = "../migrations", fixtures("base"))]
|
||||
async fn test_audit_list_filters_by_run(db: Pool<Postgres>) -> anyhow::Result<()> {
|
||||
use serde_json::json;
|
||||
|
||||
initialize_tracing().await;
|
||||
let server = ApiServer::start(db.clone()).await?;
|
||||
let port = server.addr.port();
|
||||
let w = format!("http://localhost:{port}/api/w/test-workspace");
|
||||
|
||||
let mut ids = vec![];
|
||||
for _ in 0..2 {
|
||||
let resp = authed(client().post(format!("{w}/jobs/run/preview")))
|
||||
.json(
|
||||
&json!({ "content": "export function main() {}", "language": "deno", "args": {} }),
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
assert_eq!(resp.status(), 201);
|
||||
ids.push(resp.text().await?);
|
||||
}
|
||||
let (run, other) = (&ids[0], &ids[1]);
|
||||
|
||||
let resp = authed(client().post(format!("{w}/jobs_u/queue/cancel/{run}")))
|
||||
.json(&json!({}))
|
||||
.send()
|
||||
.await?;
|
||||
assert_2xx(resp.status().as_u16(), &resp.text().await?, "cancel");
|
||||
// A subflow of the run and a step of that subflow, whose approval and start are filed under
|
||||
// their own ids.
|
||||
let (sub, step) = (uuid::Uuid::new_v4(), uuid::Uuid::new_v4());
|
||||
sqlx::query(
|
||||
"INSERT INTO v2_job (id, workspace_id, parent_job)
|
||||
VALUES ($1, 'test-workspace', $2::uuid), ($3, 'test-workspace', $1)",
|
||||
)
|
||||
.bind(sub)
|
||||
.bind(run)
|
||||
.bind(step)
|
||||
.execute(&db)
|
||||
.await?;
|
||||
sqlx::query(
|
||||
"INSERT INTO audit_partitioned (workspace_id, username, operation, action_kind, parameters)
|
||||
VALUES ('test-workspace', 'test-user', 'jobs.suspend_resume', 'update', $1),
|
||||
('test-workspace', 'test-user', 'jobs.run.script', 'execute', $2)",
|
||||
)
|
||||
.bind(json!({ "job_id": sub }))
|
||||
.bind(json!({ "uuid": step }))
|
||||
.execute(&db)
|
||||
.await?;
|
||||
|
||||
let resp = authed(client().get(format!("{w}/audit/list?job_id={run}")))
|
||||
.send()
|
||||
.await?;
|
||||
assert_eq!(resp.status(), 200);
|
||||
let mut ops = resp
|
||||
.json::<Vec<serde_json::Value>>()
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|l| l["operation"].as_str().unwrap_or_default().to_string())
|
||||
.collect::<Vec<_>>();
|
||||
ops.sort();
|
||||
assert_eq!(
|
||||
ops,
|
||||
[
|
||||
"jobs.cancel",
|
||||
"jobs.run.preview",
|
||||
"jobs.run.script",
|
||||
"jobs.suspend_resume"
|
||||
],
|
||||
"entries of {run} (not of {other})"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -282,6 +282,15 @@ paths:
|
||||
description: get audit logs for all workspaces
|
||||
schema:
|
||||
type: boolean
|
||||
- name: job_id
|
||||
in: query
|
||||
description: >
|
||||
only the entries about this run and the jobs under it (steps, loop iterations
|
||||
and subflows at any depth): who started, viewed, cancelled, approved, resumed
|
||||
or deleted each
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
|
||||
responses:
|
||||
"200":
|
||||
|
||||
@@ -5082,18 +5082,31 @@ pub async fn resume_suspended_flow_as_owner(
|
||||
job_id,
|
||||
&flow,
|
||||
value,
|
||||
Some(authed.username),
|
||||
Some(authed.username.clone()),
|
||||
true,
|
||||
&mut tx,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let (flow_id, flow_path) = (flow.id, flow.script_path.clone());
|
||||
if is_wac {
|
||||
decrement_suspend(flow.id, &mut tx).await?;
|
||||
} else {
|
||||
resume_immediately_if_relevant(flow, job_id, &mut tx).await?;
|
||||
}
|
||||
|
||||
audit_suspend_resume(
|
||||
&mut tx,
|
||||
&AuditAuthor::from(&authed),
|
||||
&w_id,
|
||||
flow_path.as_deref(),
|
||||
flow_id,
|
||||
job_id,
|
||||
true,
|
||||
&authed.username,
|
||||
)
|
||||
.await?;
|
||||
|
||||
tx.commit().await?;
|
||||
Ok(StatusCode::CREATED)
|
||||
}
|
||||
@@ -5234,6 +5247,7 @@ async fn resume_suspended(
|
||||
)
|
||||
.await?;
|
||||
|
||||
let (flow_id, flow_path) = (flow.id, flow.script_path.clone());
|
||||
if !approved {
|
||||
sqlx::query("UPDATE v2_job_queue SET suspend = 0 WHERE id = $1")
|
||||
.bind(&flow.id)
|
||||
@@ -5257,25 +5271,15 @@ async fn resume_suspended(
|
||||
}
|
||||
};
|
||||
|
||||
audit_log(
|
||||
&mut *tx,
|
||||
audit_suspend_resume(
|
||||
&mut tx,
|
||||
&audit_author,
|
||||
"jobs.suspend_resume",
|
||||
ActionKind::Update,
|
||||
&w_id,
|
||||
Some(
|
||||
&serde_json::json!({
|
||||
"approved": approved,
|
||||
"job_id": job_id,
|
||||
"details": if approved {
|
||||
format!("Approved by {}", &approver)
|
||||
} else {
|
||||
format!("Cancelled by {}", &approver)
|
||||
}
|
||||
})
|
||||
.to_string(),
|
||||
),
|
||||
None,
|
||||
flow_path.as_deref(),
|
||||
flow_id,
|
||||
resume_job_id,
|
||||
approved,
|
||||
&approver,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -5788,6 +5792,7 @@ async fn resume_suspended_job_internal(
|
||||
)
|
||||
.await?;
|
||||
|
||||
let (flow_id, flow_path) = (flow_info.id, flow_info.script_path.clone());
|
||||
if !approved {
|
||||
sqlx::query!(
|
||||
"UPDATE v2_job_queue SET suspend = 0 WHERE id = $1",
|
||||
@@ -5820,31 +5825,61 @@ async fn resume_suspended_job_internal(
|
||||
.map(|s| s[0..TOKEN_PREFIX_LEN].to_string()),
|
||||
},
|
||||
};
|
||||
audit_log(
|
||||
&mut *tx,
|
||||
audit_suspend_resume(
|
||||
&mut tx,
|
||||
&audit_author,
|
||||
"jobs.suspend_resume",
|
||||
ActionKind::Update,
|
||||
&w_id,
|
||||
Some(
|
||||
&serde_json::json!({
|
||||
"approved": approved,
|
||||
"job_id": job_id,
|
||||
"details": if approved {
|
||||
format!("Approved by {}", &approver)
|
||||
} else {
|
||||
format!("Cancelled by {}", &approver)
|
||||
}
|
||||
})
|
||||
.to_string(),
|
||||
),
|
||||
None,
|
||||
flow_path.as_deref(),
|
||||
flow_id,
|
||||
job_id,
|
||||
approved,
|
||||
&approver,
|
||||
)
|
||||
.await?;
|
||||
tx.commit().await?;
|
||||
Ok(StatusCode::CREATED)
|
||||
}
|
||||
|
||||
/// `job_id` is the flow the suspended step belongs to, whichever id the resume request named; the
|
||||
/// step itself is kept as `step_job_id`.
|
||||
async fn audit_suspend_resume(
|
||||
tx: &mut Transaction<'_, Postgres>,
|
||||
author: &AuditAuthor,
|
||||
w_id: &str,
|
||||
flow_path: Option<&str>,
|
||||
flow_id: Uuid,
|
||||
step_job_id: Uuid,
|
||||
approved: bool,
|
||||
approver: &str,
|
||||
) -> error::Result<()> {
|
||||
let flow_id_s = flow_id.to_string();
|
||||
let step_job_id_s = step_job_id.to_string();
|
||||
let details = if approved {
|
||||
format!("Approved by {approver}")
|
||||
} else {
|
||||
format!("Cancelled by {approver}")
|
||||
};
|
||||
let mut params = HashMap::from([
|
||||
("approved", if approved { "true" } else { "false" }),
|
||||
("job_id", flow_id_s.as_str()),
|
||||
("details", details.as_str()),
|
||||
]);
|
||||
if step_job_id != flow_id {
|
||||
params.insert("step_job_id", step_job_id_s.as_str());
|
||||
}
|
||||
audit_log(
|
||||
&mut **tx,
|
||||
author,
|
||||
"jobs.suspend_resume",
|
||||
ActionKind::Update,
|
||||
w_id,
|
||||
flow_path,
|
||||
Some(params),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn verify_suspended_secret(
|
||||
w_id: &String,
|
||||
db: &DB,
|
||||
@@ -9213,7 +9248,7 @@ async fn run_preview_script(
|
||||
tx,
|
||||
&w_id,
|
||||
match preview.kind {
|
||||
Some(PreviewKind::Identity) => JobPayload::Identity,
|
||||
Some(PreviewKind::Identity) => JobPayload::Identity { mocked: false, skipped: false },
|
||||
Some(PreviewKind::Noop) => JobPayload::Noop,
|
||||
_ => JobPayload::Code(RawCode {
|
||||
hash: preview
|
||||
|
||||
@@ -42,4 +42,6 @@ pub struct ListAuditLogQuery {
|
||||
// without paying a growing OFFSET on every batch.
|
||||
pub before_id: Option<i64>,
|
||||
pub all_workspaces: Option<bool>,
|
||||
// The entries about one run: started, viewed, cancelled, resumed, deleted...
|
||||
pub job_id: Option<sqlx::types::Uuid>,
|
||||
}
|
||||
|
||||
@@ -6719,6 +6719,10 @@ async fn push_inner<'c, 'd>(
|
||||
flow_timeout: Option<i32>,
|
||||
}
|
||||
let mut preprocessed = None;
|
||||
let (identity_mocked, identity_skipped) = match &job_payload {
|
||||
JobPayload::Identity { mocked, skipped } => (*mocked, *skipped),
|
||||
_ => (false, false),
|
||||
};
|
||||
#[allow(unused)]
|
||||
let JobPayloadUntagged {
|
||||
runnable_id,
|
||||
@@ -7498,7 +7502,7 @@ async fn push_inner<'c, 'd>(
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
JobPayload::Identity => {
|
||||
JobPayload::Identity { .. } => {
|
||||
JobPayloadUntagged { job_kind: JobKind::Identity, ..Default::default() }
|
||||
}
|
||||
JobPayload::Noop => JobPayloadUntagged { job_kind: JobKind::Noop, ..Default::default() },
|
||||
@@ -8067,6 +8071,21 @@ async fn push_inner<'c, 'd>(
|
||||
if let Some(client) = authed.and_then(|a| a.mcp_client.as_deref()) {
|
||||
hm.insert("mcp_client", client);
|
||||
}
|
||||
// A step's entry names its step: a no-code step has no runnable path to show as the
|
||||
// resource, and a script step's path does not say which step of which flow ran it.
|
||||
let parent_job_string = parent_job.map(|p| p.to_string());
|
||||
if let Some(step) = flow_step_id.as_deref() {
|
||||
hm.insert("step_id", step);
|
||||
}
|
||||
if let Some(p) = parent_job_string.as_deref() {
|
||||
hm.insert("parent_job", p);
|
||||
}
|
||||
if identity_mocked {
|
||||
hm.insert("mocked", "true");
|
||||
}
|
||||
if identity_skipped {
|
||||
hm.insert("skipped", "true");
|
||||
}
|
||||
|
||||
let s: String;
|
||||
let operation_name = match job_kind {
|
||||
|
||||
@@ -631,7 +631,12 @@ pub enum JobPayload {
|
||||
// instead of serializing through a single workspace-wide key.
|
||||
concurrency_key_append: Option<String>,
|
||||
},
|
||||
Identity,
|
||||
/// Passes its input through. Also stands in for a step that is mocked or skipped, which
|
||||
/// the audit entry records.
|
||||
Identity {
|
||||
mocked: bool,
|
||||
skipped: bool,
|
||||
},
|
||||
Noop,
|
||||
AIAgent {
|
||||
path: String,
|
||||
@@ -690,7 +695,7 @@ impl JobPayload {
|
||||
pub fn job_kind(&self) -> JobKind {
|
||||
match self {
|
||||
JobPayload::Noop => JobKind::Noop,
|
||||
JobPayload::Identity => JobKind::Identity,
|
||||
JobPayload::Identity { .. } => JobKind::Identity,
|
||||
JobPayload::Code { .. } => JobKind::Preview,
|
||||
JobPayload::AIAgent { .. } => JobKind::AIAgent,
|
||||
JobPayload::FlowNode { .. } => JobKind::FlowNode,
|
||||
|
||||
@@ -4045,16 +4045,23 @@ async fn push_next_flow_job(
|
||||
|
||||
resume_messages.push(to_raw_value(&js));
|
||||
audit_log(
|
||||
&mut *tx,
|
||||
&audit_author,
|
||||
"jobs.suspend_resume",
|
||||
ActionKind::Update,
|
||||
&flow_job.workspace_id,
|
||||
Some(&serde_json::json!({"approved": false, "job_id": flow_job.id, "details": "Suspend timed out without approval but can continue".to_string()}).to_string()),
|
||||
None,
|
||||
)
|
||||
.warn_after_seconds(3)
|
||||
.await?;
|
||||
&mut *tx,
|
||||
&audit_author,
|
||||
"jobs.suspend_resume",
|
||||
ActionKind::Update,
|
||||
&flow_job.workspace_id,
|
||||
flow_job.runnable_path.as_deref(),
|
||||
Some(HashMap::from([
|
||||
("approved", "false"),
|
||||
("job_id", flow_job.id.to_string().as_str()),
|
||||
(
|
||||
"details",
|
||||
"Suspend timed out without approval but can continue",
|
||||
),
|
||||
])),
|
||||
)
|
||||
.warn_after_seconds(3)
|
||||
.await?;
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
@@ -4139,16 +4146,23 @@ async fn push_next_flow_job(
|
||||
} else {
|
||||
if is_disapproved.is_none() {
|
||||
audit_log(
|
||||
&mut *tx,
|
||||
&audit_author,
|
||||
"jobs.suspend_resume",
|
||||
ActionKind::Update,
|
||||
&flow_job.workspace_id,
|
||||
Some(&serde_json::json!({"approved": false, "job_id": flow_job.id, "details": "Suspend timed out without approval and is cancelled".to_string()}).to_string()),
|
||||
None,
|
||||
)
|
||||
.warn_after_seconds(3)
|
||||
.await?;
|
||||
&mut *tx,
|
||||
&audit_author,
|
||||
"jobs.suspend_resume",
|
||||
ActionKind::Update,
|
||||
&flow_job.workspace_id,
|
||||
flow_job.runnable_path.as_deref(),
|
||||
Some(HashMap::from([
|
||||
("approved", "false"),
|
||||
("job_id", flow_job.id.to_string().as_str()),
|
||||
(
|
||||
"details",
|
||||
"Suspend timed out without approval and is cancelled",
|
||||
),
|
||||
])),
|
||||
)
|
||||
.warn_after_seconds(3)
|
||||
.await?;
|
||||
}
|
||||
tx.commit().warn_after_seconds(3).await?;
|
||||
|
||||
@@ -5749,7 +5763,7 @@ async fn compute_next_flow_transform(
|
||||
if module.mock.is_some() && module.mock.as_ref().unwrap().enabled {
|
||||
return Ok(NextFlowTransform::Continue(
|
||||
ContinuePayload::SingleJob(JobPayloadWithTag {
|
||||
payload: JobPayload::Identity,
|
||||
payload: JobPayload::Identity { mocked: true, skipped: false },
|
||||
tag: None,
|
||||
delete_after_use: false,
|
||||
delete_after_secs: None,
|
||||
@@ -5777,11 +5791,13 @@ async fn compute_next_flow_transform(
|
||||
|
||||
tracing::debug!(id = %flow_job.id, "computing next flow transform for {:?}", &module.value);
|
||||
if is_skipped {
|
||||
return trivial_next_job(JobPayload::Identity);
|
||||
return trivial_next_job(JobPayload::Identity { mocked: false, skipped: true });
|
||||
}
|
||||
|
||||
match module.get_value()? {
|
||||
FlowModuleValue::Identity => trivial_next_job(JobPayload::Identity),
|
||||
FlowModuleValue::Identity => {
|
||||
trivial_next_job(JobPayload::Identity { mocked: false, skipped: false })
|
||||
}
|
||||
FlowModuleValue::Flow { path, .. } => {
|
||||
let mut payload = flow_to_payload(
|
||||
path,
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
import { type AuditLog } from '$lib/gen'
|
||||
import { displayDate } from '$lib/utils'
|
||||
import { ExternalLink, X } from 'lucide-svelte'
|
||||
import { Highlight } from 'svelte-highlight'
|
||||
import { json } from 'svelte-highlight/languages'
|
||||
import HighlightTheme from '$lib/components/HighlightTheme.svelte'
|
||||
|
||||
interface Props {
|
||||
logs: AuditLog[]
|
||||
@@ -21,6 +24,8 @@
|
||||
const ViewAppOp: AuditLog['operation'][] = ['apps.create', 'apps.update']
|
||||
</script>
|
||||
|
||||
<HighlightTheme />
|
||||
|
||||
<div class="flex flex-col items-start">
|
||||
{#if selectedId}
|
||||
{@const log = logs.find((e) => e.id === selectedId)}
|
||||
@@ -59,8 +64,8 @@
|
||||
{/if}
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="font-semibold text-xs text-emphasis">Parameters</span>
|
||||
<div class="text-xs p-2 bg-surface-secondary rounded-md">
|
||||
{JSON.stringify(log.parameters, null, 2)}
|
||||
<div class="text-xs p-2 bg-surface-secondary rounded-md overflow-x-auto">
|
||||
<Highlight language={json} code={JSON.stringify(log.parameters, null, 2)} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
import { usePromise } from '$lib/svelte5Utils.svelte'
|
||||
import { safeSelectItems } from '../select/utils.svelte'
|
||||
import { sendUserToast } from '$lib/toast'
|
||||
import TextInput from '../text_input/TextInput.svelte'
|
||||
import { isUuid } from '$lib/utils/uuid'
|
||||
|
||||
let usernames: string[] | undefined = $state()
|
||||
let resources = usePromise(() => loadResources($workspaceStore!), { loadInit: false })
|
||||
@@ -52,6 +54,8 @@
|
||||
perPage?: number | undefined
|
||||
operation?: string
|
||||
resource?: string | undefined
|
||||
/** Only the entries about this run. */
|
||||
jobId?: string | undefined
|
||||
actionKind?: ActionKind | 'all'
|
||||
scope?: undefined | 'all_workspaces' | 'instance'
|
||||
loading?: boolean
|
||||
@@ -68,6 +72,7 @@
|
||||
perPage = $bindable(100),
|
||||
operation = $bindable(),
|
||||
resource = $bindable() as string | undefined,
|
||||
jobId = $bindable(),
|
||||
actionKind = $bindable(undefined),
|
||||
scope = $bindable(undefined),
|
||||
loading = false,
|
||||
@@ -109,6 +114,7 @@
|
||||
addQueryParam('after', after)
|
||||
addQueryParam('operation', operation)
|
||||
addQueryParam('resource', resource)
|
||||
addQueryParam('job_id', jobId?.trim())
|
||||
addQueryParam('actionKind', actionKind)
|
||||
if (scope && $workspaceStore == 'admins') {
|
||||
addQueryParam('scope', scope)
|
||||
@@ -128,6 +134,7 @@
|
||||
perPage = Number(urlSearchParams.get('perPage')) || 100
|
||||
operation = urlSearchParams.get('operation') ?? 'all'
|
||||
resource = urlSearchParams.get('resource') ?? undefined
|
||||
jobId = urlSearchParams.get('job_id') ?? undefined
|
||||
|
||||
actionKind = (urlSearchParams.get('actionKind') as ActionKind) ?? 'all'
|
||||
}
|
||||
@@ -265,7 +272,7 @@
|
||||
|
||||
// observe all the variables that should be reflected in the url
|
||||
$effect(() => {
|
||||
;[username, perPage, before, after, operation, resource, actionKind, scope]
|
||||
;[username, perPage, before, after, operation, resource, jobId, actionKind, scope]
|
||||
untrack(() => updateQueryParams())
|
||||
})
|
||||
|
||||
@@ -374,6 +381,15 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="w-40 min-w-0 shrink">
|
||||
<TextInput
|
||||
size="sm"
|
||||
bind:value={jobId}
|
||||
error={!!jobId?.trim() && !isUuid(jobId)}
|
||||
inputProps={{ placeholder: 'all runs', title: 'Only the entries about this run ID' }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="w-40 min-w-0 shrink">
|
||||
<Select
|
||||
class="w-full"
|
||||
@@ -415,6 +431,7 @@
|
||||
actionKind = 'all'
|
||||
perPage = 100
|
||||
resource = 'all'
|
||||
jobId = undefined
|
||||
scope = undefined
|
||||
}}
|
||||
unifiedSize="sm"
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface AuditLogsLoaderArgs {
|
||||
username: string
|
||||
operation: string
|
||||
resource: string | undefined
|
||||
jobId: string | undefined
|
||||
actionKind: ActionKind | 'all'
|
||||
before: string | undefined
|
||||
after: string | undefined
|
||||
@@ -56,6 +57,7 @@ export function useAuditLogsLoader(args: () => AuditLogsLoaderArgs) {
|
||||
operation: a.operation === 'all' || a.operation === '' ? undefined : a.operation,
|
||||
resource: a.resource === 'all' || a.resource === '' ? undefined : a.resource,
|
||||
actionKind: a.actionKind === 'all' ? undefined : a.actionKind,
|
||||
jobId: a.jobId || undefined,
|
||||
allWorkspaces: a.scope === 'all_workspaces'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -42,7 +42,8 @@
|
||||
Users,
|
||||
Play,
|
||||
SearchX,
|
||||
ArrowRight
|
||||
ArrowRight,
|
||||
Eye
|
||||
} from 'lucide-svelte'
|
||||
import WorkspaceIcon from '$lib/components/workspace/WorkspaceIcon.svelte'
|
||||
import { forLater } from '$lib/forLater'
|
||||
@@ -57,7 +58,13 @@
|
||||
import DbtRunGraph from '$lib/components/dbt/DbtRunGraph.svelte'
|
||||
import DispatchEventsPanel from '$lib/components/runs/DispatchEventsPanel.svelte'
|
||||
import UpstreamSnapshotsPanel from '$lib/components/runs/UpstreamSnapshotsPanel.svelte'
|
||||
import { enterpriseLicense, initialArgsStore, superadmin, userWorkspaces } from '$lib/stores'
|
||||
import {
|
||||
enterpriseLicense,
|
||||
initialArgsStore,
|
||||
roleCapabilities,
|
||||
superadmin,
|
||||
userWorkspaces
|
||||
} from '$lib/stores'
|
||||
import FlowStatusViewer from '$lib/components/FlowStatusViewer.svelte'
|
||||
import HighlightCode from '$lib/components/HighlightCode.svelte'
|
||||
import JobLoader from '$lib/components/JobLoader.svelte'
|
||||
@@ -816,6 +823,36 @@
|
||||
if (!forceCancel) setTimeout(() => (forceCancel = true), 3001)
|
||||
}
|
||||
|
||||
// The run's life and a day after it: the audit filter on a run id has no index, so its cost
|
||||
// grows with the time range it covers. Later entries are a widened range away on that page.
|
||||
const auditLogsHref = $derived.by(() => {
|
||||
if (!job) return undefined
|
||||
const params = new URLSearchParams({ job_id: job.id })
|
||||
if (job.created_at) {
|
||||
params.set('after', new Date(new Date(job.created_at).getTime() - 1000).toISOString())
|
||||
}
|
||||
if (job.type === 'CompletedJob') {
|
||||
const end = job.completed_at
|
||||
? new Date(job.completed_at).getTime()
|
||||
: new Date(job.started_at).getTime() + job.duration_ms
|
||||
params.set('before', new Date(end + 24 * 3600 * 1000).toISOString())
|
||||
}
|
||||
return `/audit_logs?${params}`
|
||||
})
|
||||
const moreItems = $derived<Item[]>([
|
||||
{
|
||||
displayName: 'Audit logs',
|
||||
icon: Eye,
|
||||
href: auditLogsHref,
|
||||
hide: !job || !$roleCapabilities.visibility.audit_logs
|
||||
},
|
||||
{
|
||||
displayName: 'Show flow debug info',
|
||||
icon: EllipsisVertical,
|
||||
action: debugInfo,
|
||||
hide: !canDebug
|
||||
}
|
||||
])
|
||||
// The same actions as the row, most used first; the restart and session controls stay beside
|
||||
// the menu, since each opens a popover of its own that a menu row cannot hold.
|
||||
const menuItems = $derived.by((): Item[] => {
|
||||
@@ -882,6 +919,12 @@
|
||||
href: runsHref,
|
||||
hide: !canDelete || !(job.job_kind === 'script' || job.job_kind === 'flow')
|
||||
},
|
||||
{
|
||||
displayName: 'Audit logs',
|
||||
icon: Eye,
|
||||
href: auditLogsHref,
|
||||
hide: !$roleCapabilities.visibility.audit_logs
|
||||
},
|
||||
{
|
||||
displayName: 'Copy link for members',
|
||||
icon: Users,
|
||||
@@ -1122,6 +1165,9 @@
|
||||
{/snippet}
|
||||
|
||||
{#snippet runActionsRow()}
|
||||
{#if moreItems.some((i) => !i.hide)}
|
||||
<Dropdown items={moreItems} size="sm" />
|
||||
{/if}
|
||||
{#if canDelete}
|
||||
<Dropdown
|
||||
items={[
|
||||
@@ -1185,29 +1231,6 @@
|
||||
{/snippet}
|
||||
</Dropdown>
|
||||
{/if}
|
||||
{#if (job?.job_kind == 'flow' || isFlowPreview(job?.job_kind)) && job?.['running'] && job?.parent_job == undefined}
|
||||
<div class="inline">
|
||||
<Dropdown
|
||||
items={[
|
||||
{
|
||||
displayName: 'Show Flow Debug Info',
|
||||
action: () => {
|
||||
debugInfo()
|
||||
}
|
||||
}
|
||||
]}
|
||||
class="h-auto"
|
||||
>
|
||||
{#snippet buttonReplacement()}
|
||||
<Button nonCaptureEvent unifiedSize="sm" variant="subtle">
|
||||
<div class="flex flex-row items-center">
|
||||
<EllipsisVertical size={14} />
|
||||
</div>
|
||||
</Button>
|
||||
{/snippet}
|
||||
</Dropdown>
|
||||
</div>
|
||||
{/if}
|
||||
{#if isFlowPreview(job?.job_kind) || isScriptPreview(job?.job_kind)}
|
||||
<Button
|
||||
unifiedSize="sm"
|
||||
|
||||
@@ -15,3 +15,7 @@ export function randomSecret(bytes = 32): string {
|
||||
crypto.getRandomValues(buf)
|
||||
return Array.from(buf, (b) => b.toString(16).padStart(2, '0')).join('')
|
||||
}
|
||||
|
||||
export function isUuid(s: string | undefined): s is string {
|
||||
return !!s && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(s.trim())
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import { Splitpanes, Pane } from 'svelte-splitpanes'
|
||||
import AuditLogsTimeline from '$lib/components/auditLogs/AuditLogsTimeline.svelte'
|
||||
import { useAuditLogsLoader } from '$lib/components/auditLogs/useAuditLogsLoader.svelte'
|
||||
import { isUuid } from '$lib/utils/uuid'
|
||||
|
||||
let username: string = $state(page.url.searchParams.get('username') ?? 'all')
|
||||
let before: string | undefined = $state(page.url.searchParams.get('before') ?? undefined)
|
||||
@@ -26,6 +27,7 @@
|
||||
let perPage: number | undefined = $state(Number(page.url.searchParams.get('perPage')) || 100)
|
||||
let operation: string = $state(page.url.searchParams.get('operation') ?? 'all')
|
||||
let resource: string | undefined = $state(page.url.searchParams.get('resource') ?? undefined)
|
||||
let jobId: string | undefined = $state(page.url.searchParams.get('job_id') ?? undefined)
|
||||
let scope: undefined | 'all_workspaces' | 'instance' = $state(
|
||||
(page.url.searchParams.get('scope') ?? undefined) as undefined | 'all_workspaces' | 'instance'
|
||||
)
|
||||
@@ -40,6 +42,7 @@
|
||||
username,
|
||||
operation,
|
||||
resource,
|
||||
jobId: isUuid(jobId) ? jobId.trim() : undefined,
|
||||
actionKind,
|
||||
before,
|
||||
after,
|
||||
@@ -165,6 +168,7 @@
|
||||
bind:actionKind
|
||||
bind:operation
|
||||
bind:resource
|
||||
bind:jobId
|
||||
bind:perPage
|
||||
bind:scope
|
||||
loading={auditLogsLoader.loading}
|
||||
@@ -182,6 +186,7 @@
|
||||
bind:actionKind
|
||||
bind:operation
|
||||
bind:resource
|
||||
bind:jobId
|
||||
bind:scope
|
||||
loading={auditLogsLoader.loading}
|
||||
onRefresh={() => auditLogsLoader.reload()}
|
||||
|
||||
Reference in New Issue
Block a user