Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client facing log metrics #738

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.stream.Collectors;

import static com.datorama.oss.timbermill.TaskIndexer.logErrorInEventsMap;
import static com.datorama.oss.timbermill.pipe.LocalOutputPipe.tryReportInputQueueMetricWithTag;

public class ElasticsearchUtil {
public static final String CLIENT = "client";
Expand Down Expand Up @@ -322,7 +323,11 @@ public static void drainAndIndex(BlockingQueue<Event> eventsQueue, TaskIndexer t
Collection<Event> unfilteredEvents = new ArrayList<>();
eventsQueue.drainTo(unfilteredEvents, maxElement);
Collection<Event> events = filterEvents(unfilteredEvents, skipEventsAtDrainFlag, notToSkipRegex);
KamonConstants.MESSAGES_IN_INPUT_QUEUE_RANGE_SAMPLER.withoutTags().decrement(events.size());
events.forEach(e -> {
if(!tryReportInputQueueMetricWithTag(e, false)) {
KamonConstants.MESSAGES_IN_INPUT_QUEUE_RANGE_SAMPLER.withoutTags().decrement();
}
});
logErrorInEventsMap(events.stream().filter(event -> event.getTaskId() != null).collect(Collectors.groupingBy(Event::getTaskId)), "drainAndIndex");

events.forEach(e -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.regex.Pattern;

public class LocalOutputPipe implements EventOutputPipe {

Expand All @@ -41,6 +42,7 @@ public class LocalOutputPipe implements EventOutputPipe {
private boolean stoppedRunning = false;
private static final Logger LOG = LoggerFactory.getLogger(LocalOutputPipe.class);
private LoadingCache<String, RateLimiter> rateLimiterMap;
private static String clientFacingEventsRegex = null;

private LocalOutputPipe(Builder builder) {
if (builder.elasticUrl == null){
Expand Down Expand Up @@ -121,10 +123,55 @@ public static void doPushEventToQueues(PersistenceHandler persistenceHandler, Bl
KamonConstants.MESSAGES_IN_OVERFLOWED_QUEUE_RANGE_SAMPLER.withoutTags().increment();
}
} else {
KamonConstants.MESSAGES_IN_INPUT_QUEUE_RANGE_SAMPLER.withoutTags().increment();
if(!tryReportInputQueueMetricWithTag(event, true)) {
KamonConstants.MESSAGES_IN_INPUT_QUEUE_RANGE_SAMPLER.withoutTags().increment();
}
}
}


public static boolean tryReportInputQueueMetricWithTag(Event event, boolean isIncrement) {
LOG.info("about to tryReportClientFacingInputQueueMetric for event name:{}", event.getName());
boolean success = false;
//todo: remove
// clientFacingEventsRegex = "(account_analytics.*)|(page_view.*)|(validate_login)|(last_workspace_update)|(interactive_dingo_query)|(widget_init)|(widget_rendered)|(page_load)|(iframe_route_states_log)|(workspace_analytics_average_query_load_time)|(top_workspace_analytics_orphan_count)|(workspace_analytics_orphan_count)";

if(clientFacingEventsRegex!=null && !StringUtils.isEmpty(event.getName())){
try {
if (Pattern.compile(clientFacingEventsRegex).matcher(event.getName()).matches()) {
if(isIncrement) {
KamonConstants.MESSAGES_IN_INPUT_QUEUE_RANGE_SAMPLER.withTag("client_facing", true).increment();
LOG.info("timbermill2.inputQueue.size.range.sampler event with name {} with tag client_facing=true incremented Grafana metric", event.getName());
}
else{
KamonConstants.MESSAGES_IN_INPUT_QUEUE_RANGE_SAMPLER.withTag("client_facing", true).decrement();
LOG.info("timbermill2.inputQueue.size.range.sampler event with name {} with tag client_facing=true decremented Grafana metric", event.getName());
}
} else {
if(isIncrement) {
KamonConstants.MESSAGES_IN_INPUT_QUEUE_RANGE_SAMPLER.withTag("client_facing", false).increment();
LOG.info("timbermill2.inputQueue.size.range.sampler event with name {} with tag client_facing=false incremented Grafana metric", event.getName());
}
else{
KamonConstants.MESSAGES_IN_INPUT_QUEUE_RANGE_SAMPLER.withTag("client_facing", false).decrement();
LOG.info("timbermill2.inputQueue.size.range.sampler event with name {} with tag client_facing=false decremented Grafana metric", event.getName());
}
}
success = true;
}
catch (Exception e) {
LOG.error("failed tryReportClientFacingInputQueueMetric, event name:{}, clientFacingEventsRegex:{}, exception:{}", event.getName(), clientFacingEventsRegex, e);
}
} else if(clientFacingEventsRegex==null){
LOG.info("ClientFacingEvents | LocalOutputPipe | clientFacingEventsRegex is null");//todo: remove log
}
else if(StringUtils.isEmpty(event.getName())){
LOG.info("tryReportClientFacingInputQueueMetric, event name is empty");//todo: remove log
}
LOG.info("done tryReportClientFacingInputQueueMetric for event name:{} with success:{}", event.getName(), success);
return success;
}

public void close() {
LOG.info("Gracefully shutting down Timbermill Server.");
keepRunning = false;
Expand Down Expand Up @@ -170,6 +217,14 @@ public void setRateLimiterMap(LoadingCache<String, RateLimiter> rateLimiterMap)
this.rateLimiterMap = rateLimiterMap;
}

public static String getClientFacingEventsRegex() {
return clientFacingEventsRegex;
}

public static void setClientFacingEventsRegex(String clientFacingEventsRegex) {
LocalOutputPipe.clientFacingEventsRegex = clientFacingEventsRegex;
}

public static class Builder {

Bulker bulker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class TimbermillService {
private CronsRunner cronsRunner = new CronsRunner();
private int eventsMaxElement;

private String clientFacingEventsRegex;
private static Pattern notToSkipRegexPattern = null;
private static Pattern metadataPatten = Pattern.compile("metadata.*");

Expand Down Expand Up @@ -116,6 +117,7 @@ public TimbermillService(@Value("${INDEX_BULK_SIZE:200000}") Integer indexBulkSi
@Value("${LIMIT_FOR_PERIOD:30000}") int limitForPeriod,
@Value("${LIMIT_REFRESH_PERIOD_MINUTES:1}") int limitRefreshPeriod,
@Value("${RATE_LIMITER_CAPACITY:1000000}") int rateLimiterCapacity,
@Value("${client.facing.events.regex:(account_analytics.*)|(page_view.*)|(validate_login)|(last_workspace_update)|(interactive_dingo_query)|(widget_init)|(widget_rendered)|(page_load)|(iframe_route_states_log)|(workspace_analytics_average_query_load_time)|(top_workspace_analytics_orphan_count)|(workspace_analytics_orphan_count)}") String clientFacingEventsRegex,
@Value("${skip.events.at.insert.flag:false}") boolean skipEventsAtInsertFlag,
@Value("${skip.events.at.drain.flag:false}") boolean skipEventsAtDrainFlag,
@Value("${not.to.skip.events.regex:.*}") String notToSkipRegex){
Expand Down Expand Up @@ -148,6 +150,15 @@ public TimbermillService(@Value("${INDEX_BULK_SIZE:200000}") Integer indexBulkSi
AbstractCacheHandler cacheHandler = CacheHandlerUtil.getCacheHandler(cacheStrategy, cacheParams);
this.eventsMaxElement = eventsMaxElement;
taskIndexer = new TaskIndexer(pluginsJson, daysRotation, es, timbermillVersion, cacheHandler);

if(!clientFacingEventsRegex.isEmpty()) {
LOG.info("ClientFacingEvents | TimbermillService | setting clientFacingEventsRegex:{}", clientFacingEventsRegex);
LocalOutputPipe.setClientFacingEventsRegex(clientFacingEventsRegex);
} else {
LOG.info("ClientFacingEvents | TimbermillService | NOT setting clientFacingEventsRegex because empty");

}

cronsRunner.runCrons(bulkPersistentFetchCronExp, eventsPersistentFetchCronExp, persistenceHandler, es, deletionCronExp,
eventsQueue, overflowedQueue, mergingCronExp, redisService, rateLimiterMap, indexMergerCronExp);
startQueueSpillerThread();
Expand Down
Loading