1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import {info} from "../../../log/Log.js"; 17 18export const initMetaDataStrategy = (metricData: Array<any>): TraceMetadata => { 19 info("Meta Strategy data length is:", metricData.length) 20 let traceMetaDataList: Array<TraceMetadataItem> = [] 21 let statDataArray = []; 22 let jsonText = `{`; 23 for (let index = 0; index < metricData.length; index++) { 24 let name = metricData[index].name; 25 let value = metricData[index].valueText; 26 if (!value.match('^-?\\d+$')) { 27 value = "\"" + value.replace('\r|\n', '') + '\"' 28 } 29 jsonText += `'` + name + `'` + `: ` + `'` + value.toString() + `'` + `,`; 30 if (index >= metricData.length - 1) { 31 jsonText += `}`; 32 } 33 } 34 35 for (let sqlIndex = 0; sqlIndex < metricData.length; sqlIndex++) { 36 let name = metricData[sqlIndex].name; 37 let value = metricData[sqlIndex].valueText; 38 if (!value.match('^-?\\d+$')) { 39 value = "\"" + value.replace('\r|\n', '') + '\"' 40 } 41 let traceMetaData = { 42 name: name, 43 value: value 44 } 45 traceMetaDataList?.push(traceMetaData); 46 } 47 return { 48 traceMetadata: traceMetaDataList 49 } 50} 51 52export interface TraceMetadata { 53 traceMetadata: Array<TraceMetadataItem> 54} 55 56export interface TraceMetadataItem { 57 name: string 58 value: string 59} 60 61