Skip to content

Commit 237e613

Browse files
committed
[#9631] Add API to retrieve CLP replaced tokens with count and ordering
1 parent a0a92c9 commit 237e613

File tree

17 files changed

+555
-52
lines changed

17 files changed

+555
-52
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
@@ -15,11 +15,13 @@
1515
*/
1616
package com.navercorp.pinpoint.exceptiontrace.web.config;
1717

18+
import com.navercorp.pinpoint.exceptiontrace.web.entity.ClpConvertedEntity;
1819
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionMetaDataEntity;
1920
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionTraceSummaryEntity;
2021
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionTraceValueViewEntity;
2122
import com.navercorp.pinpoint.exceptiontrace.web.entity.GroupedFieldNameEntity;
22-
import com.navercorp.pinpoint.exceptiontrace.web.util.ExceptionTraceQueryParameter;
23+
import com.navercorp.pinpoint.exceptiontrace.web.query.ClpQueryParameter;
24+
import com.navercorp.pinpoint.exceptiontrace.web.query.ExceptionTraceQueryParameter;
2325
import com.navercorp.pinpoint.mybatis.MyBatisRegistryHandler;
2426
import org.apache.ibatis.type.TypeAliasRegistry;
2527
import org.apache.ibatis.type.TypeHandlerRegistry;
@@ -34,7 +36,9 @@ public void registerTypeAlias(TypeAliasRegistry typeAliasRegistry) {
3436
typeAliasRegistry.registerAlias(GroupedFieldNameEntity.class);
3537
typeAliasRegistry.registerAlias(ExceptionTraceSummaryEntity.class);
3638
typeAliasRegistry.registerAlias(ExceptionTraceValueViewEntity.class);
39+
typeAliasRegistry.registerAlias(ClpConvertedEntity.class);
3740
typeAliasRegistry.registerAlias(ExceptionTraceQueryParameter.class);
41+
typeAliasRegistry.registerAlias(ClpQueryParameter.class);
3842
}
3943

4044
@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
@@ -18,10 +18,12 @@
1818

1919
import com.navercorp.pinpoint.common.server.util.time.Range;
2020
import com.navercorp.pinpoint.common.server.util.time.RangeValidator;
21+
import com.navercorp.pinpoint.exceptiontrace.web.model.ClpConverted;
2122
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceSummary;
2223
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceValueView;
24+
import com.navercorp.pinpoint.exceptiontrace.web.query.ClpQueryParameter;
2325
import com.navercorp.pinpoint.exceptiontrace.web.service.ExceptionTraceService;
24-
import com.navercorp.pinpoint.exceptiontrace.web.util.ExceptionTraceQueryParameter;
26+
import com.navercorp.pinpoint.exceptiontrace.web.query.ExceptionTraceQueryParameter;
2527
import com.navercorp.pinpoint.exceptiontrace.web.util.GroupByAttributes;
2628
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionMetaDataView;
2729
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionTraceView;
@@ -159,6 +161,37 @@ public List<ExceptionTraceSummary> getListOfExceptionMetaDataWithDynamicGroupBy(
159161
);
160162
}
161163

