Fix metrics

This commit is contained in:
yo000 2024-02-04 13:07:19 +01:00
parent e1f6e0ad60
commit 4b032a90cf

View File

@ -73,7 +73,12 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
private final Meter redisGetRequestErrors;
private final Timer redisSetRequestTimer;
private final Meter redisSetRequestErrors;
private final Timer redisDelRequestTimer;
private final Meter redisDelRequestErrors;
private final Timer redisAssignTtlRequestTimer;
private final Meter redisAssignTtlRequestErrors;
private final Timer redisSetStringListRequestTimer;
private final Meter redisSetStringListRequestErrors;
@Inject
public RedisLookupDataAdapter(@Assisted("dto") DataAdapterDto dto,
@ -98,6 +103,12 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
this.redisGetRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisGetRequestErrors"));
this.redisSetRequestTimer = metricRegistry.timer(MetricRegistry.name(getClass(), "redisSetRequestTime"));
this.redisSetRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisSetRequestErrors"));
this.redisDelRequestTimer = metricRegistry.timer(MetricRegistry.name(getClass(), "redisDelRequestTime"));
this.redisDelRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisDelRequestErrors"));
this.redisAssignTtlRequestTimer = metricRegistry.timer(MetricRegistry.name(getClass(), "redisAssignTtlRequestTime"));
this.redisAssignTtlRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisAssignTtlRequestErrors"));
this.redisSetStringListRequestTimer = metricRegistry.timer(MetricRegistry.name(getClass(), "redisSetStringListRequestTime"));
this.redisSetStringListRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisSetStringListRequestErrors"));
}
@Override
@ -187,18 +198,18 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
@Override
public void clearKey(Object key) {
final Timer.Context time = redisSetRequestTimer.time();
final Timer.Context time = redisDelRequestTimer.time();
final String trimmedKey = StringUtils.trimToNull(key.toString());
try {
final Long result = this.commands.del(key.toString());
if (result != 1) {
LOG.debug("Redis DEL key <{}> returned {}", key, result);
redisSetRequestErrors.mark();
redisDelRequestErrors.mark();
}
return;
} catch (Exception e) {
LOG.error("Redis DEL key <{}> returned {}", key, e);
redisSetRequestErrors.mark();
redisDelRequestErrors.mark();
return;
} finally {
time.stop();
@ -237,7 +248,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
// TTL -1 = never expire
public LookupResult assignTtl(Object key, Long ttlSec) {
final Timer.Context time = redisSetRequestTimer.time();
final Timer.Context time = redisAssignTtlRequestTimer.time();
final String trimmedKey = StringUtils.trimToNull(key.toString());
try {
if (ttlSec > 0) {
@ -247,7 +258,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
}
} catch (Exception e) {
LOG.error("assignTtl <{}> to key <{}> returned {}", ttlSec, trimmedKey, e);
redisSetRequestErrors.mark();
redisAssignTtlRequestErrors.mark();
return LookupResult.withError();
} finally {
time.stop();