Skip to content

引入

ts
import {
  GalileoTagSearch,
  GalileoMessageSearch,
  QueryGalileoLogRsp,
  QueryGalileoLogOptions,
  GALILEO_LOG_QUERY_URL,
  queryGalileoLog,
  queryGalileoLogAll,
  GalileoNamespace
} from 't-comm';

// 不支持 tree-shaking 的项目
import {
  GalileoTagSearch,
  GalileoMessageSearch,
  QueryGalileoLogRsp,
  QueryGalileoLogOptions,
  GALILEO_LOG_QUERY_URL,
  queryGalileoLog,
  queryGalileoLogAll,
  GalileoNamespace
} from 't-comm/lib/galileo-api/index';

// 只支持 ESM 的项目
import {
  GalileoTagSearch,
  GalileoMessageSearch,
  QueryGalileoLogRsp,
  QueryGalileoLogOptions,
  GALILEO_LOG_QUERY_URL,
  queryGalileoLog,
  queryGalileoLogAll,
  GalileoNamespace
} from 't-comm/es/galileo-api/index';

GalileoTagSearch

描述:tag 条件搜索,对应 proto TagSearch

参数

GalileoMessageSearch

描述:message 关键字搜索,对应 proto MessageSearch

参数

QueryGalileoLogRsp

描述:查询日志响应,对应 proto QueryLogRsp

参数

queryGalileoLogRsp.code : number

0 为成功,其他为错误

Kind: instance property of QueryGalileoLogRsp

queryGalileoLogRsp.total : number

当前实际查询所得条数

Kind: instance property of QueryGalileoLogRsp

queryGalileoLogRsp.cursor : string

游标翻页查询

Kind: instance property of QueryGalileoLogRsp

queryGalileoLogRsp.has_next_page : boolean

是否有下一页

Kind: instance property of QueryGalileoLogRsp

QueryGalileoLogOptions

描述:查询日志接口的额外配置

参数

queryGalileoLogOptions.auth : GalileoAuth

蓝鲸 APIGW 鉴权

Kind: instance property of QueryGalileoLogOptions

queryGalileoLogOptions.url : string

自定义请求地址,默认 https://galileo-api.apigw.o.woa.com/prod/log/query

Kind: instance property of QueryGalileoLogOptions
Optional:

queryGalileoLogOptions.timeout : number

请求超时(毫秒),默认 15000

Kind: instance property of QueryGalileoLogOptions
Optional:

GALILEO_LOG_QUERY_URL

描述:伽利略日志查询网关地址(蓝鲸 APIGW)

参数

queryGalileoLog()

描述:查询伽利略日志(调用蓝鲸网关 /prod/log/query) 参考文档:https://iwiki.woa.com/p/4007673553 调用前需要在「伽利略 API 权限申请表」中申请 bk_app_code/bk_app_secret,以及对应 target 的查询权限。

参数

示例

ts
import { queryGalileoLog, GalileoLogSortType } from 't-comm/lib/galileo-api';

const now = Date.now();
const res = await queryGalileoLog(
  {
    target: 'PCG-123.galileo.apiserver',
    namespace: 'Production',
    start: now - 30 * 60 * 1000,
    end: now,
    limit: 100,
    query: 'message:target and level:error',
    sort_type: GalileoLogSortType.ASC,
  },
  {
    auth: {
      bk_app_code: 'tip-tool',
      bk_app_secret: 'xxx',
    },
  },
);
console.log(res.logs, res.has_next_page, res.cursor);

queryGalileoLogAll(req, options, extra)

描述:通过游标不断翻页,直到满足 limit 条数或 has_next_page=false。 伽利略后端分片查询时,稀疏数据可能单次只返回少量条目,需要借助 cursor 继续翻页。 该方法会自动循环翻页直到累计条数 >= req.limit 或没有下一页。

参数

参数名描述
req查询参数,limit 为期望累计的总条数
options鉴权及请求配置
extra可选项:最大翻页次数、每页大小

示例

ts
const res = await queryGalileoLogAll(
  {
    target: 'PCG-123.galileo.apiserver',
    namespace: 'Production',
    start: Date.now() - 3600 * 1000,
    end: Date.now(),
    limit: 500,
    query: 'level:error',
  },
  { auth: { bk_app_code: 'xxx', bk_app_secret: 'xxx' } },
);

GalileoNamespace

描述:命名空间,伽利略协议枚举

参数