164+
@GetMapping("/replacedTokens")
165+
public List<ClpConverted> getReplacedVariables(
166+
@RequestParam("applicationName") @NotBlank String applicationName,
167+
@RequestParam(value = "agentId", required = false) String agentId,
168+
@RequestParam("from") @PositiveOrZero long from,
169+
@RequestParam("to") @PositiveOrZero long to,
170+
171+
@RequestParam("logType") String logType,
172+
@RequestParam("targetColumn") String targetColumn,
173+
@RequestParam("targetIndex") int targetIndex
174+
) {
175+
Range range = Range.between(from, to);
176+
rangeValidator.validate(range);
177+
178+
ClpQueryParameter queryParameter = new ClpQueryParameter.Builder()
179+
.setTableName(tableName)
180+
.setTenantId(tenantProvider.getTenantId())
181+
.setApplicationName(applicationName)
182+
.setAgentId(agentId)
183+
.setRange(Range.between(from, to))
184+
.setTimePrecision(DETAILED_TIME_PRECISION)
185+
.setLogType(logType)
186+
.setTargetColumn(targetColumn)
187+
.setTargetIndex(targetIndex)
188+
.build();
189+
190+
return exceptionTraceService.getReplacedVariables(
191+
queryParameter
192+
);
193+
}
194+
162195
@GetMapping("/chart")
163196
public ExceptionTraceView getCollectedExceptionMetaDataByGivenRange(
164197
@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
@@ -18,9 +18,11 @@
1818

1919

2020
import com.navercorp.pinpoint.exceptiontrace.common.model.ExceptionMetaData;
21+
import com.navercorp.pinpoint.exceptiontrace.web.model.ClpConverted;
2122
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceSummary;
2223
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceValueView;
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.exceptiontrace.web.view.ExceptionMetaDataView;
2527

2628
import java.util.List;
@@ -34,4 +36,5 @@ public interface ExceptionTraceDao {
3436
ExceptionMetaData getException(ExceptionTraceQueryParameter exceptionTraceQueryParameter);
3537
List<ExceptionTraceSummary> getSummaries(ExceptionTraceQueryParameter exceptionTraceQueryParameter);
3638
List<ExceptionTraceValueView> getValueViews(ExceptionTraceQueryParameter exceptionTraceQueryParameter);
39+
List<ClpConverted> getReplacedVariables(ClpQueryParameter queryParameter);
3740
}

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
@@ -17,13 +17,16 @@
1717
package com.navercorp.pinpoint.exceptiontrace.web.dao;
1818

1919
import com.navercorp.pinpoint.exceptiontrace.common.model.ExceptionMetaData;
20+
import com.navercorp.pinpoint.exceptiontrace.web.entity.ClpConvertedEntity;
2021
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionMetaDataEntity;
2122
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionTraceSummaryEntity;
2223
import com.navercorp.pinpoint.exceptiontrace.web.entity.ExceptionTraceValueViewEntity;
2324
import com.navercorp.pinpoint.exceptiontrace.web.mapper.ExceptionMetaDataEntityMapper;
25+
import com.navercorp.pinpoint.exceptiontrace.web.model.ClpConverted;
2426
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceSummary;
2527
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceValueView;
26-
import com.navercorp.pinpoint.exceptiontrace.web.util.ExceptionTraceQueryParameter;
28+
import com.navercorp.pinpoint.exceptiontrace.web.query.ClpQueryParameter;
29+
import com.navercorp.pinpoint.exceptiontrace.web.query.ExceptionTraceQueryParameter;
2730
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionMetaDataView;
2831
import org.apache.logging.log4j.LogManager;
2932
import org.apache.logging.log4j.Logger;
@@ -49,6 +52,7 @@ public class PinotExceptionTraceDao implements ExceptionTraceDao {
4952
private static final String SELECT_EXACT_QUERY = "selectExactException";
5053
private static final String SELECT_SUMMARIES_QUERY = "selectSummaries";
5154
private static final String SELECT_VALUEVIEWS_QUERY = "selectValueViews";
55+
private static final String SELECT_CLP_VARIABLES_QUERY = "selectClpVariables";
5256

5357
private final SqlSessionTemplate sqlPinotSessionTemplate;
5458

@@ -105,4 +109,13 @@ public List<ExceptionTraceValueView> getValueViews(ExceptionTraceQueryParameter
105109
)
106110
).collect(Collectors.toList());
107111
}
112+
113+
@Override
114+
public List<ClpConverted> getReplacedVariables(ClpQueryParameter queryParameter) {
115+
List<ClpConvertedEntity> clpConvertedEntities = this.sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_CLP_VARIABLES_QUERY, queryParameter);
116+
117+
return clpConvertedEntities.stream()
118+
.map(mapper::toClpConverted)
119+
.collect(Collectors.toList());
120+
}
108121
}
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)