• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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<{
19  name: string;
20  valueText: string;
21}>): TraceMetadata => {
22  info('Meta Strategy data length is:', metricData.length);
23  let traceMetaDataList: Array<TraceMetadataItem> = [];
24  let statDataArray = [];
25  let jsonText = `{`;
26  for (let index = 0; index < metricData.length; index++) {
27    let name = metricData[index].name;
28    let value = metricData[index].valueText;
29    if (!value.match('^-?\\d+$')) {
30      value = '"' + value.replace('\r|\n', '') + '"';
31    }
32    jsonText += `'` + name + `'` + `: ` + `'` + value.toString() + `'` + `,`;
33    if (index >= metricData.length - 1) {
34      jsonText += `}`;
35    }
36  }
37
38  for (let sqlIndex = 0; sqlIndex < metricData.length; sqlIndex++) {
39    let name = metricData[sqlIndex].name;
40    let value = metricData[sqlIndex].valueText;
41    if (!value.match('^-?\\d+$')) {
42      value = '"' + value.replace('\r|\n', '') + '"';
43    }
44    let traceMetaData = {
45      name: name,
46      value: value,
47    };
48    traceMetaDataList?.push(traceMetaData);
49  }
50  return {
51    traceMetadata: traceMetaDataList,
52  };
53};
54
55export interface TraceMetadata {
56  traceMetadata: Array<TraceMetadataItem>;
57}
58
59export interface TraceMetadataItem {
60  name: string;
61  value: string;
62}
63