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