Skip to content

Commit

Permalink
update prettier width
Browse files Browse the repository at this point in the history
  • Loading branch information
adaex committed Oct 2, 2021
1 parent 38afd5c commit f85c7d4
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off"
}
}
}
1 change: 0 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"printWidth": 160,
"semi": false,
"singleQuote": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build": "rm -rf dist && tsc && cp package.json *.md dist && rm -rf dist/test",
"test": "node dist/test",
"lint": "eslint .",
"prettier": "prettier -w .",
"format": "prettier -w .",
"sync": "curl -X PUT 'https://npm.taobao.org/sync/coa-ali-sls?sync_upstream=true'"
},
"dependencies": {
Expand Down
20 changes: 16 additions & 4 deletions src/lib/AliSlsBin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export class AliSlsBin {
const headers = this.getHeaders('GET', path)
const baseURL = `https://${this.config.project}.${this.config.endpoint}`

const result = await axios.get(url, { params, headers, baseURL }).catch(this.resultError)
const result = await axios
.get(url, { params, headers, baseURL })
.catch(this.resultError)

return this.resultResponse(result)
}
Expand Down Expand Up @@ -44,15 +46,21 @@ export class AliSlsBin {
return { body, info }
}

private getSortQueryString(params: AliSls.Dic<string | number | boolean | undefined>) {
private getSortQueryString(
params: AliSls.Dic<string | number | boolean | undefined>
) {
const list = [] as string[]
_.forEach(params, (v, k) => {
list.push(k + '=' + v)
})
return list.sort().join('&')
}

private getHeaders(method: string, path: string, headers: AliSls.Dic<string> = {}) {
private getHeaders(
method: string,
path: string,
headers: AliSls.Dic<string> = {}
) {
_.defaults(headers, {
'x-log-bodyrawsize': '0',
'x-log-apiversion': '0.6.0',
Expand Down Expand Up @@ -82,7 +90,11 @@ export class AliSlsBin {
signs.push(...x_list.sort())
signs.push(path)

const signature = secure.sha1_hmac(signs.join('\n'), this.config.accessKeySecret, 'base64')
const signature = secure.sha1_hmac(
signs.join('\n'),
this.config.accessKeySecret,
'base64'
)

return `LOG ${this.config.accessKeyId}:${signature}`
}
Expand Down
25 changes: 21 additions & 4 deletions src/lib/AliSlsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,17 @@ export class AliSlsQuery {
* @param field 列名
* @param alias 输出别名
*/
timeSeries(field: string, alias: string, grainSize: string, format = '%Y-%m-%d %H:%i', padding = 0) {
return this.column(`time_series(${field}, '${grainSize}', '${format}', '${padding}')`, alias)
timeSeries(
field: string,
alias: string,
grainSize: string,
format = '%Y-%m-%d %H:%i',
padding = 0
) {
return this.column(
`time_series(${field}, '${grainSize}', '${format}', '${padding}')`,
alias
)
}

/**
Expand Down Expand Up @@ -166,10 +175,18 @@ export class AliSlsQuery {
* @param wrapValue 是否把值当作字符串处理 是:在查询值两边添加单引号 否:不添加单引号
* @param checkEmpty true进行空值检查,false不进行空值检查
*/
private where(field: string, operate: string, value: string, wrapValue: boolean, checkEmpty: boolean) {
private where(
field: string,
operate: string,
value: string,
wrapValue: boolean,
checkEmpty: boolean
) {
// 当开启空值检查 并且当前值为空的时候跳过该值
if (checkEmpty && !value) return this
const str = wrapValue ? `"${field}" ${operate} '${value}'` : `"${field}" ${operate} ${value}`
const str = wrapValue
? `"${field}" ${operate} '${value}'`
: `"${field}" ${operate} ${value}`
this._where.push(str)
return this
}
Expand Down
18 changes: 15 additions & 3 deletions src/service/AliSlsPageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,35 @@ export class AliSlsPageService {
/**
* 获取日志查询控制台链接
*/
getLogSearchConsolePageUrl(project: string, logstore: string, params: { [key: string]: string }) {
getLogSearchConsolePageUrl(
project: string,
logstore: string,
params: { [key: string]: string }
) {
const search = new URLSearchParams(params).toString()
return `${baseURL}/lognext/project/${project}/logsearch/${logstore}?${search}`
}

/**
* 获取快速查询控制台链接
*/
getSavedSearchConsolePageUrl(project: string, savedsearch: string, params: { [key: string]: string }) {
getSavedSearchConsolePageUrl(
project: string,
savedsearch: string,
params: { [key: string]: string }
) {
const search = new URLSearchParams(params).toString()
return `${baseURL}/lognext/project/${project}/savedsearch/${savedsearch}?${search}`
}

/**
* 获取仪表盘控制台链接
*/
getDashboardConsolePageUrl(project: string, dashboard: string, params: { [key: string]: string }) {
getDashboardConsolePageUrl(
project: string,
dashboard: string,
params: { [key: string]: string }
) {
const search = new URLSearchParams(params).toString()
return `${baseURL}/lognext/project/${project}/dashboard/${dashboard}?${search}`
}
Expand Down
29 changes: 26 additions & 3 deletions src/service/AliSlsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ export class AliSlsService {
name: string,
from: number,
to: number,
param?: { query?: string; topic?: string; offset?: number; line?: number; reverse?: boolean }
param?: {
query?: string
topic?: string
offset?: number
line?: number
reverse?: boolean
}
) {
const params = {
type: 'log',
Expand All @@ -33,7 +39,18 @@ export class AliSlsService {
}

// GetLogs 接口查询指定 Project 下某个 Logstore 中的日志数据
async getLogs(name: string, from: Dayjs, to: Dayjs, param?: { query?: string; topic?: string; offset?: number; line?: number; reverse?: boolean }) {
async getLogs(
name: string,
from: Dayjs,
to: Dayjs,
param?: {
query?: string
topic?: string
offset?: number
line?: number
reverse?: boolean
}
) {
const params = {
type: 'log',
from: from.unix(),
Expand All @@ -45,7 +62,13 @@ export class AliSlsService {
}

// 查询指定 Project 下某个 Logstore 中日志的分布情况
async getHistograms(name: string, from: Dayjs, to: Dayjs, query?: string, topic?: string) {
async getHistograms(
name: string,
from: Dayjs,
to: Dayjs,
query?: string,
topic?: string
) {
const params = {
type: 'histogram',
from: from.unix(),
Expand Down
6 changes: 5 additions & 1 deletion src/test/test-page-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { AliSlsPageService } from '..'
$.run(async () => {
const pageService = new AliSlsPageService()

const url = pageService.getLogSearchConsolePageUrl('xxx-project-xxx', 'xxx-logstore-xx', { isShare: 'true' })
const url = pageService.getLogSearchConsolePageUrl(
'xxx-project-xxx',
'xxx-logstore-xx',
{ isShare: 'true' }
)

console.log(url)
})

0 comments on commit f85c7d4

Please sign in to comment.