Skip to content

Commit b9bcbdf

Browse files
committed
[#9631] Add API to retrieve CLP replaced tokens with count and ordering
sdf
1 parent c9233f7 commit b9bcbdf

File tree

17 files changed

+513
-40
lines changed

17 files changed

+513
-40
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2024 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.navercorp.pinpoint.exceptiontrace.common.pinot;
17+
18+
/**
19+
* @author intr3p1d
20+
*/
21+
public enum PinotFunctions {
22+
ARRAY_SLICE_INT("arraySliceInt"),
23+
ARRAY_SLICE_STRING("arraySliceString");
24+
25+
private final String name;
26+
27+
PinotFunctions(String name) {
28+
this.name = name;
29+
}
30+
31+
public String getName() {
32+
return name;
33+
}
34+
}

exceptiontrace/exceptiontrace-web/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
<groupId>com.navercorp.pinpoint</groupId>
3030
<artifactId>pinpoint-exceptiontrace-common</artifactId>
3131
</dependency>
32+
<dependency>
33+
<groupId>org.apache.commons</groupId>
34+
<artifactId>commons-text</artifactId>
35+
<version>1.10.0</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.apache.commons</groupId>
39+
<artifactId>commons-lang3</artifactId>
40+
</dependency>
3241
<dependency>
3342
<groupId>org.mapstruct</groupId>
3443
<artifactId>mapstruct</artifactId>

exceptiontrace/exceptiontrace-web/src/main/java/com/navercorp/pinpoint/exceptiontrace/web/config/ExceptionTraceRegistryHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
import com.navercorp.pinpoint.exceptiontrace.web.entity.ErrorSummaryEntity;
1919
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionChartValueViewEntity;
2020
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionGroupSummaryEntity;
21+
import com.navercorp.pinpoint.exceptiontrace.web.entity.ClpConvertedEntity;
2122
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionMetaDataEntity;
2223
import com.navercorp.pinpoint.exceptiontrace.web.entity.GroupedFieldNameEntity;
23-
import com.navercorp.pinpoint.exceptiontrace.web.util.ExceptionTraceQueryParameter;
24+
import com.navercorp.pinpoint.exceptiontrace.web.query.ClpQueryParameter;
25+
import com.navercorp.pinpoint.exceptiontrace.web.query.ExceptionTraceQueryParameter;
2426
import com.navercorp.pinpoint.mybatis.MyBatisRegistryHandler;
2527
import org.apache.ibatis.type.TypeAliasRegistry;
2628
import org.apache.ibatis.type.TypeHandlerRegistry;
@@ -36,7 +38,9 @@ public void registerTypeAlias(TypeAliasRegistry typeAliasRegistry) {
3638
typeAliasRegistry.registerAlias(ErrorSummaryEntity.class);
3739
typeAliasRegistry.registerAlias(ExceptionGroupSummaryEntity.class);
3840
typeAliasRegistry.registerAlias(ExceptionChartValueViewEntity.class);
41+
typeAliasRegistry.registerAlias(ClpConvertedEntity.class);
3942
typeAliasRegistry.registerAlias(ExceptionTraceQueryParameter.class);
43+
typeAliasRegistry.registerAlias(ClpQueryParameter.class);
4044
}
4145

4246
@Override

exceptiontrace/exceptiontrace-web/src/main/java/com/navercorp/pinpoint/exceptiontrace/web/controller/ExceptionTraceController.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import com.navercorp.pinpoint.common.server.util.time.RangeValidator;
2121
import com.navercorp.pinpoint.exceptiontrace.web.model.ErrorSummary;
2222
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionGroupSummary;
23+
import com.navercorp.pinpoint.exceptiontrace.web.query.ExceptionTraceQueryParameter;
2324
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionChartValueView;
25+
import com.navercorp.pinpoint.exceptiontrace.web.model.ClpConverted;
26+
import com.navercorp.pinpoint.exceptiontrace.web.query.ClpQueryParameter;
2427
import com.navercorp.pinpoint.exceptiontrace.web.service.ExceptionTraceService;
25-
import com.navercorp.pinpoint.exceptiontrace.web.util.ExceptionTraceQueryParameter;
2628
import com.navercorp.pinpoint.exceptiontrace.web.util.GroupByAttributes;
2729
import com.navercorp.pinpoint.exceptiontrace.web.view.ErrorSummaryView;
2830
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionDetailView;
@@ -197,6 +199,37 @@ public List<ExceptionGroupSummary> getListOfExceptionMetaDataWithDynamicGroupBy(
197199
);
198200
}
199201

