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
2 changes: 1 addition & 1 deletion .github/workflows/ci-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
name: 漏洞扫描 (govulncheck)
runs-on: ubuntu-latest
# 存量可达漏洞已清零: 升级 grpc / x/text / excelize / quic-go / etcd 等依赖并将 go 版本钉到
# 1.25.12(修复 crypto/tls ECH 漏洞 GO-2026-5856)后, govulncheck 对"可达"漏洞报告为空。
# 1.25.13(覆盖 crypto/tls 等 stdlib 补丁 + etcd server ≥3.5.33)后, govulncheck 对"可达"漏洞报告为空。
# govulncheck 只报告调用链真正触及的漏洞, 误报极低; 故转为硬门禁,
# 与本仓库 golangci-lint / ruff / mypy / safety / bandit 的"存量先反馈、清零后转门禁"一致。
steps:
Expand Down
2 changes: 2 additions & 0 deletions apps/cognida-web/src/api/audit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface AuditLog {
RequestID: string | null
DurationMs: number | null
CreatedAt: string
/** 该 request_id 在 trace_spans 是否有调用链,无则前端不展示跳转按钮 */
HasTrace?: boolean
}

export interface AuditLogPage {
Expand Down
21 changes: 18 additions & 3 deletions apps/cognida-web/src/api/datasource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,17 @@ export interface TestDatasourceResult {
message?: string
}

/** 表清单条目(与后端 TableInfo 对齐) */
export interface DatasourceTableInfo {
name: string
comment?: string
/** information_schema 估算行数 */
rows?: number
}

/** 表列表响应 */
export interface DatasourceTablesResponse {
tables: string[]
tables: DatasourceTableInfo[]
}

/** 表结构详情(列信息等,后端可按需扩展) */
Expand All @@ -119,9 +127,16 @@ export interface DatasourceTableDetail {

export const datasourceApi = {
/**
* 分页获取数据源列表
* 分页获取数据源列表。
* 可选筛选:name(名称模糊)、type(mysql|postgres)、database(库名模糊)。
*/
list(params?: { page?: number; page_size?: number }) {
list(params?: {
page?: number
page_size?: number
name?: string
type?: DatasourceType | ''
database?: string
}) {
return http.get<DatasourceListResponse>('/datasources', { params })
},

Expand Down
17 changes: 13 additions & 4 deletions apps/cognida-web/src/api/evaluation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@
},

/**
* 列出测评任务
*/
list(params?: { page?: number; page_size?: number }) {
* 列出测评任务。
* 可选筛选:status(running/failed…)、task_id、dataset_id、dataset_name、type。
*/
list(params?: {
page?: number
page_size?: number
status?: string
type?: string
task_id?: string
dataset_id?: string
dataset_name?: string
}) {
return http.get<DatasetListResponse>('/evaluation/tasks', { params })
},

Expand Down Expand Up @@ -89,7 +98,7 @@
/**
* 列出数据集
*/
listDatasets(params?: { type?: string }) {
listDatasets(params?: { type?: string; name?: string; id?: string }) {
return http.get<{ datasets: DatasetInfo[] }>('/evaluation/datasets', { params })
},

Expand Down Expand Up @@ -146,6 +155,6 @@
* 预览数据集样本(文件系统数据集)
*/
previewDataset(id: string, limit: number = 5) {
return http.get<{ qapairs: any[] }>(`/evaluation/datasets/${id}/preview?limit=${limit}`)

Check warning on line 158 in apps/cognida-web/src/api/evaluation/index.ts

View workflow job for this annotation

GitHub Actions / 检查与测试

Unexpected any. Specify a different type
}
}
9 changes: 7 additions & 2 deletions apps/cognida-web/src/components/ui/UiTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
<div v-if="showPagination && pagination" class="ui-table__pagination">
<slot name="pagination">
<UiPagination
v-model:page="pagination.page"
v-model:page-size="pagination.pageSize"
:page="pagination.page"
:page-size="pagination.pageSize"
:total="pagination.total"
@change="handlePageChange"
/>
Expand Down Expand Up @@ -202,6 +202,11 @@ function formatCellValue(row: any, column: Column) {
}

function handleRowClick(row: any, index: number) {
// 拖选/长按选中文字时,mouseup 也会触发 click;有选区则不当作行点击,避免误开详情。
const sel = window.getSelection()
if (sel && !sel.isCollapsed && sel.toString().trim()) {
return
}
emit('row-click', row, index)
}

Expand Down
4 changes: 4 additions & 0 deletions apps/cognida-web/src/types/evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export interface EvaluationTask {
id?: string
task_id: string
dataset_id: string
/** 数据集显示名称(列表接口按 dataset_id 解析) */
dataset_name?: string
type: string
status: EvaluationStatus
total_count: number
Expand All @@ -139,6 +141,8 @@ export interface EvaluationTaskDetail extends EvaluationTask {
export interface EvaluationDetail {
task_id: string
dataset_id: string
/** 数据集显示名称(后端按 dataset_id 解析,缺失时可能为空) */
dataset_name?: string
type: string
status: EvaluationStatus
qa_results: any[]
Expand Down
3 changes: 2 additions & 1 deletion apps/cognida-web/src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ service.interceptors.response.use(

// 处理404错误
if (error.response?.status === 404) {
ElMessage.error('请求的资源不存在')
const payload = error.response.data as { message?: string } | undefined
ElMessage.error(payload?.message || '请求的资源不存在')
return Promise.reject(error)
}

Expand Down
146 changes: 113 additions & 33 deletions apps/cognida-web/src/views/audit/AuditLogList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@
{{ formatTime(row.CreatedAt) }}
</template>
<template #cell-RequestID="{ row }">
<router-link
v-if="row.RequestID"
class="mono trace-link"
:to="{ path: '/traces', query: { request_id: row.RequestID } }"
title="查看该请求的调用链"
@click.stop
>
{{ row.RequestID }}
</router-link>
<span v-else class="mono">-</span>
<span class="req-id-cell">
<span class="mono">{{ row.RequestID || '-' }}</span>
<UiButton
v-if="row.HasTrace && row.RequestID"
size="sm"
variant="secondary"
@click.stop="openTrace(row.RequestID)"
>
追踪
</UiButton>
</span>
</template>
<template #cell-Status="{ row }">
<UiTag size="sm" :variant="row.Status === 'success' ? 'success' : 'danger'">
Expand Down Expand Up @@ -127,58 +128,92 @@
<UiDrawer v-model="showDetail" title="审计详情" :size="520">
<div v-if="current" class="detail">
<UiDescriptions :column="1" border>
<UiDescriptionsItem label="ID">{{ current.ID }}</UiDescriptionsItem>
<UiDescriptionsItem label="时间">{{ formatTime(current.CreatedAt) }}</UiDescriptionsItem>
<UiDescriptionsItem label="ID">
<span class="copyable" title="点击复制" @click="copyField(String(current.ID))">{{ current.ID }}</span>
</UiDescriptionsItem>
<UiDescriptionsItem label="时间">
<span class="copyable" title="点击复制" @click="copyField(formatTime(current.CreatedAt))">{{ formatTime(current.CreatedAt) }}</span>
</UiDescriptionsItem>
<UiDescriptionsItem label="Request ID">
<router-link
v-if="current.RequestID"
class="mono trace-link"
:to="{ path: '/traces', query: { request_id: current.RequestID } }"
>
{{ current.RequestID }}
</router-link>
<span v-else class="mono">-</span>
<span
class="mono copyable"
title="点击复制"
@click="copyField(current.RequestID || '')"
>{{ current.RequestID || '-' }}</span>
</UiDescriptionsItem>
<UiDescriptionsItem label="状态">
<UiTag size="sm" :variant="current.Status === 'success' ? 'success' : 'danger'">
{{ current.Status === 'success' ? '成功' : '失败' }}
</UiTag>
</UiDescriptionsItem>
<UiDescriptionsItem label="模块">{{ current.Module || '-' }}</UiDescriptionsItem>
<UiDescriptionsItem label="模块">
<span class="copyable" title="点击复制" @click="copyField(current.Module || '')">{{ current.Module || '-' }}</span>
</UiDescriptionsItem>
<UiDescriptionsItem label="操作">
<span class="mono">{{ current.Action || '-' }}</span>
<span
class="mono copyable"
title="点击复制"
@click="copyField(current.Action || '')"
>{{ current.Action || '-' }}</span>
</UiDescriptionsItem>
<UiDescriptionsItem label="资源类型">
<span class="copyable" title="点击复制" @click="copyField(current.ResourceType || '')">{{ current.ResourceType || '-' }}</span>
</UiDescriptionsItem>
<UiDescriptionsItem label="资源类型">{{ current.ResourceType || '-' }}</UiDescriptionsItem>
<UiDescriptionsItem label="资源">
{{ current.ResourceName || current.ResourceID || '-' }}
<span
class="copyable"
title="点击复制"
@click="copyField(current.ResourceName || current.ResourceID || '')"
>{{ current.ResourceName || current.ResourceID || '-' }}</span>
</UiDescriptionsItem>
<UiDescriptionsItem label="耗时">
{{ current.DurationMs != null ? `${current.DurationMs} ms` : '-' }}
</UiDescriptionsItem>
<UiDescriptionsItem label="用户 ID">{{ current.UserID ?? '-' }}</UiDescriptionsItem>
<UiDescriptionsItem label="用户 ID">
<span
class="copyable"
title="点击复制"
@click="copyField(current.UserID != null ? String(current.UserID) : '')"
>{{ current.UserID ?? '-' }}</span>
</UiDescriptionsItem>
<UiDescriptionsItem label="来源 IP">
<span class="mono">{{ current.IPAddress || '-' }}</span>
<span
class="mono copyable"
title="点击复制"
@click="copyField(current.IPAddress || '')"
>{{ current.IPAddress || '-' }}</span>
</UiDescriptionsItem>
</UiDescriptions>

<div v-if="current.ErrorMessage" class="detail-block">
<h4>错误信息</h4>
<pre class="error-msg">{{ current.ErrorMessage }}</pre>
<h4>错误信息 <span class="copy-hint">点击下方复制</span></h4>
<pre class="error-msg copyable" title="点击复制" @click="copyField(current.ErrorMessage)">{{ current.ErrorMessage }}</pre>
</div>

<div class="detail-block">
<h4>请求详情</h4>
<pre class="details-json">{{ prettyDetails }}</pre>
<h4>请求详情 <span class="copy-hint">点击下方复制</span></h4>
<pre class="details-json copyable" title="点击复制" @click="copyField(prettyDetails)">{{ prettyDetails }}</pre>
</div>

<div v-if="current.RequestID" class="detail-block">
<h4>关联原始日志</h4>
<h4>关联原始日志 <span class="copy-hint">点击下方复制</span></h4>
<p class="hint">在 Grafana Explore(Loki 数据源)中用如下 LogQL 检索该请求在各服务的原始日志:</p>
<pre class="logql">{{ `{job="link"} |= "${current.RequestID}"` }}</pre>
<pre
class="logql copyable"
title="点击复制"
@click="copyField(logqlQuery)"
>{{ logqlQuery }}</pre>
</div>
</div>

<template #footer>
<UiButton
v-if="current?.HasTrace && current.RequestID"
variant="primary"
@click="openTrace(current.RequestID)"
>
查看追踪
</UiButton>
<UiButton variant="secondary" @click="showDetail = false">关闭</UiButton>
</template>
</UiDrawer>
Expand All @@ -187,6 +222,7 @@

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { Refresh } from '@element-plus/icons-vue'
import {
UiButton,
Expand All @@ -201,11 +237,14 @@ import {
UiStatistic
} from '@/components'
import toast from '@/utils/toast'
import { copyToClipboard } from '@/utils/security'
import { auditApi, type AuditLog, type AuditStats } from '@/api/audit'

const router = useRouter()

const columns = [
{ key: 'CreatedAt', title: '时间', width: 170 },
{ key: 'RequestID', title: 'Request ID', width: 180 },
{ key: 'RequestID', title: 'Request ID', width: 280 },
{ key: 'Module', title: '模块', width: 120 },
{ key: 'Action', title: '操作' },
{ key: 'Status', title: '状态', width: 90 },
Expand Down Expand Up @@ -244,6 +283,20 @@ const prettyDetails = computed(() => {
}
})

const logqlQuery = computed(() => {
const rid = current.value?.RequestID
if (!rid) return ''
return `{job="link"} |= "${rid}"`
})

async function copyField(text: string) {
const value = (text || '').trim()
if (!value || value === '-') return
const ok = await copyToClipboard(value)
if (ok) toast.success('已复制')
else toast.error('复制失败')
}

function formatTime(iso: string): string {
if (!iso) return '-'
const d = new Date(iso)
Expand Down Expand Up @@ -319,6 +372,10 @@ function viewDetail(row: AuditLog) {
showDetail.value = true
}

function openTrace(requestId: string) {
router.push({ path: '/traces', query: { request_id: requestId } })
}

onMounted(() => {
loadStats()
loadLogs()
Expand Down Expand Up @@ -375,6 +432,29 @@ onMounted(() => {
font-size: 12px;
}

.copyable {
cursor: pointer;
border-radius: 3px;
transition: background 0.15s ease;
}

.copyable:hover {
background: color-mix(in srgb, var(--primary, #4f8cff) 12%, transparent);
}

.copy-hint {
margin-left: 8px;
font-size: 12px;
font-weight: 400;
color: var(--text-muted);
}

.req-id-cell {
display: flex;
align-items: center;
gap: 8px;
}

.trace-link {
color: var(--primary, #4f8cff);
text-decoration: none;
Expand Down
Loading
Loading