Skip to content

Commit

Permalink
[#9631] Add new optional parameter filters to errorList API
Browse files Browse the repository at this point in the history
  • Loading branch information
intr3p1d committed May 9, 2024
1 parent 83b73d6 commit 5e83c54
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public List<ExceptionMetaDataView> getListOfExceptionMetaDataByGivenRange(
@RequestParam("from") @PositiveOrZero long from,
@RequestParam("to") @PositiveOrZero long to,

@RequestParam(value = "query", required = false) List<String> tags,
@RequestParam(value = "filters", required = false) List<String> filters,
@RequestParam("orderBy") String orderBy,
@RequestParam("isDesc") boolean isDesc,
@RequestParam("count") int count
Expand All @@ -124,6 +124,7 @@ public List<ExceptionMetaDataView> getListOfExceptionMetaDataByGivenRange(
.setRange(range)
.setTimePrecision(DETAILED_TIME_PRECISION)
.setHardLimit(count)
.addAllFilters(filters)
.setOrderBy(orderBy)
.setIsDesc(isDesc)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.navercorp.pinpoint.exceptiontrace.web.model.ExceptionTraceValueView;
import com.navercorp.pinpoint.exceptiontrace.web.model.Grouped;
import com.navercorp.pinpoint.exceptiontrace.web.model.GroupedFieldName;
import com.navercorp.pinpoint.exceptiontrace.web.model.RawGroupedFieldName;
import com.navercorp.pinpoint.exceptiontrace.web.util.GroupByAttributes;
import com.navercorp.pinpoint.exceptiontrace.web.view.ExceptionMetaDataView;
import org.mapstruct.AfterMapping;
Expand Down Expand Up @@ -78,12 +79,32 @@ ExceptionTraceValueView toValueView(

@Mappings({
@Mapping(target = "groupedFieldName", ignore = true),
@Mapping(source = "entity", target = "rawFieldName"),
})
ExceptionTraceSummary toSummary(
ExceptionTraceSummaryEntity entity,
List<GroupByAttributes> attributesList
);

@AfterMapping
default void addRawGroupedFieldName(
ExceptionTraceSummaryEntity entity,
List<GroupByAttributes> attributesList,
@MappingTarget ExceptionTraceSummary summary
) {
RawGroupedFieldName groupedFieldName = new RawGroupedFieldName();
for (GroupByAttributes attributes : attributesList) {
switch (attributes) {
case STACK_TRACE -> groupedFieldName.setStackTraceHash(checkIfNull(entity.getStackTraceHash()));
case URI_TEMPLATE -> groupedFieldName.setUriTemplate(checkIfNull(entity.getUriTemplate()));
case ERROR_CLASS_NAME -> groupedFieldName.setErrorClassName(checkIfNull(entity.getErrorClassName()));
case ERROR_MESSAGE_LOG_TYPE ->
groupedFieldName.setErrorMessage_logtype(checkIfNull(selectErrorMessage(entity)));
}
}
summary.setRawFieldName(groupedFieldName);
}

@AfterMapping
default void addGroupedFieldName(
GroupedFieldNameEntity entity,
Expand All @@ -96,7 +117,8 @@ default void addGroupedFieldName(
case STACK_TRACE -> groupedFieldName.setStackTraceHash(checkIfNull(entity.getStackTraceHash()));
case URI_TEMPLATE -> groupedFieldName.setUriTemplate(checkIfNull(entity.getUriTemplate()));
case ERROR_CLASS_NAME -> groupedFieldName.setErrorClassName(checkIfNull(entity.getErrorClassName()));
case ERROR_MESSAGE_LOG_TYPE -> groupedFieldName.setErrorMessage(checkIfNull(selectErrorMessage(entity)));
case ERROR_MESSAGE_LOG_TYPE ->
groupedFieldName.setErrorMessage(checkIfNull(selectErrorMessage(entity)));
}
}
grouped.setGroupedFieldName(groupedFieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public class ExceptionTraceSummary implements Grouped {

private GroupedFieldName groupedFieldName;
private RawGroupedFieldName rawFieldName;
private String mostRecentErrorClass;
private String mostRecentErrorMessage;
private long count;
Expand All @@ -41,6 +42,15 @@ public void setGroupedFieldName(GroupedFieldName groupedFieldName) {
this.groupedFieldName = groupedFieldName;
}

@JsonProperty("rawFieldName")
public RawGroupedFieldName getRawFieldName() {
return rawFieldName;
}

public void setRawFieldName(RawGroupedFieldName rawFieldName) {
this.rawFieldName = rawFieldName;
}

public String getMostRecentErrorClass() {
return mostRecentErrorClass;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.exceptiontrace.web.model;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
* @author intr3p1d
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RawGroupedFieldName {
private String uriTemplate;
private String errorClassName;
private String errorMessage_logtype;
private String stackTraceHash;


public String getUriTemplate() {
return uriTemplate;
}

public void setUriTemplate(String uriTemplate) {
this.uriTemplate = uriTemplate;
}

public String getErrorClassName() {
return errorClassName;
}

public void setErrorClassName(String errorClassName) {
this.errorClassName = errorClassName;
}

public String getErrorMessage_logtype() {
return errorMessage_logtype;
}

public void setErrorMessage_logtype(String errorMessage_logtype) {
this.errorMessage_logtype = errorMessage_logtype;
}

public String getStackTraceHash() {
return stackTraceHash;
}

public void setStackTraceHash(String stackTraceHash) {
this.stackTraceHash = stackTraceHash;
}


@Override
public String toString() {
return "RawGroupedFieldName{" +
"uriTemplate='" + uriTemplate + '\'' +
", errorClassName='" + errorClassName + '\'' +
", errorMessage_logtype='" + errorMessage_logtype + '\'' +
", stackTraceHash='" + stackTraceHash + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class ExceptionTraceQueryParameter extends QueryParameter {
private final OrderByAttributes orderBy;
private final String isDesc;
private final List<GroupByAttributes> groupByAttributes;
private final FilterByAttributes filterByAttributes;

private final long timeWindowRangeCount;

Expand All @@ -67,6 +68,7 @@ protected ExceptionTraceQueryParameter(
this.orderBy = builder.orderBy;
this.isDesc = builder.isDesc;
this.groupByAttributes = builder.groupByAttributes;
this.filterByAttributes = builder.filterByAttributes;
this.timeWindowRangeCount = builder.timeWindowRangeCount;
}

Expand Down Expand Up @@ -94,6 +96,7 @@ public static class Builder extends QueryParameter.Builder<Builder> {
private OrderByAttributes orderBy;
private String isDesc;
private final List<GroupByAttributes> groupByAttributes = new ArrayList<>();
private final FilterByAttributes filterByAttributes = new FilterByAttributes();

private long timeWindowRangeCount = 0;

Expand Down Expand Up @@ -182,11 +185,22 @@ public Builder addAllGroupByList(Collection<String> strings) {
GroupByAttributes::fromValue
)
.filter(Objects::nonNull)
.distinct().sorted().collect(Collectors.toList());
.distinct().sorted().toList();
this.groupByAttributes.addAll(groupByAttributesList);
return self();
}

public Builder addAllFilters(Collection<String> strings) {
if (strings == null) {
return self();
}
for (String string : strings) {
String[] tag = string.split(":", 2);
filterByAttributes.put(tag[0], tag[1]);
}
return self();
}

public long useLimitIfSet() {
if (hardLimit != null) {
return hardLimit;
Expand Down Expand Up @@ -216,7 +230,8 @@ public ExceptionTraceQueryParameter build() {
@Override
public String toString() {
return "ExceptionTraceQueryParameter{" +
"tenantId='" + tenantId + '\'' +
"tableName='" + tableName + '\'' +
", tenantId='" + tenantId + '\'' +
", applicationName='" + applicationName + '\'' +
", agentId='" + agentId + '\'' +
", transactionId='" + transactionId + '\'' +
Expand All @@ -226,6 +241,7 @@ public String toString() {
", orderBy=" + orderBy +
", isDesc='" + isDesc + '\'' +
", groupByAttributes=" + groupByAttributes +
", filterByAttributes=" + filterByAttributes +
", timeWindowRangeCount=" + timeWindowRangeCount +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.exceptiontrace.web.util;

import com.navercorp.pinpoint.common.server.util.EnumGetter;
import com.navercorp.pinpoint.exceptiontrace.common.pinot.PinotColumns;

import java.util.EnumMap;
import java.util.Map;

/**
* @author intr3p1d
*/
public class FilterByAttributes {

public enum FilterByColumn {
URI_TEMPLATE(PinotColumns.URI_TEMPLATE),
ERROR_MESSAGE_LOG_TYPE(PinotColumns.ERROR_MESSAGE_LOG_TYPE),
ERROR_CLASS_NAME(PinotColumns.ERROR_CLASS_NAME),
STACK_TRACE(PinotColumns.STACK_TRACE_HASH);

private static final EnumGetter<FilterByColumn> GETTER = new EnumGetter<>(FilterByColumn.class);

private final PinotColumns column;

FilterByColumn(PinotColumns column) {
this.column = column;
}

public PinotColumns getColumn() {
return column;
}

public static FilterByColumn fromValue(String column) {
return GETTER.fromValue((FilterByColumn x) -> x.getColumn().getName(), column);
}
}


private final Map<FilterByColumn, String> map = new EnumMap<>(FilterByColumn.class);

public void put(String column, String value) {
this.map.put(FilterByColumn.fromValue(column), value);
}

public Map<FilterByColumn, String> getMap() {
return map;
}

@Override
public String toString() {
return "FilterByAttributes{" +
"map=" + map +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
</foreach>
</sql>

<sql id="filterByGivenColumnsAndValue">
<foreach collection="filterByAttributes.getMap()" item="value" index="key" separator="">
AND ${key.column.name}=#{value}
</foreach>
</sql>

<sql id="getGroupedFieldNameEntity">
<choose>
<when test="!groupByAttributes.isEmpty()">
Expand Down Expand Up @@ -125,11 +131,7 @@
<if test="agentId != null">
AND agentId = #{agentId}
</if>
<if test="transactionId != null">
AND transactionId = #{transactionId}
AND spanId = #{spanId}
AND exceptionId = #{exceptionId}
</if>
<include refid="filterByGivenColumnsAndValue"></include>
ORDER BY ${orderBy.getAttributeName} ${isDesc}
LIMIT ${limit}
</select>
Expand Down

0 comments on commit 5e83c54

Please sign in to comment.