Skip to content

Commit

Permalink
[log] truncate collection request parameters to the first 10 items...
Browse files Browse the repository at this point in the history
...and remaining count
  • Loading branch information
cmark committed Nov 22, 2020
1 parent 405010f commit df069b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.b2international.commons.StringUtils;
import com.b2international.snowowl.core.ServiceProvider;
import com.b2international.snowowl.core.events.DelegatingRequest;
import com.b2international.snowowl.core.events.Request;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tags;
Expand Down Expand Up @@ -53,7 +54,7 @@ public R execute(ServiceProvider context) {
final Tags tags = Tags.of("context", getContextId());
tags.and("context", DEFAULT_CONTEXT_ID);
final long responseTime = responseTimeSample.stop(registry.timer("response_time", tags));
final Map<String, Object> additionalInfo = ImmutableMap.of("metrics", ImmutableMap.of("responseTime", TimeUnit.NANOSECONDS.toMillis(responseTime)));
final Map<String, Object> additionalInfo = Map.of("metrics", Map.of("responseTime", TimeUnit.NANOSECONDS.toMillis(responseTime)));
LOG.info(getMessage(context, additionalInfo));
}
}
Expand All @@ -63,10 +64,23 @@ private String getMessage(ServiceProvider context, final Map<String, Object> add
final ObjectMapper mapper = context.service(ObjectMapper.class);
final Map<String, Object> body = mapper.convertValue(next(), Map.class);
body.putAll(additionalInfo);
return mapper.writeValueAsString(body);
return mapper.writeValueAsString(truncateArrays(body));
} catch (Throwable e) {
return "Unable to get request description: " + e.getMessage();
}
}

private Map<String, Object> truncateArrays(Map<String, Object> json) {
return Maps.transformValues(json, propertyValue -> {
if (propertyValue instanceof Map<?, ?>) {
return truncateArrays((Map<String, Object>) propertyValue);
} else if (propertyValue instanceof Iterable<?>) {
// TODO support arrays
return StringUtils.limitedToString((Iterable<?>) propertyValue, 10);
} else {
return propertyValue;
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import javax.validation.constraints.NotNull;

import com.b2international.commons.CompareUtils;
import com.b2international.commons.StringUtils;
import com.b2international.commons.options.Options;
import com.b2international.commons.options.OptionsBuilder;
import com.b2international.snowowl.core.ServiceProvider;
Expand Down Expand Up @@ -259,18 +258,11 @@ protected final Options options() {
return options;
}

@JsonProperty
protected final Set<String> componentIds() {
return componentIds;
}

/**
* @return
*/
@JsonProperty("componentIds")
String getTruncatedComponentIdValues() {
return componentIds == null ? null : StringUtils.limitedToString(componentIds, 10);
}

protected final boolean containsKey(Enum<?> key) {
return options.containsKey(key.name());
}
Expand Down

0 comments on commit df069b0

Please sign in to comment.