202+
@GetMapping("/replacedTokens")
203+
public List<ClpConverted> getReplacedVariables(
204+
@RequestParam("applicationName") @NotBlank String applicationName,
205+
@RequestParam(value = "agentId", required = false) String agentId,
206+
@RequestParam("from") @PositiveOrZero long from,
207+
@RequestParam("to") @PositiveOrZero long to,
208+
209+
@RequestParam("logType") String logType,
210+
@RequestParam("targetColumn") String targetColumn,
211+
@RequestParam("targetIndex") int targetIndex
212+
) {
213+
Range range = Range.between(from, to);
214+
rangeValidator.validate(range);
215+
216+
ClpQueryParameter queryParameter = new ClpQueryParameter.Builder()
217+
.setTableName(tableName)
218+
.setTenantId(tenantProvider.getTenantId())
219+
.setApplicationName(applicationName)
220+
.setAgentId(agentId)
221+
.setRange(Range.between(from, to))
222+
.setTimePrecision(DETAILED_TIME_PRECISION)
223+
.setLogType(logType)
224+
.setTargetColumn(targetColumn)
225+
.setTargetIndex(targetIndex)
226+
.build();
227+
228+
return exceptionTraceService.getReplacedVariables(
229+
queryParameter
230+
);
231+
}
232+
200233
@GetMapping("/chart")
201234
public ExceptionChartView getCollectedExceptionMetaDataByGivenRange(
202235
@RequestParam("applicationName") @NotBlank String applicationName,

exceptiontrace/exceptiontrace-web/src/main/java/com/navercorp/pinpoint/exceptiontrace/web/dao/ExceptionTraceDao.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import com.navercorp.pinpoint.exceptiontrace.common.model.ExceptionMetaData;
2121
import com.navercorp.pinpoint.exceptiontrace.web.model.ErrorSummary;
2222
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionGroupSummary;
23+
import com.navercorp.pinpoint.exceptiontrace.web.query.ExceptionTraceQueryParameter;
2324
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionChartValueView;
24-
import com.navercorp.pinpoint.exceptiontrace.web.util.ExceptionTraceQueryParameter;
2525
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionDetailView;
26+
import com.navercorp.pinpoint.exceptiontrace.web.model.ClpConverted;
27+
import com.navercorp.pinpoint.exceptiontrace.web.query.ClpQueryParameter;
2628

2729
import java.util.List;
2830

@@ -36,4 +38,5 @@ public interface ExceptionTraceDao {
3638
List<ExceptionGroupSummary> getGroupSummaries(ExceptionTraceQueryParameter exceptionTraceQueryParameter);
3739
List<ExceptionChartValueView> getChartValueViews(ExceptionTraceQueryParameter exceptionTraceQueryParameter);
3840
List<ErrorSummary> getErrorSummaries(ExceptionTraceQueryParameter exceptionTraceQueryParameter);
41+
List<ClpConverted> getReplacedVariables(ClpQueryParameter queryParameter);
3942
}

exceptiontrace/exceptiontrace-web/src/main/java/com/navercorp/pinpoint/exceptiontrace/web/dao/PinotExceptionTraceDao.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919
import com.navercorp.pinpoint.exceptiontrace.common.model.ExceptionMetaData;
2020
import com.navercorp.pinpoint.exceptiontrace.web.entity.ErrorSummaryEntity;
2121
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionGroupSummaryEntity;
22+
import com.navercorp.pinpoint.exceptiontrace.web.entity.ClpConvertedEntity;
2223
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionMetaDataEntity;
2324
import com.navercorp.pinpoint.exceptiontrace.web.model.ErrorSummary;
2425
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionChartValueViewEntity;
2526
import com.navercorp.pinpoint.exceptiontrace.web.mapper.ExceptionEntityMapper;
2627
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionGroupSummary;
27-
import com.navercorp.pinpoint.exceptiontrace.web.util.ExceptionTraceQueryParameter;
28+
import com.navercorp.pinpoint.exceptiontrace.web.query.ExceptionTraceQueryParameter;
2829
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionChartValueView;
2930
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionDetailView;
31+
import com.navercorp.pinpoint.exceptiontrace.web.model.ClpConverted;
32+
import com.navercorp.pinpoint.exceptiontrace.web.query.ClpQueryParameter;
3033
import org.apache.logging.log4j.LogManager;
3134
import org.apache.logging.log4j.Logger;
3235
import org.mybatis.spring.SqlSessionTemplate;
@@ -52,6 +55,7 @@ public class PinotExceptionTraceDao implements ExceptionTraceDao {
5255
private static final String SELECT_GROUP_SUMMARIES_QUERY = "selectGroupSummaries";
5356
private static final String SELECT_CHART_QUERY = "selectChartValueViews";
5457
private static final String SELECT_ERROR_SUMMARIES_QUERY = "selectErrorSummaries";
58+
private static final String SELECT_CLP_VARIABLES_QUERY = "selectClpVariables";
5559

5660
private final SqlSessionTemplate sqlPinotSessionTemplate;
5761

@@ -124,4 +128,13 @@ public List<ErrorSummary> getErrorSummaries(ExceptionTraceQueryParameter excepti
124128
)
125129
).collect(Collectors.toList());
126130
}
131+
132+
@Override
133+
public List<ClpConverted> getReplacedVariables(ClpQueryParameter queryParameter) {
134+
List<ClpConvertedEntity> clpConvertedEntities = this.sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_CLP_VARIABLES_QUERY, queryParameter);
135+
136+
return clpConvertedEntities.stream()
137+
.map(mapper::toClpConverted)
138+
.collect(Collectors.toList());
139+
}
127140
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2024 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.navercorp.pinpoint.exceptiontrace.web.entity;
17+
18+
/**
19+
* @author intr3p1d
20+
*/
21+
public class ClpConvertedEntity {
22+
23+
private String replacedToken;
24+
private int count;
25+
26+
public ClpConvertedEntity() {
27+
}
28+
29+
public String getReplacedToken() {
30+
return replacedToken;
31+
}
32+
33+
public void setReplacedToken(String replacedToken) {
34+
this.replacedToken = replacedToken;
35+
}
36+
37+
public int getCount() {
38+
return count;
39+
}
40+
41+
public void setCount(int count) {
42+
this.count = count;
43+
}
44+
}

