|
|
|
@ -16,6 +16,20 @@
|
|
|
|
|
*/
|
|
|
|
|
package in.nosd.redis.dataadapters;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.graylog.autovalue.WithBeanGetter;
|
|
|
|
|
import org.graylog2.lookup.dto.DataAdapterDto;
|
|
|
|
|
import org.graylog2.plugin.lookup.LookupCachePurge;
|
|
|
|
|
import org.graylog2.plugin.lookup.LookupDataAdapter;
|
|
|
|
|
import org.graylog2.plugin.lookup.LookupDataAdapterConfiguration;
|
|
|
|
|
import org.graylog2.plugin.lookup.LookupResult;
|
|
|
|
|
import org.joda.time.Duration;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import com.codahale.metrics.Meter;
|
|
|
|
|
import com.codahale.metrics.MetricRegistry;
|
|
|
|
|
import com.codahale.metrics.Timer;
|
|
|
|
@ -26,37 +40,18 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonTypeName;
|
|
|
|
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
|
|
|
import com.google.auto.value.AutoValue;
|
|
|
|
|
import org.graylog2.lookup.dto.DataAdapterDto;
|
|
|
|
|
import com.google.common.collect.ArrayListMultimap;
|
|
|
|
|
import com.google.common.collect.Multimap;
|
|
|
|
|
import com.google.inject.Inject;
|
|
|
|
|
import com.google.inject.assistedinject.Assisted;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import io.lettuce.core.RedisClient;
|
|
|
|
|
import io.lettuce.core.RedisURI;
|
|
|
|
|
import io.lettuce.core.api.StatefulRedisConnection;
|
|
|
|
|
import io.lettuce.core.api.sync.RedisCommands;
|
|
|
|
|
import in.nosd.redis.dataadapters.AutoValue_RedisLookupDataAdapter_Config;
|
|
|
|
|
import org.graylog2.plugin.lookup.LookupCachePurge;
|
|
|
|
|
import org.graylog2.plugin.lookup.LookupDataAdapter;
|
|
|
|
|
import org.graylog2.plugin.lookup.LookupDataAdapterConfiguration;
|
|
|
|
|
import org.graylog2.plugin.lookup.LookupResult;
|
|
|
|
|
import org.joda.time.Duration;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
import com.google.inject.Inject;
|
|
|
|
|
import com.google.inject.assistedinject.Assisted;
|
|
|
|
|
import javax.validation.constraints.Min;
|
|
|
|
|
import javax.validation.constraints.NotEmpty;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.StringJoiner;
|
|
|
|
|
import jakarta.validation.constraints.Min;
|
|
|
|
|
import jakarta.validation.constraints.NotEmpty;
|
|
|
|
|
import reactor.util.annotation.Nullable;
|
|
|
|
|
|
|
|
|
|
public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(RedisLookupDataAdapter.class);
|
|
|
|
@ -90,8 +85,8 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|
|
|
|
public RedisLookupDataAdapter(@Assisted("dto") DataAdapterDto dto,
|
|
|
|
|
MetricRegistry metricRegistry) {
|
|
|
|
|
super(dto, metricRegistry);
|
|
|
|
|
|
|
|
|
|
this.config = (Config) dto.config();
|
|
|
|
|
|
|
|
|
|
RedisURI redisUri ;
|
|
|
|
|
redisUri = RedisURI.Builder.redis(this.config.redisHost(),this.config.redisPort())
|
|
|
|
|
.withPort(this.config.redisPort())
|
|
|
|
@ -187,7 +182,6 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|
|
|
|
// This is deprecated, see setValue
|
|
|
|
|
@Deprecated
|
|
|
|
|
public void set(Object key, Object value) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -195,6 +189,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|
|
|
|
return setValueWithTtl(key, value, this.config.redisKeyTTL());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public LookupResult setValueWithTtl(Object key, Object value, Long ttlSec) {
|
|
|
|
|
final Timer.Context time = redisSetRequestTimer.time();
|
|
|
|
|
final String trimmedKey = StringUtils.trimToNull(key.toString());
|
|
|
|
@ -273,6 +268,7 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TTL -1 = never expire
|
|
|
|
|
@Override
|
|
|
|
|
public LookupResult assignTtl(Object key, Long ttlSec) {
|
|
|
|
|
final Timer.Context time = redisAssignTtlRequestTimer.time();
|
|
|
|
|
final String trimmedKey = StringUtils.trimToNull(key.toString());
|
|
|
|
@ -347,11 +343,12 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public LookupResult setStringListWithTtl(Object key, List<String> listValue, Long ttlSec) {
|
|
|
|
|
final Timer.Context time = redisSetStringListWithTtlRequestTimer.time();
|
|
|
|
|
try {
|
|
|
|
|
setStringList(key, listValue);
|
|
|
|
|
return(assignTtl(key, ttlSec));
|
|
|
|
|
return assignTtl(key, ttlSec);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// This exception comes from assignTtl
|
|
|
|
|
if (e.getMessage().startsWith("WRONGTYPE Operation against a key holding the wrong kind of value")) {
|
|
|
|
@ -420,11 +417,12 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AutoValue
|
|
|
|
|
@WithBeanGetter
|
|
|
|
|
@JsonAutoDetect
|
|
|
|
|
@JsonDeserialize(builder = RedisLookupDataAdapter.Config.Builder.class)
|
|
|
|
|
@JsonDeserialize(builder = AutoValue_RedisLookupDataAdapter_Config.Builder.class)
|
|
|
|
|
@JsonTypeName(NAME)
|
|
|
|
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
|
|
|
|
public abstract static class Config implements LookupDataAdapterConfiguration {
|
|
|
|
|
public static abstract class Config implements LookupDataAdapterConfiguration {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@JsonProperty(TYPE_FIELD)
|
|
|
|
@ -472,11 +470,6 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|
|
|
|
|
|
|
|
|
@AutoValue.Builder
|
|
|
|
|
public abstract static class Builder {
|
|
|
|
|
@JsonCreator
|
|
|
|
|
public static Builder create() {
|
|
|
|
|
return Config.builder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JsonProperty(TYPE_FIELD)
|
|
|
|
|
public abstract Builder type(String type);
|
|
|
|
|
|
|
|
|
|