Skip to content

Commit

Permalink
feat: object支持别名配置 (#4854)
Browse files Browse the repository at this point in the history
Co-authored-by: Long <43227452+positivelong@users.noreply.github.com>
Co-authored-by: unique0lai <11598235+unique0lai@users.noreply.github.com>
Co-authored-by: chenguo <chenguo367@163.com>
Co-authored-by: wencong1724427771 <82081580+wencong1724427771@users.noreply.github.com>
Co-authored-by: 热心网友陈德华 <47016498+rxwycdh@users.noreply.github.com>
Co-authored-by: xlc <33691777+xiaolicheng-github@users.noreply.github.com>
Co-authored-by: LeeXT <xintaoLi@users.noreply.github.com>
Co-authored-by: Jiahua Wu <553544693@qq.com>
Co-authored-by: 闪烁 <57348011+shan-shuo@users.noreply.github.com>
Co-authored-by: goodGai <106252008+goodGai@users.noreply.github.com>
Co-authored-by: byron <14138993@qq.com>
Co-authored-by: 17 <66986742+yiqiwang-17@users.noreply.github.com>
Co-authored-by: liang ling <lingliang1100@gmail.com>
Co-authored-by: JayCC1 <85379453+JayCC1@users.noreply.github.com>
Co-authored-by: q15971095971 <764419406@qq.com>
Co-authored-by: HACK-WU <89595754+HACK-WU@users.noreply.github.com>
Co-authored-by: tang202388 <141982444+tang202388@users.noreply.github.com>
Co-authored-by: WuFantaotao <88392262+WuFantaotao@users.noreply.github.com>
Co-authored-by: ctenetlau <74183504+EASYGOING45@users.noreply.github.com>
Co-authored-by: yzygyin <168320989+yzygyin@users.noreply.github.com>
Co-authored-by: 奇客 <945186289@qq.com>
  • Loading branch information
1 parent 4ce8299 commit ff09f44
Show file tree
Hide file tree
Showing 33 changed files with 1,204 additions and 201 deletions.
470 changes: 407 additions & 63 deletions bklog/web/src/components/collection-access/field-table.vue

Large diffs are not rendered by default.

145 changes: 134 additions & 11 deletions bklog/web/src/components/collection-access/step-field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,22 @@
data-test-id="fieldExtractionBox_span_applyTemp"
@click="openTemplateDialog(false)"
>
<span class="bklog-icon bklog-daoru"></span>
<i
class="bk-icon bklog-icon bklog-app-store"
v-bk-tooltips.top="$t('隐藏')"
></i>
{{ $t('应用模版') }}
</span>
<span
v-if="docUrl"
class="template-text documentation button-text"
@click="handleGotoLink('logExtract')"
>
{{ $t('说明文档') }}<span class="bklog-icon bklog-jump"></span>
<i
class="bk-icon bklog-icon bklog-help"
v-bk-tooltips.top="$t('隐藏')"
></i>
{{ $t('说明文档') }}
</span>
</div>

Expand All @@ -209,6 +216,7 @@
:data-test-id="`fieldExtractionBox_button_filterMethod${option.id}`"
:disabled="(isCleanField && !cleanCollector) || isSetDisabled"
:key="option.id"
class="bklog-button"
@click="handleSelectConfig(option.id)"
>
{{ option.name }}
Expand Down Expand Up @@ -322,13 +330,13 @@
ext-cls="en-bk-form"
:label="$t('字段列表')"
>
<div
<!-- <div
v-if="!isTempField"
:class="{ 'view-log-btn': true, disabled: !hasFields }"
@click.stop="viewStandard"
>
{{ $t('查看内置字段') }}
</div>
</div> -->
<div
:style="isClearTemplate ? { 'margin-top': '10px' } : ''"
class="field-method-result"
Expand All @@ -345,10 +353,13 @@
:key="renderKey"
:original-text-tokenize-on-chars="defaultParticipleStr"
:retain-extra-json="formData.etl_params.retain_extra_json"
:built-field-show = "builtFieldShow"
:select-etl-config="params.etl_config"
@delete-visible="visibleHandle"
@delete-field="deleteField"
@handle-keep-field="handleKeepField"
@handle-table-data="handleTableData"
@handle-built-field="handleBuiltField"
@reset="getDetail"
@standard="dialogVisible = true"
>
Expand Down Expand Up @@ -1026,6 +1037,7 @@
is_delete: false,
is_dimension: false,
is_time: false,
query_alias:'',
value: '',
option: {
time_format: '',
Expand Down Expand Up @@ -1085,9 +1097,11 @@
field_name: '',
field_type: '',
description: '',
query_alias:'',
is_case_sensitive: false,
is_analyzed: false,
is_built_in: false,
is_add_in: true,
is_dimension: false,
previous_type: '',
tokenize_on_chars: '',
Expand All @@ -1112,6 +1126,9 @@
timeCheckContent: '',
metaDataList: [],
isDebugLoading: false,
builtFieldShow:false,
fieldsObjectData: [],
alias_settings:[]
};
},
computed: {
Expand Down Expand Up @@ -1299,6 +1316,7 @@
}
await this.getCleanStash(collectorID);
this.getDataLog('init');

},
methods: {
handlerSearchTemplate() {
Expand All @@ -1312,6 +1330,22 @@
handleTableData(data) {
this.fieldNameList = data;
},
// 切换显示内置字段
handleBuiltField(value){
this.builtFieldShow = value
if(value){
const allFields = this.$refs.fieldTable.getData();
this.formData.fields = [...allFields, ...this.copyBuiltField]
this.savaFormData();
}else{
const allFields = this.$refs.fieldTable.getData();
const builtFields = allFields.filter( item => item.is_built_in)
this.formData.fields = allFields.filter( item => !item.is_built_in)
if(builtFields.length){
this.copyBuiltField = builtFields;
}
}
},
// 初始化清洗项
initCleanItem() {
this.basicLoading = true;
Expand Down Expand Up @@ -1511,11 +1545,30 @@
// 判断是否有设置字段清洗,如果没有则把etl_params设置成 bk_log_text
data.clean_type = !fieldTableData.length ? 'bk_log_text' : etlConfig;
data.etl_fields = fieldTableData;
if( this.params.etl_config === 'bk_log_json'){
if(!this.builtFieldShow){
this.copyBuiltField.forEach(field => {
if (field.hasOwnProperty('expand')) {
if (field.expand === false) {
this.copyBuiltField.push(...field.children)
}
}
})
data.etl_fields.push(...this.copyBuiltField)
}
data.alias_settings = fieldTableData.filter(item => item.query_alias).map(item => {
return {
field_name: item.alias_name || item.field_name,
query_alias: item.query_alias,
path_type: item.field_type
}
})
data.etl_fields = data.etl_fields.filter( item => !item.is_built_in )
}
} else {
delete data.etl_params['separator_regexp'];
delete data.etl_params['separator'];
}

let requestUrl;
const urlParams = {};
if (this.isSetEdit) {
Expand Down Expand Up @@ -1601,8 +1654,8 @@
},
/** 入库请求 */
async fieldCollectionRequest(atLastFormData, callback) {
const { clean_type: etlConfig, etl_params: etlParams, etl_fields: etlFields } = atLastFormData;
// 检索设置 直接入库
const { clean_type: etlConfig, etl_params: etlParams, etl_fields: etlFields, alias_settings } = atLastFormData;
// 检索设置 直接入库
const {
table_id,
storage_cluster_id,
Expand All @@ -1625,14 +1678,15 @@
etl_config: etlConfig,
fields: etlFields,
etl_params: etlParams,
alias_settings,
};

const updateData = {
params: {
collector_config_id: this.curCollect.collector_config_id,
},
data,
};

this.$http
.request('collect/fieldCollection', updateData)
.then(res => {
Expand Down Expand Up @@ -1840,6 +1894,7 @@
etl_config,
etl_params: etlParams,
fields,
index_set_id
} = this.curCollect;
const option = { time_zone: '', time_format: '' };
const copyFields = fields ? JSON.parse(JSON.stringify(fields)) : [];
Expand All @@ -1858,7 +1913,6 @@
row.option = Object.assign({}, option);
}
});

this.params.etl_config = etl_config;
Object.assign(this.params.etl_params, {
separator_regexp: etlParams?.separator_regexp || '',
Expand Down Expand Up @@ -1899,6 +1953,7 @@
if (this.curCollect.etl_config && this.curCollect.etl_config !== 'bk_log_text') {
this.formatResult = true;
}
this.requestFields(index_set_id)
},
clickFile() {
this.defaultSettings.isShow = true;
Expand Down Expand Up @@ -2245,6 +2300,7 @@
.then(res => {
if (res.data) {
const { clean_type, etl_params: etlParams, etl_fields: etlFields } = res.data;
this.concatenationQueryAlias(etlFields)
this.formData.fields.splice(0, this.formData.fields.length);

this.params.etl_config = clean_type;
Expand Down Expand Up @@ -2314,16 +2370,36 @@
})
.then(async res => {
if (res.data) {
const keys = Object.keys(res.data.alias_settings || {});
const arr = keys.map( key => {
return {
query_alias : key,
field_name : res.data.alias_settings[key].path
}
})
this.alias_settings = arr
this.concatenationQueryAlias( res.data.fields)
this.$store.commit('collect/setCurCollect', res.data);
this.getDetail();
await this.getCleanStash(id);
this.getDataLog('init');
this.requestFields(res.data.index_set_id)
}
})
.finally(() => {
this.basicLoading = false;
});
},
// 拼接query_alias
concatenationQueryAlias(fields) {
fields.forEach(item => {
this.alias_settings.forEach(item2 => {
if( item.field_name === item2.field_name || item.alias_name === item2.field_name ){
item.query_alias = item2.query_alias
}
})
})
},
// 新增、编辑清洗选择采集项
async handleCollectorChange(id) {
this.basicLoading = true;
Expand All @@ -2348,6 +2424,7 @@
});
if (curCollect.create_clean_able || this.isEditCleanItem) {
this.setAdvanceCleanTab(false);

// 获取采集项详情
await this.setDetail(id);
} else {
Expand Down Expand Up @@ -2383,6 +2460,9 @@
},
/** 切换匹配模式 */
handleSelectConfig(id) {
if(this.params.etl_config === id){
return
}
if (!this.isFinishCatchFrom) {
this.catchFields = this.$refs.fieldTable.getData();
this.isFinishCatchFrom = true;
Expand All @@ -2393,6 +2473,7 @@
this.isFinishCatchFrom = false;
return;
}
this.handleBuiltField(false)
this.formData.fields = []; // 切换匹配模式时需要清空字段
},
/** json格式新增字段 */
Expand Down Expand Up @@ -2459,6 +2540,7 @@
},
getNotParticipleFieldTableData() {
const fieldsData = this.$refs.fieldTable.getData() || [];

const { field_name, time_zone, time_format } = this.formData;
const isReportingTime = this.formData.log_reporting_time;
const result = fieldsData.map(item => {
Expand Down Expand Up @@ -2512,6 +2594,40 @@
}, {}),
);
},
/** 获取fields */
async requestFields(indexSetId) {
const typeConversion= {
keyword : 'string'
}
try {
const res = await this.$http.request('retrieve/getLogTableHead', {
params: {
index_set_id: indexSetId
},
});
this.fieldsObjectData = res.data.fields.filter(item => item.field_name.includes('.'))
this.fieldsObjectData.forEach(item => {
let name = item.field_name.split('.')[0]
item.field_type = typeConversion[item.field_type]
item.is_objectKey = true
this.copyBuiltField.forEach( builtField => {
if(builtField.field_type === "object" && name.includes(builtField.field_name)){
if (!Array.isArray(builtField.children)) {
builtField.children = [];
this.$set(builtField, 'expand', false);
}
builtField.children.push(item);
}
} )
})

} catch (err) {
console.warn(err);
}
},
deleteField(field) {
this.formData.fields = this.formData.fields.filter(item => item.field_index !== field.field_index)
}
},
};
</script>
Expand Down Expand Up @@ -2772,6 +2888,13 @@
display: flex;
align-items: center;
margin: 10px 0 0;
.bklog-button{
font-size: 12px;
}
}

.bklog-icon{
font-size: 16px;
}

.documentation {
Expand Down Expand Up @@ -2801,7 +2924,7 @@
}

.field-method-result {
margin-top: -20px;
margin-top: 10px;
}

.add-field-container {
Expand Down Expand Up @@ -3092,4 +3215,4 @@
}
}
}
</style>
</style>
Loading

0 comments on commit ff09f44

Please sign in to comment.