Skip to content

Commit

Permalink
Merge pull request #6701 from easy-mj/feature/mj-r-master-4933
Browse files Browse the repository at this point in the history
feat(4933): 容器主机支持日志查询
  • Loading branch information
easy-mj committed Jun 14, 2024
2 parents d02f8af + 5f243f4 commit f08e9d4
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 40 deletions.
25 changes: 0 additions & 25 deletions containers/Compute/views/pod-container/mixins/singleActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ export default {
return ret
},
},
{
label: this.$t('common.view_logs'),
action: async (obj) => {
const connectRes = await this.fetchLogUrl(obj)
this.openWebConsole(connectRes)
},
meta: (obj) => {
const ret = { validate: true }
if (!['running', 'exited'].includes(obj.status)) {
ret.tooltip = this.$t('compute.repo.helper.view_log', [this.$t('dictionary.container')])
ret.validate = false
}
return ret
},
},
{
label: this.$t('common.more'),
actions: (obj) => {
Expand Down Expand Up @@ -103,15 +88,5 @@ export default {
})
return Promise.resolve(data)
},
async fetchLogUrl (obj) {
const { data } = await new this.$Manager('webconsole', 'v1').objectRpc({
methodname: 'DoContainerLog',
params: {
container_id: obj.id,
follow: true,
},
})
return Promise.resolve(data)
},
},
}
112 changes: 112 additions & 0 deletions containers/Compute/views/pod-container/sidepage/Log.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<template>
<div>
<a-form-model :model="form" layout="inline">
<a-form-model-item :label="$t('k8s.text_1')">
<a-select style="min-width: 200px;" v-model="form.activeContainer">
<a-select-option v-for="item in containers" :value="item.id" :key="item.id">{{ item.name }}</a-select-option>
</a-select>
</a-form-model-item>
<a-form-model-item :label="$t('k8s.text_320')">
<a-row>
<a-col :span="12">
<a-form-model-item>
<a-select style="min-width: 240px;" v-model="form.time">
<a-select-option v-for="item in timeOptions" :value="item.value" :key="item.name">{{ item.name }}</a-select-option>
</a-select>
</a-form-model-item>
</a-col>
<a-col :span="12" v-show="isCustomTime">
<a-form-model-item>
<duration-second-input v-model="form.customTime" :durationOptions="durationOptions" />
</a-form-model-item>
</a-col>
</a-row>
</a-form-model-item>
<a-form-model-item>
<a-button type="primary" style="margin-left: -20px;" @click="fetchUrl">{{$t('common.ok')}}</a-button>
</a-form-model-item>
</a-form-model>
<xterm :connectParams="connectParams" />
</div>
</template>

