2021-08-05 22:25:55 +08:00
|
|
|
<template>
|
2021-10-11 14:05:07 +08:00
|
|
|
<nz-bottom-data-list
|
|
|
|
|
:showTitle='showTitle'
|
2021-11-17 13:51:28 +08:00
|
|
|
:obj='obj'
|
2022-10-18 14:33:45 +08:00
|
|
|
id="logBottomTab"
|
2022-10-28 14:07:06 +08:00
|
|
|
:tableId="tableId"
|
2021-08-05 22:25:55 +08:00
|
|
|
:custom-tool="true"
|
|
|
|
|
:layout="[]"
|
|
|
|
|
:show-pagination="false"
|
|
|
|
|
:tabs="tabs"
|
|
|
|
|
:targetTab="targetTab"
|
|
|
|
|
@changeTab="changeTab"
|
|
|
|
|
>
|
|
|
|
|
<template v-slot:title><span :title="obj.name">{{obj.name}}</span></template>
|
|
|
|
|
<template v-slot:top-tool-right>
|
2023-04-18 15:15:48 +08:00
|
|
|
<el-input v-model="matchContent" class="margin-r-10" placeholder="" size="small" @keyup.enter.native="dateChange()">
|
2021-08-05 22:25:55 +08:00
|
|
|
<el-select slot="prepend" v-model="matchSymbol" class="symbol-select" size="small" style="width: 60px;">
|
2021-10-28 15:10:56 +08:00
|
|
|
<el-option value="|=">
|
|
|
|
|
<span style="font-family: Inter-Regular">|=</span>
|
|
|
|
|
</el-option>
|
|
|
|
|
<el-option value="!=">
|
|
|
|
|
<span style="font-family: Inter-Regular">!=</span>
|
|
|
|
|
</el-option>
|
|
|
|
|
<el-option value="|~">
|
|
|
|
|
<span style="font-family: Inter-Regular">|~</span>
|
|
|
|
|
</el-option>
|
|
|
|
|
<el-option value="!~">
|
|
|
|
|
<span style="font-family: Inter-Regular">!~</span>
|
|
|
|
|
</el-option>
|
2021-08-05 22:25:55 +08:00
|
|
|
</el-select>
|
2023-04-18 15:15:48 +08:00
|
|
|
<button slot="suffix" class="search-icon-btn"><i class="el-icon-search" @click="dateChange()"></i></button>
|
2021-08-05 22:25:55 +08:00
|
|
|
</el-input>
|
2023-07-20 17:03:55 +08:00
|
|
|
<pick-time id="explore" ref="pickTime" v-model="filterTime" :refresh-data-func="getData" :show-locked="true" :sign="sign" :use-chart-unit="false" :use-refresh="false">
|
2021-08-05 22:25:55 +08:00
|
|
|
<template slot="added-text">{{$t('overall.query')}}</template>
|
|
|
|
|
</pick-time>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-slot>
|
2022-09-09 16:03:54 +08:00
|
|
|
<log-tab ref="logDetail" v-my-loading="loading" :loading-bottom="endpointLoading" :time-range="filterTime" :log-data="logData" :tab-index="9" @exportLog="exportLog" @limitChange="queryLogData"></log-tab>
|
2022-03-25 15:40:05 +08:00
|
|
|
<!-- <div v-my-loading="loading" v-if="!logData" style="height: 300px; width: 100%; display: flex; justify-content: center; align-items: center; color: #999;">No Data</div>-->
|
2021-08-05 22:25:55 +08:00
|
|
|
</template>
|
|
|
|
|
</nz-bottom-data-list>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import nzBottomDataList from '@/components/common/bottomBox/nzBottomDataList'
|
|
|
|
|
import logTab from '@/components/page/dashboard/explore/logTab'
|
|
|
|
|
import subDataListMixin from '@/components/common/mixin/subDataList'
|
|
|
|
|
import axios from 'axios'
|
|
|
|
|
import bus from '@/libs/bus'
|
2021-08-06 17:06:52 +08:00
|
|
|
import { fromRoute } from '@/components/common/js/constants'
|
2021-10-11 14:05:07 +08:00
|
|
|
import detailViewRightMixin from '@/components/common/mixin/detailViewRightMixin'
|
2021-08-05 22:25:55 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'logBottomTab',
|
2021-10-11 14:05:07 +08:00
|
|
|
mixins: [subDataListMixin, detailViewRightMixin],
|
2021-08-05 22:25:55 +08:00
|
|
|
components: {
|
|
|
|
|
nzBottomDataList,
|
|
|
|
|
logTab
|
|
|
|
|
},
|
2022-04-13 17:09:59 +08:00
|
|
|
props: {
|
2022-10-18 14:33:45 +08:00
|
|
|
sign: [Number, String]
|
2022-04-13 17:09:59 +08:00
|
|
|
},
|
2021-08-05 22:25:55 +08:00
|
|
|
data () {
|
|
|
|
|
return {
|
2022-10-28 14:07:06 +08:00
|
|
|
tableId: 'logBottomTab',
|
2021-09-26 18:01:10 +08:00
|
|
|
logData: null,
|
2021-08-05 22:25:55 +08:00
|
|
|
filterTime: [
|
2022-04-22 10:04:59 +08:00
|
|
|
bus.timeFormate(bus.getOffsetTimezoneData(-1)),
|
|
|
|
|
bus.timeFormate(bus.getOffsetTimezoneData())
|
2021-08-05 22:25:55 +08:00
|
|
|
],
|
|
|
|
|
expressions: [''],
|
|
|
|
|
matchSymbol: '|=',
|
2021-08-31 18:13:15 +08:00
|
|
|
matchContent: '',
|
2021-11-01 10:18:33 +08:00
|
|
|
loading: true,
|
2023-04-18 17:26:56 +08:00
|
|
|
endpointLoading: false,
|
2023-07-20 17:03:55 +08:00
|
|
|
limit: 100,
|
|
|
|
|
nowTimeType: {}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
timePickerLocked () {
|
|
|
|
|
return this.$store.getters.getTimePickerLocked
|
|
|
|
|
},
|
|
|
|
|
timePickerRange () {
|
|
|
|
|
return this.$store.getters.getTimePickerRange
|
2021-08-05 22:25:55 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
exportLog ({ limit, descending }) {
|
|
|
|
|
const params = {
|
|
|
|
|
logql: this.expressions,
|
2022-04-22 10:04:59 +08:00
|
|
|
start: this.$stringTimeParseToUnix(bus.formateTimeToTime(this.filterTime[0])),
|
|
|
|
|
end: this.$stringTimeParseToUnix(bus.formateTimeToTime(this.filterTime[1])),
|
2021-08-05 22:25:55 +08:00
|
|
|
direction: descending ? 'backward' : 'forward',
|
|
|
|
|
limit
|
|
|
|
|
}
|
|
|
|
|
axios.get('/logs/loki/export', { responseType: 'blob', params: params }).then(res => {
|
|
|
|
|
if (window.navigator.msSaveOrOpenBlob) {
|
|
|
|
|
// 兼容ie11
|
|
|
|
|
const blobObject = new Blob([res.data])
|
|
|
|
|
window.navigator.msSaveOrOpenBlob(blobObject, 'log')
|
|
|
|
|
} else {
|
|
|
|
|
const url = URL.createObjectURL(new Blob([res.data]))
|
|
|
|
|
const a = document.createElement('a')
|
|
|
|
|
document.body.appendChild(a) // 此处增加了将创建的添加到body当中
|
|
|
|
|
a.href = url
|
|
|
|
|
a.download = 'log'
|
|
|
|
|
a.target = '_blank'
|
|
|
|
|
a.click()
|
|
|
|
|
a.remove() // 将a标签移除
|
|
|
|
|
}
|
|
|
|
|
}, error => {
|
|
|
|
|
const $self = this
|
|
|
|
|
const reader = new FileReader()
|
|
|
|
|
reader.onload = function (event) {
|
|
|
|
|
const responseText = reader.result
|
|
|
|
|
const exception = JSON.parse(responseText)
|
|
|
|
|
if (exception.message) {
|
|
|
|
|
$self.$message.error(exception.message)
|
|
|
|
|
} else {
|
|
|
|
|
console.error(error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
reader.readAsText(error.response.data)
|
|
|
|
|
})
|
|
|
|
|
},
|
2023-04-18 15:15:48 +08:00
|
|
|
dateChange () {
|
|
|
|
|
this.$refs.pickTime && this.$refs.pickTime.$refs.timePicker.refresh()
|
|
|
|
|
},
|
2023-04-18 17:26:56 +08:00
|
|
|
getData () {
|
2023-07-20 17:03:55 +08:00
|
|
|
const nowTimeType = this.$refs.pickTime.$refs.timePicker.nowTimeType
|
|
|
|
|
this.setSearchTime(nowTimeType.type, nowTimeType.value)
|
|
|
|
|
this.$store.dispatch('dispatchTimePickerRange', {
|
|
|
|
|
time: this.searchTime,
|
|
|
|
|
nowTimeType: this.nowTimeType
|
|
|
|
|
})
|
2023-04-18 17:26:56 +08:00
|
|
|
this.queryLogData()
|
|
|
|
|
},
|
2023-07-20 17:03:55 +08:00
|
|
|
setTimePickerRange () {
|
2023-07-20 18:02:58 +08:00
|
|
|
this.$nextTick(() => {
|
|
|
|
|
if (!this.timePickerLocked || !this.timePickerRange.nowTimeType) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const nowTimeType = this.nowTimeType = this.timePickerRange.nowTimeType
|
|
|
|
|
this.filterTime = this.timePickerRange.time
|
|
|
|
|
this.$refs.pickTime && this.$refs.pickTime.$refs.timePicker.setTimeRange(this.nowTimeType, this.filterTime)
|
|
|
|
|
this.setSearchTime(nowTimeType.type, nowTimeType.value, nowTimeType)
|
|
|
|
|
})
|
2023-07-20 17:03:55 +08:00
|
|
|
},
|
|
|
|
|
setSearchTime (type, val) { // 设置searchTime
|
|
|
|
|
if (type === 'minute') {
|
|
|
|
|
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setMinutes(new Date(bus.computeTimezone(new Date().getTime())).getMinutes() - val))
|
|
|
|
|
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())))
|
|
|
|
|
this.$set(this.filterTime, 0, startTime)
|
|
|
|
|
this.$set(this.filterTime, 1, endTime)
|
|
|
|
|
this.$set(this.filterTime, 2, val + 'm')
|
|
|
|
|
} else if (type === 'hour') {
|
|
|
|
|
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setHours(new Date(bus.computeTimezone(new Date().getTime())).getHours() - val))
|
|
|
|
|
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())))
|
|
|
|
|
this.$set(this.filterTime, 0, startTime)
|
|
|
|
|
this.$set(this.filterTime, 1, endTime)
|
|
|
|
|
this.$set(this.filterTime, 2, val + 'h')
|
|
|
|
|
} else if (type === 'date') {
|
|
|
|
|
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setDate(new Date(bus.computeTimezone(new Date().getTime())).getDate() - val))
|
|
|
|
|
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())))
|
|
|
|
|
this.$set(this.filterTime, 0, startTime)
|
|
|
|
|
this.$set(this.filterTime, 1, endTime)
|
|
|
|
|
this.$set(this.filterTime, 2, val + 'd')
|
|
|
|
|
}
|
|
|
|
|
this.$refs.pickTime.$refs.timePicker.searchTime = this.filterTime
|
|
|
|
|
},
|
2023-04-18 17:26:56 +08:00
|
|
|
queryLogData (limit) { // log的chart和table是一个请求
|
2021-08-31 18:13:15 +08:00
|
|
|
this.loading = true
|
2023-04-18 17:26:56 +08:00
|
|
|
if (limit) {
|
|
|
|
|
this.limit = limit
|
|
|
|
|
}
|
2021-08-05 22:25:55 +08:00
|
|
|
if (this.expressions.length > 0) {
|
|
|
|
|
const requestArr = []
|
|
|
|
|
this.expressions.forEach((item, index) => {
|
|
|
|
|
if (item != '') {
|
|
|
|
|
let expr = item
|
2021-08-25 16:05:33 +08:00
|
|
|
this.matchContent && (expr = `${item} ${this.matchSymbol} "${this.matchContent}"`)
|
2022-04-22 10:04:59 +08:00
|
|
|
const statTime = bus.formateTimeToTime(this.filterTime[0])
|
|
|
|
|
const endTime = bus.formateTimeToTime(this.filterTime[1])
|
2023-04-18 17:26:56 +08:00
|
|
|
requestArr.push(this.$get('/logs/loki/api/v1/query_range?format=1&query=' + encodeURIComponent(expr) + '&start=' + this.$stringTimeParseToUnix(statTime) + '&end=' + this.$stringTimeParseToUnix(endTime) + '&limit=' + this.limit))
|
2021-08-05 22:25:55 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
axios.all(requestArr).then(res => {
|
|
|
|
|
this.logData = res.map(r => r.data)
|
2022-03-23 16:27:59 +08:00
|
|
|
if (this.logData[0]) {
|
|
|
|
|
if (this.logData[0].result.length > 0) {
|
|
|
|
|
this.endpointLoading = false
|
|
|
|
|
} else {
|
|
|
|
|
this.endpointLoading = true
|
|
|
|
|
}
|
2021-11-01 10:18:33 +08:00
|
|
|
} else {
|
|
|
|
|
this.endpointLoading = true
|
|
|
|
|
}
|
2021-08-31 18:13:15 +08:00
|
|
|
}).finally(() => {
|
|
|
|
|
this.loading = false
|
2021-08-05 22:25:55 +08:00
|
|
|
})
|
2021-08-31 18:13:15 +08:00
|
|
|
} else {
|
|
|
|
|
this.loading = false
|
2021-08-05 22:25:55 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted () {
|
2021-08-05 22:31:36 +08:00
|
|
|
if (this.from === fromRoute.endpoint) {
|
|
|
|
|
this.expressions = [`{project="${this.obj.project.name}",module="${this.obj.module.name}",endpoint="${this.obj.name}"}`]
|
|
|
|
|
} else if (this.from === fromRoute.asset) {
|
|
|
|
|
this.expressions = [`{asset="${this.obj.name}"}`]
|
|
|
|
|
}
|
2023-07-20 17:03:55 +08:00
|
|
|
this.setTimePickerRange()
|
2021-10-11 14:05:07 +08:00
|
|
|
this.$nextTick(() => {
|
2021-09-26 18:01:10 +08:00
|
|
|
this.queryLogData()
|
|
|
|
|
})
|
2021-08-05 22:25:55 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|