-
Notifications
You must be signed in to change notification settings - Fork 96
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
logging for cache put failures #1114
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2016 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
// | ||
package com.yahoo.bard.webservice.logging.blocks; | ||
|
||
import com.yahoo.bard.webservice.logging.LogInfo; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
|
||
/** | ||
* Log that keep tracks for cache set failures. | ||
*/ | ||
@JsonAutoDetect(getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY) | ||
public class BardCacheInfo implements LogInfo { | ||
String cacheKeyCksum; | ||
int cacheKeyLength; | ||
int cacheValLength; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param cacheKeyLength The Length of the cache key | ||
* @param cacheKeyCksum The cache Key MD5 checksum value | ||
* @param cacheValLength The cache value length | ||
*/ | ||
public BardCacheInfo(int cacheKeyLength, String cacheKeyCksum, int cacheValLength) { | ||
this.cacheKeyLength = cacheKeyLength; | ||
this.cacheKeyCksum = cacheKeyCksum; | ||
this.cacheValLength = cacheValLength; | ||
bharatmotwani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,23 +6,34 @@ | |
import static com.yahoo.bard.webservice.web.handlers.PartialDataRequestHandler.getPartialIntervalsWithDefault; | ||
import static com.yahoo.bard.webservice.web.handlers.VolatileDataRequestHandler.getVolatileIntervalsWithDefault; | ||
|
||
import com.yahoo.bard.webservice.application.MetricRegistryFactory; | ||
import com.yahoo.bard.webservice.config.SystemConfig; | ||
import com.yahoo.bard.webservice.config.SystemConfigProvider; | ||
import com.yahoo.bard.webservice.data.cache.TupleDataCache; | ||
import com.yahoo.bard.webservice.druid.client.FailureCallback; | ||
import com.yahoo.bard.webservice.druid.client.HttpErrorCallback; | ||
import com.yahoo.bard.webservice.druid.model.query.DruidAggregationQuery; | ||
import com.yahoo.bard.webservice.logging.RequestLog; | ||
import com.yahoo.bard.webservice.logging.blocks.BardCacheInfo; | ||
import com.yahoo.bard.webservice.metadata.QuerySigningService; | ||
import com.yahoo.bard.webservice.util.SimplifiedIntervalList; | ||
|
||
import com.codahale.metrics.Meter; | ||
import com.codahale.metrics.MetricRegistry; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectWriter; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Locale; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.xml.bind.DatatypeConverter; | ||
|
||
/** | ||
* A response processor which caches the results if appropriate after completing a query. | ||
|
@@ -31,6 +42,8 @@ public class CacheV2ResponseProcessor implements ResponseProcessor { | |
|
||
private static final Logger LOG = LoggerFactory.getLogger(CacheV2ResponseProcessor.class); | ||
private static final SystemConfig SYSTEM_CONFIG = SystemConfigProvider.getInstance(); | ||
private static final MetricRegistry REGISTRY = MetricRegistryFactory.getRegistry(); | ||
public static final Meter CACHE_SET_FAILURES = REGISTRY.meter("queries.meter.cache.put.failures"); | ||
|
||
private final long maxDruidResponseLengthToCache = SYSTEM_CONFIG.getLongProperty( | ||
SYSTEM_CONFIG.getPackageVariableName( | ||
|
@@ -105,6 +118,13 @@ public void processResponse(JsonNode json, DruidAggregationQuery<?> druidQuery, | |
); | ||
} | ||
} catch (Exception e) { | ||
//mark and log the cache put failure | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could use a test. |
||
CACHE_SET_FAILURES.mark(1); | ||
RequestLog.record(new BardCacheInfo( | ||
cacheKey.length(), | ||
getMD5Cksum(cacheKey), | ||
valueString != null ? valueString.length() : 0 | ||
)); | ||
LOG.warn( | ||
"Unable to cache {}value of size: {}", | ||
valueString == null ? "null " : "", | ||
|
@@ -128,4 +148,41 @@ protected boolean isCacheable() { | |
|
||
return missingIntervals.isEmpty() && volatileIntervals.isEmpty(); | ||
} | ||
|
||
/** | ||
* Generate the Checksum of cacheKey using MD5 algorithm. | ||
* @param cacheKey cache key | ||
* | ||
* @return String representation of the Cksum | ||
*/ | ||
public static String getMD5Cksum(String cacheKey) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be better injected. |
||
try { | ||
MessageDigest digest = MessageDigest.getInstance("MD5"); | ||
byte[] hash = digest.digest(cacheKey.getBytes("UTF-8")); | ||
return bytesToHex(hash); // make it readable | ||
} catch (NoSuchAlgorithmException ex) { | ||
String msg = "Unable to initialize hash generator with default MD5 algorithm "; | ||
LOG.warn(msg, ex); | ||
throw new RuntimeException(msg, ex); | ||
} catch (UnsupportedEncodingException x) { | ||
String msg = "Unable to initialize checksum byte array "; | ||
LOG.warn(msg, x); | ||
throw new RuntimeException(msg, x); | ||
} catch (Exception exception) { | ||
String msg = "Failed to generate checksum for cache key"; | ||
LOG.warn(msg, exception); | ||
throw new RuntimeException(msg, exception); | ||
} | ||
} | ||
|
||
/** | ||
* Converts bytes array to the hex String. | ||
* @param hash array of bytes to be converted in Hex | ||
* | ||
* @return String representation of the checksum | ||
*/ | ||
public static String bytesToHex(byte[] hash) { | ||
return DatatypeConverter.printHexBinary(hash) | ||
.toLowerCase(Locale.ENGLISH); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import com.fasterxml.jackson.databind.ObjectWriter; | ||
import com.yahoo.bard.webservice.config.SystemConfig; | ||
import com.yahoo.bard.webservice.config.SystemConfigProvider; | ||
import com.yahoo.bard.webservice.logging.blocks.BardCacheInfo; | ||
import com.yahoo.bard.webservice.util.SimplifiedIntervalList; | ||
import com.yahoo.bard.webservice.application.MetricRegistryFactory; | ||
import com.yahoo.bard.webservice.data.cache.TupleDataCache; | ||
|
@@ -22,6 +23,7 @@ | |
import com.yahoo.bard.webservice.metadata.QuerySigningService; | ||
import com.yahoo.bard.webservice.util.Utils; | ||
import com.yahoo.bard.webservice.web.handlers.RequestContext; | ||
import com.yahoo.bard.webservice.web.responseprocessors.CacheV2ResponseProcessor; | ||
import com.yahoo.bard.webservice.web.responseprocessors.ResponseProcessor; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
@@ -53,6 +55,7 @@ public class QuerySignedCacheService implements CacheService { | |
public static final Meter CACHE_POTENTIAL_HITS = REGISTRY.meter("queries.meter.cache.potential_hits"); | ||
public static final Meter CACHE_MISSES = REGISTRY.meter("queries.meter.cache.misses"); | ||
public static final Meter CACHE_REQUESTS = REGISTRY.meter("queries.meter.cache.total"); | ||
public static final Meter CACHE_SET_FAILURES = REGISTRY.meter("queries.meter.cache.put.failures"); | ||
|
||
TupleDataCache<String, Long, String> dataCache; | ||
QuerySigningService<Long> querySigningService; | ||
|
@@ -148,6 +151,13 @@ public void writeCache( | |
); | ||
} | ||
} catch (Exception e) { | ||
//mark and log the cache put failure | ||
CACHE_SET_FAILURES.mark(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could use a test. |
||
RequestLog.record(new BardCacheInfo( | ||
cacheKey.length(), | ||
CacheV2ResponseProcessor.getMD5Cksum(cacheKey), | ||
valueString != null ? valueString.length() : 0 | ||
)); | ||
LOG.warn( | ||
"Unable to cache {}value of size: {}", | ||
valueString == null ? "null " : "", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two paths could use a test to guarantee config results in the correct behaviors.