<script>
export default {
name: 'Log',
props: {
data: {
type: Object,
required: true,
},
},
data () {
return {
containers: [],
form: {
activeContainer: '',
time: 'all',
customTime: 3600,
},
connectParams: '',
durationOptions: [
{ label: this.$t('k8s.text_321'), key: 'hours' },
{ label: this.$t('k8s.text_322'), key: 'minutes' },
{ label: this.$t('k8s.text_323'), key: 'days' },
],
timeOptions: [
{ name: this.$t('common_95'), value: 'all' },
{ name: this.$t('common_nearly_num_minutes', [5]), value: 5 * 60 },
{ name: this.$t('common_nearly_num_minutes', [30]), value: 30 * 60 },
{ name: this.$t('common_nearly_num_hours', [1]), value: 60 * 60 },
{ name: this.$t('common_nearly_num_hours', [6]), value: 6 * 60 * 60 },
{ name: this.$t('common_nearly_num_hours', [12]), value: 12 * 60 * 60 },
{ name: this.$t('common_nearly_num_days', [1]), value: 24 * 60 * 60 },
{ name: this.$t('common.date_time.custom'), value: 'custom' },
],
}
},
computed: {
isAllTime () {
return this.form.time === 'all'
},
isCustomTime () {
return this.form.time === 'custom'
},
},
created () {
this.manager = new this.$Manager('containers')
this.fetchData()
},
methods: {
async fetchData () {
const { data } = await this.manager.list({
params: {
guest_id: this.data.guest_id,
},
})
this.containers = data.data
const firstContainer = data.data?.[0]
this.form.activeContainer = firstContainer.id
this.fetchUrl()
},
async fetchUrl () {
const params = {
container_id: this.form.activeContainer,
follow: true,
}
if (!this.isAllTime) {
if (this.isCustomTime) {
params.since = `${this.form.customTime}s`
} else {
params.since = `${this.form.time}s`
}
}
const { data } = await new this.$Manager('webconsole', 'v1').objectRpc({
methodname: 'DoContainerLog',
params,
})
this.connectParams = data.connect_params
},
},
}
</script>
3 changes: 3 additions & 0 deletions containers/Compute/views/pod-container/sidepage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import SidePageMixin from '@/mixins/sidePage'
import WindowsMixin from '@/mixins/windows'
import Actions from '@/components/PageList/Actions'
import Log from './Log'
import Monitor from './Monitor'
import Detail from './Detail'
import SingleActionsMixin from '../mixins/singleActions'
Expand All @@ -42,13 +43,15 @@ export default {
name: 'VmPodContainerSidePage',
components: {
Actions,
Log,
Monitor,
Detail,
},
mixins: [SidePageMixin, WindowsMixin, ColumnsMixin, SingleActionsMixin],
data () {
const detailTabs = [
{ label: this.$t('compute.text_238'), key: 'detail' },
{ label: this.$t('k8s.text_325'), key: 'log' },
{ label: this.$t('compute.text_608'), key: 'monitor' },
{ label: this.$t('compute.text_240'), key: 'event-drawer' },
]
Expand Down
55 changes: 41 additions & 14 deletions containers/K8S/views/pod/sidepage/Log.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@
<div>
<a-form-model :model="form" layout="inline">
<a-form-model-item :label="$t('k8s.text_1')">
<a-select style="min-width: 200px;" v-model="form.activeContainer" @change="fetchUrl">
<a-select style="min-width: 200px;" v-model="form.activeContainer">
<a-select-option v-for="item in containers" :value="item.name" :key="item.name">{{ item.name }}</a-select-option>
</a-select>
</a-form-model-item>
<a-form-model-item :label="$t('k8s.text_319')">
<a-switch v-model="form.showTime" />
<a-form-model-item :label="$t('k8s.text_320')">
<a-row>
<a-col :span="12">
<a-form-model-item>
<a-select style="min-width: 240px;" v-model="form.time">
<a-select-option v-for="item in timeOptions" :value="item.value" :key="item.name">{{ item.name }}</a-select-option>
</a-select>
</a-form-model-item>
</a-col>
<a-col :span="12" v-show="isCustomTime">
<a-form-model-item>
<duration-second-input v-model="form.customTime" :durationOptions="durationOptions" />
</a-form-model-item>
</a-col>
</a-row>
</a-form-model-item>
<a-form-model-item :label="$t('k8s.text_320')" v-if="form.showTime">
<duration-second-input v-model="form.time" :durationOptions="durationOptions" />
<a-form-model-item>
<a-button type="primary" style="margin-left: -20px;" @click="fetchUrl">{{$t('common.ok')}}</a-button>
</a-form-model-item>
</a-form-model>
<xterm :connectParams="connectParams" />
Expand All @@ -31,23 +44,33 @@ export default {
containers: [],
form: {
activeContainer: '',
showTime: false,
time: 3600,
time: 'all',
customTime: 3600,
},
connectParams: '',
durationOptions: [
{ label: this.$t('k8s.text_321'), key: 'hours' },
{ label: this.$t('k8s.text_322'), key: 'minutes' },
{ label: this.$t('k8s.text_323'), key: 'days' },
],
timeOptions: [
{ name: this.$t('common_95'), value: 'all' },
{ name: this.$t('common_nearly_num_minutes', [5]), value: 5 * 60 },
{ name: this.$t('common_nearly_num_minutes', [30]), value: 30 * 60 },
{ name: this.$t('common_nearly_num_hours', [1]), value: 60 * 60 },
{ name: this.$t('common_nearly_num_hours', [6]), value: 6 * 60 * 60 },
{ name: this.$t('common_nearly_num_hours', [12]), value: 12 * 60 * 60 },
{ name: this.$t('common_nearly_num_days', [1]), value: 24 * 60 * 60 },
{ name: this.$t('common.date_time.custom'), value: 'custom' },
],
}
},
watch: {
'form.showTime' () {
this.fetchUrl()
computed: {
isAllTime () {
return this.form.time === 'all'
},
'form.time' () {
this.fetchUrl()
isCustomTime () {
return this.form.time === 'custom'
},
},
created () {
Expand All @@ -74,8 +97,12 @@ export default {
name: this.data.name,
container,
}
if (this.form.showTime) {
params.since = `${this.form.time}s`
if (!this.isAllTime) {
if (this.isCustomTime) {
params.since = `${this.form.customTime}s`
} else {
params.since = `${this.form.time}s`
}
}
const { data } = await new this.$Manager('webconsole', 'v1').objectRpc({
methodname: 'DoK8sLogConnect',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4432,7 +4432,9 @@
"common_165": "(IP can be filled)",
"common_166": "Time Granularity",
"common_167": "Last 1 hour",
"common_nearly_num_minutes": "Last {0} minutes",
"common_nearly_num_hours": "Last {0} hours",
"common_nearly_num_days": "Last {0} days",
"common_num_minutes": "{0} minutes",
"common_num_hours": "{0} hours",
"common_168": "1 minute",
Expand Down
4 changes: 3 additions & 1 deletion src/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -4449,7 +4449,9 @@
"common_165": "(補足可能なIP)",
"common_166": "時間の粒度",
"common_167": "ほぼ1時間",
"common_nearly_num_hours": "ほぼ{0}時間",
"common_nearly_num_minutes": "過去 {0} 分間",
"common_nearly_num_hours": "過去 {0} 時間",
"common_nearly_num_days": "過去 {0} 日間",
"common_num_minutes": "{0}分",
"common_num_hours": "{0}時間",
"common_168": "1 分",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -4450,7 +4450,9 @@
"common_165": "(可补IP)",
"common_166": "时间粒度",
"common_167": "近1小时",
"common_nearly_num_minutes": "近{0}分钟",
"common_nearly_num_hours": "近{0}小时",
"common_nearly_num_days": "近{0}天",
"common_num_minutes": "{0}分钟",
"common_num_hours": "{0}小时",
"common_168": "1分钟",
Expand Down

0 comments on commit f08e9d4

Please sign in to comment.