exceptiontrace/exceptiontrace-web/src/main/java/com/navercorp/pinpoint/exceptiontrace/web/mapper/CLPMapper.java

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
*/
1616
package com.navercorp.pinpoint.exceptiontrace.web.mapper;
1717

18+
19+
import org.apache.commons.text.StringEscapeUtils;
20+
1821
import java.nio.charset.StandardCharsets;
22+
import java.util.function.Function;
23+
import java.util.regex.Matcher;
24+
import java.util.regex.Pattern;
1925

2026
/**
2127
* @author intr3p1d
@@ -26,17 +32,76 @@ public class CLPMapper {
2632
public final static char DICTIONARY_VARIABLE_VALUE = '\u0011';
2733
public final static char NON_DICTIONARY_VALUE = '\u0012';
2834

29-
public final static String DICTIONARY_REPLACEMENT = "▨▨▨";
30-
public final static String NON_DICTIONARY_REPLACEMENT = "▧▧▧";
35+
public final static String DICTIONARY_REPLACEMENT = "<ClpPlaceHolder dict %d/>";
36+
public final static String NON_DICTIONARY_REPLACEMENT = "<ClpPlaceHolder non-dict %d/>";
37+
38+
public final static String SIMPLE_REPLACEMENT = "▨▨▨";
39+
40+
static String fixAndEscapeLogType(String encodedLogType) {
41+
return replaceDictPlaceHolder(replaceNonDictPlaceHolder(
42+
escapeXml(correctEncoding(
43+
encodedLogType
44+
))
45+
));
46+
}
47+
48+
static String processEncodedLogType(String encodedLogType) {
49+
return replaceSimple(correctEncoding(
50+
encodedLogType
51+
));
52+
}
3153

32-
static String makeReadableString(String encodedLogType) {
33-
byte[] encodedLogTypeBytes = encodedLogType.getBytes(StandardCharsets.ISO_8859_1);
54+
static String correctEncoding(String isoString) {
55+
byte[] encodedLogTypeBytes = isoString.getBytes(StandardCharsets.ISO_8859_1);
3456
return new String(encodedLogTypeBytes, StandardCharsets.UTF_8);
3557
}
3658

37-
static String replacePlaceHolders(String encodedLogType) {
38-
return encodedLogType
39-
.replaceAll(String.valueOf(DICTIONARY_VARIABLE_VALUE), DICTIONARY_REPLACEMENT)
40-
.replaceAll(String.valueOf(NON_DICTIONARY_VALUE), NON_DICTIONARY_REPLACEMENT);
59+
static String escapeXml(String rawString) {
60+
return StringEscapeUtils.escapeHtml4(rawString);
61+
}
62+
63+
static String replaceNonDictPlaceHolder(String encodedLogType) {
64+
return replaceHolder(
65+
encodedLogType,
66+
String.valueOf(NON_DICTIONARY_VALUE),
67+
x -> stringFunction(NON_DICTIONARY_REPLACEMENT, x)
68+
);
69+
}
70+
71+
static String replaceDictPlaceHolder(String encodedLogType) {
72+
return replaceHolder(
73+
encodedLogType,
74+
String.valueOf(DICTIONARY_VARIABLE_VALUE),
75+
x -> stringFunction(DICTIONARY_REPLACEMENT, x)
76+
);
77+
}
78+
79+
static String replaceSimple(String encodedLogType) {
80+
return replaceHolder(replaceHolder(
81+
encodedLogType,
82+
String.valueOf((DICTIONARY_VARIABLE_VALUE)),
83+
x -> stringFunction(SIMPLE_REPLACEMENT, x)
84+
),
85+
String.valueOf(NON_DICTIONARY_VALUE),
86+
x -> stringFunction(SIMPLE_REPLACEMENT, x)
87+
);
88+
}
89+
90+
static String stringFunction(String format, int index) {
91+
return String.format(format, index);
92+
}
93+
94+
static String replaceHolder(String encodedLogType, String replacedCharacter, Function<Integer, String> replacement) {
95+
Pattern pattern = Pattern.compile(replacedCharacter);
96+
Matcher matcher = pattern.matcher(encodedLogType);
97+
StringBuilder result = new StringBuilder();
98+
int wordCount = 0;
99+
100+
while (matcher.find()) {
101+
matcher.appendReplacement(result, replacement.apply(wordCount++));
102+
}
103+
matcher.appendTail(result);
104+
105+
return result.toString();
41106
}
42107
}

0 commit comments

Comments
 (0)