Skip to content

Commit c43f848

Browse files
committed
[#noissue] Handle PinotResultSet implicitly convert "null" to null
1 parent e9811ea commit c43f848

File tree

9 files changed

+111
-29
lines changed

9 files changed

+111
-29
lines changed

‎exceptiontrace/exceptiontrace-common/src/main/java/com/navercorp/pinpoint/exceptiontrace/common/model/ExceptionMetaData.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
package com.navercorp.pinpoint.exceptiontrace.common.model;
1818

1919
import com.navercorp.pinpoint.common.server.util.StringPrecondition;
20+
import com.navercorp.pinpoint.common.util.StringUtils;
2021
import com.navercorp.pinpoint.exceptiontrace.common.util.HashUtils;
2122

2223

2324
import java.util.List;
25+
import java.util.Objects;
2426

2527
/**
2628
* @author intr3p1d
@@ -77,7 +79,7 @@ public ExceptionMetaData(
7779
this.agentId = StringPrecondition.requireHasLength(agentId, "agentId");
7880
this.uriTemplate = uriTemplate;
7981
this.errorClassName = StringPrecondition.requireHasLength(errorClassName, "errorClassName");
80-
this.errorMessage = StringPrecondition.requireHasLength(errorMessage, "errorMessage");
82+
this.errorMessage = StringUtils.defaultString(errorMessage, "null");
8183
this.exceptionDepth = exceptionDepth;
8284
this.stackTrace = stackTrace;
8385
this.stackTraceHash = stackTraceHash;

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,21 @@ public ExceptionMetaData getException(ExceptionTraceQueryParameter exceptionTrac
8888
public List<ExceptionTraceSummary> getSummaries(ExceptionTraceQueryParameter exceptionTraceQueryParameter) {
8989
List<ExceptionTraceSummaryEntity> entities = this.sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_SUMMARIES_QUERY, exceptionTraceQueryParameter);
9090
return entities.stream()
91-
.map(mapper::entityToExceptionTraceSummary)
92-
.collect(Collectors.toList());
91+
.map((ExceptionTraceSummaryEntity e) ->
92+
mapper.toSummary(
93+
e, exceptionTraceQueryParameter.getGroupByAttributes()
94+
)
95+
).collect(Collectors.toList());
9396
}
9497

9598
@Override
9699
public List<ExceptionTraceValueView> getValueViews(ExceptionTraceQueryParameter exceptionTraceQueryParameter) {
97100
List<ExceptionTraceValueViewEntity> valueViewEntities = this.sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_VALUEVIEWS_QUERY, exceptionTraceQueryParameter);
98101
return valueViewEntities.stream()
99-
.map(mapper::entityToExceptionTraceValueView)
100-
.collect(Collectors.toList());
102+
.map((ExceptionTraceValueViewEntity e) ->
103+
mapper.toValueView(
104+
e, exceptionTraceQueryParameter.getGroupByAttributes()
105+
)
106+
).collect(Collectors.toList());
101107
}
102108
}

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

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,29 @@
1616
package com.navercorp.pinpoint.exceptiontrace.web.mapper;
1717

1818
import com.navercorp.pinpoint.common.server.mapper.MapStructUtils;
19+
import com.navercorp.pinpoint.common.util.StringUtils;
1920
import com.navercorp.pinpoint.exceptiontrace.common.model.ExceptionMetaData;
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.entity.GroupedFieldNameEntity;
2425
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceSummary;
2526
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceValueView;
27+
import com.navercorp.pinpoint.exceptiontrace.web.model.Grouped;
28+
import com.navercorp.pinpoint.exceptiontrace.web.model.GroupedFieldName;
29+
import com.navercorp.pinpoint.exceptiontrace.web.util.GroupByAttributes;
2630
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionMetaDataView;
31+
import org.mapstruct.AfterMapping;
32+
import org.mapstruct.CollectionMappingStrategy;
2733
import org.mapstruct.InjectionStrategy;
2834
import org.mapstruct.Mapper;
2935
import org.mapstruct.Mapping;
36+
import org.mapstruct.MappingTarget;
3037
import org.mapstruct.Mappings;
3138
import org.mapstruct.Named;
3239

40+
import java.util.List;
41+
3342
import static com.navercorp.pinpoint.exceptiontrace.web.mapper.CLPMapper.makeReadableString;
3443
import static com.navercorp.pinpoint.exceptiontrace.web.mapper.CLPMapper.replacePlaceHolders;
3544

@@ -39,6 +48,7 @@
3948
@Mapper(
4049
componentModel = "spring",
4150
injectionStrategy = InjectionStrategy.CONSTRUCTOR,
51+
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
4252
uses = {
4353
StackTraceMapper.class,
4454
MapStructUtils.class
@@ -57,21 +67,40 @@ public interface ExceptionMetaDataEntityMapper {
5767
ExceptionMetaDataView toView(ExceptionMetaDataEntity entity);
5868

5969
@Mappings({
60-
@Mapping(source = "values", target = "values", qualifiedBy = MapStructUtils.JsonStrToList.class),
61-
@Mapping(source = "uriTemplate", target = "groupedFieldName.uriTemplate"),
62-
@Mapping(source = "errorClassName", target = "groupedFieldName.errorClassName"),
63-
@Mapping(source = ".", target = "groupedFieldName.errorMessage", qualifiedByName = "selectErrorMessage"),
64-
@Mapping(source = "stackTraceHash", target = "groupedFieldName.stackTraceHash")
70+
@Mapping(source = "entity.values", target = "values", qualifiedBy = MapStructUtils.JsonStrToList.class),
71+
@Mapping(target = "tags", ignore = true),
72+
@Mapping(target = "groupedFieldName", ignore = true),
6573
})
66-
ExceptionTraceValueView entityToExceptionTraceValueView(ExceptionTraceValueViewEntity entity);
74+
ExceptionTraceValueView toValueView(
75+
ExceptionTraceValueViewEntity entity,
76+
List<GroupByAttributes> attributesList
77+
);
6778

6879
@Mappings({
69-
@Mapping(source = "uriTemplate", target = "groupedFieldName.uriTemplate"),
70-
@Mapping(source = "errorClassName", target = "groupedFieldName.errorClassName"),
71-
@Mapping(source = ".", target = "groupedFieldName.errorMessage", qualifiedByName = "selectErrorMessage"),
72-
@Mapping(source = "stackTraceHash", target = "groupedFieldName.stackTraceHash")
80+
@Mapping(target = "groupedFieldName", ignore = true),
7381
})
74-
ExceptionTraceSummary entityToExceptionTraceSummary(ExceptionTraceSummaryEntity entity);
82+
ExceptionTraceSummary toSummary(
83+
ExceptionTraceSummaryEntity entity,
84+
List<GroupByAttributes> attributesList
85+
);
86+
87+
@AfterMapping
88+
default void addGroupedFieldName(
89+
GroupedFieldNameEntity entity,
90+
List<GroupByAttributes> attributesList,
91+
@MappingTarget Grouped grouped
92+
) {
93+
GroupedFieldName groupedFieldName = new GroupedFieldName();
94+
for (GroupByAttributes attributes : attributesList) {
95+
switch (attributes) {
96+
case STACK_TRACE -> groupedFieldName.setStackTraceHash(checkIfNull(entity.getStackTraceHash()));
97+
case URI_TEMPLATE -> groupedFieldName.setUriTemplate(checkIfNull(entity.getUriTemplate()));
98+
case ERROR_CLASS_NAME -> groupedFieldName.setErrorClassName(checkIfNull(entity.getErrorClassName()));
99+
case ERROR_MESSAGE_LOG_TYPE -> groupedFieldName.setErrorMessage(checkIfNull(selectErrorMessage(entity)));
100+
}
101+
}
102+
grouped.setGroupedFieldName(groupedFieldName);
103+
}
75104

76105
@Named("selectErrorMessage")
77106
default String selectErrorMessage(GroupedFieldNameEntity entity) {
@@ -82,4 +111,8 @@ default String selectErrorMessage(GroupedFieldNameEntity entity) {
82111
}
83112
return entity.getErrorMessage();
84113
}
114+
115+
default String checkIfNull(String s) {
116+
return StringUtils.defaultString(s, "null");
117+
}
85118
}

‎exceptiontrace/exceptiontrace-web/src/main/java/com/navercorp/pinpoint/exceptiontrace/web/model/ExceptionTraceSummary.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* @author intr3p1d
2222
*/
23-
public class ExceptionTraceSummary {
23+
public class ExceptionTraceSummary implements Grouped {
2424

2525
private GroupedFieldName groupedFieldName;
2626
private String mostRecentErrorClass;

‎exceptiontrace/exceptiontrace-web/src/main/java/com/navercorp/pinpoint/exceptiontrace/web/model/ExceptionTraceValueView.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
/**
2626
* @author intr3p1d
2727
*/
28-
public class ExceptionTraceValueView implements TimeSeriesValueView {
28+
public class ExceptionTraceValueView implements TimeSeriesValueView, Grouped {
2929

30-
private static final String TOTAL_FIELDNAME = "total";
31-
private static final String EMPTY_STRING = "";
30+
public static final String TOTAL_FIELDNAME = "total";
31+
public static final String EMPTY_STRING = "(empty error message)";
3232
private GroupedFieldName groupedFieldName;
3333
private List<Integer> values;
3434

@@ -44,7 +44,10 @@ public String getFieldName() {
4444
if (groupedFieldName == null) {
4545
return TOTAL_FIELDNAME;
4646
}
47-
return StringUtils.defaultString(groupedFieldName.inAString(), TOTAL_FIELDNAME);
47+
return StringUtils.defaultIfEmpty(
48+
StringUtils.defaultString(groupedFieldName.inAString(), TOTAL_FIELDNAME),
49+
EMPTY_STRING
50+
);
4851
}
4952

5053
@JsonIgnore
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.model;
17+
18+
/**
19+
* @author intr3p1d
20+
*/
21+
public interface Grouped {
22+
GroupedFieldName getGroupedFieldName();
23+
void setGroupedFieldName(GroupedFieldName groupedFieldName);
24+
}

‎exceptiontrace/exceptiontrace-web/src/main/java/com/navercorp/pinpoint/exceptiontrace/web/util/ExceptionTraceQueryParameter.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ protected ExceptionTraceQueryParameter(
7070
this.timeWindowRangeCount = builder.timeWindowRangeCount;
7171
}
7272

73+
public List<GroupByAttributes> getGroupByAttributes() {
74+
return groupByAttributes;
75+
}
76+
7377
public static class Builder extends QueryParameter.Builder<Builder> {
7478

7579
private static final int MAX_LIMIT = 65536;

‎exceptiontrace/exceptiontrace-web/src/test/java/com/navercorp/pinpoint/exceptiontrace/web/mapper/ExceptionMetaDataEntityMapperTest.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.navercorp.pinpoint.exceptiontrace.web.entity.GroupedFieldNameEntity;
1111
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceSummary;
1212
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceValueView;
13+
import com.navercorp.pinpoint.exceptiontrace.web.util.GroupByAttributes;
1314
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionMetaDataView;
1415
import org.apache.logging.log4j.LogManager;
1516
import org.apache.logging.log4j.Logger;
@@ -180,7 +181,9 @@ public <T> List<T> convertToList(String json) {
180181
public void testEntityToValueView() {
181182
ExceptionTraceValueViewEntity expected = newExceptionMetaDataEntity();
182183

183-
ExceptionTraceValueView actual = mapper.entityToExceptionTraceValueView(expected);
184+
ExceptionTraceValueView actual = mapper.toValueView(
185+
expected, List.of(GroupByAttributes.values())
186+
);
184187

185188
assertEquals(expected.getUriTemplate(), actual.getGroupedFieldName().getUriTemplate());
186189
assertEquals(expected.getErrorClassName(), actual.getGroupedFieldName().getErrorClassName());
@@ -208,7 +211,9 @@ private ExceptionTraceValueViewEntity newExceptionMetaDataEntity() {
208211
public void testEntityToSummary() {
209212
ExceptionTraceSummaryEntity expected = newExceptionTraceSummaryEntity();
210213

211-
ExceptionTraceSummary actual = mapper.entityToExceptionTraceSummary(expected);
214+
ExceptionTraceSummary actual = mapper.toSummary(
215+
expected, List.of(GroupByAttributes.values())
216+
);
212217

213218
assertEquals(expected.getMostRecentErrorClass(), actual.getMostRecentErrorClass());
214219
assertEquals(expected.getMostRecentErrorMessage(), actual.getMostRecentErrorMessage());
@@ -239,14 +244,14 @@ private ExceptionTraceSummaryEntity newExceptionTraceSummaryEntity() {
239244
}
240245

241246
@Test
242-
public void testSelectErrorMessage(){
247+
public void testSelectErrorMessage() {
243248
GroupedFieldNameEntity entity = new GroupedFieldNameEntity();
244249
entity.setErrorMessage_logtype("getAgentsList.from: \u0011 ì\u009D´ì\u0083\u0081ì\u009D´ì\u0096´ì\u0095¼ í\u0095©ë\u008B\u0088ë\u008B¤");
245250

246251
String result = mapper.selectErrorMessage(entity);
247252
assertEquals(
248-
"getAgentsList.from: "+ CLPMapper.DICTIONARY_REPLACEMENT +" 이상이���야 합니다"
249-
,result
253+
"getAgentsList.from: " + CLPMapper.DICTIONARY_REPLACEMENT + " 이상이어야 합니다"
254+
, result
250255
);
251256
}
252257
}

‎exceptiontrace/exceptiontrace-web/src/test/java/com/navercorp/pinpoint/exceptiontrace/web/model/ExceptionTraceValueViewTest.java‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ void testGetFieldName() {
1717
emptyFieldName.setErrorMessage("");
1818
view.setGroupedFieldName(emptyFieldName);
1919

20-
assertEquals("", view.getFieldName());
20+
assertEquals(ExceptionTraceValueView.EMPTY_STRING, view.getFieldName());
2121

22+
GroupedFieldName nullStringFieldName = new GroupedFieldName();
23+
emptyFieldName.setErrorMessage("null");
24+
view.setGroupedFieldName(emptyFieldName);
25+
26+
assertEquals(ExceptionTraceValueView.EMPTY_STRING, view.getFieldName());
2227

2328
GroupedFieldName nullFieldName = new GroupedFieldName();
2429
view.setGroupedFieldName(nullFieldName);
2530

26-
assertEquals("total", view.getFieldName());
31+
assertEquals(ExceptionTraceValueView.TOTAL_FIELDNAME, view.getFieldName());
2732

2833

2934
view.setGroupedFieldName(null);
3035

31-
assertEquals("total", view.getFieldName());
36+
assertEquals(ExceptionTraceValueView.TOTAL_FIELDNAME, view.getFieldName());
3237
}
3338
}

0 commit comments

Comments
 (0)