Moved inject for metric prefix filter into the RemoteDatastore constructor, to be sure that we're reading the prefixes to filter before we check to see if we're trying to filter what we forward, so we don't get a null pointer error.
@@ -19,6 +19,7 @@ package org.kairosdb.datastore.remote;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Multimap;
+import org.h2.util.StringUtils;
import org.kairosdb.eventbus.Subscribe;
import com.google.inject.Inject;
import com.google.inject.name.Named;
@@ -51,6 +52,7 @@ import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
+import java.util.Arrays;
import java.util.SortedMap;
import java.util.zip.GZIPOutputStream;
@@ -86,8 +88,6 @@ public class RemoteDatastore implements Datastore
@Named("HOSTNAME")
private String m_hostName = "localhost";
- @Inject(optional = true)
- @Named(METRIC_PREFIX_FILTER)
private String m_prefixFilter = null;
private String[] m_prefixFilterArray;
@@ -98,18 +98,18 @@ public class RemoteDatastore implements Datastore
@Inject
public RemoteDatastore(@Named(DATA_DIR_PROP) String dataDir,
- @Named(REMOTE_URL_PROP) String remoteUrl) throws IOException, DatastoreException
+ @Named(REMOTE_URL_PROP) String remoteUrl,
+ @Named(METRIC_PREFIX_FILTER) String prefixFilter) throws IOException, DatastoreException
{
m_dataDirectory = dataDir;
m_remoteUrl = remoteUrl;
m_client = HttpClients.createDefault();
- logger.info("kairosdb.datastore.remote.prefix_filter:" + m_prefixFilter);
- if (m_prefixFilter != null)
+ if (!StringUtils.isNullOrEmpty(prefixFilter))
{
- m_prefixFilter = m_prefixFilter.replaceAll("\\s+","");
+ m_prefixFilter = prefixFilter.replaceAll("\\s+","");
m_prefixFilterArray = m_prefixFilter.split(",");
- logger.info("Forwarding these prefixes to remote KairosDB:" + m_prefixFilterArray);
+ logger.info("List of metric prefixes to forward to remote KairosDB: " + Arrays.toString(m_prefixFilterArray));
}
createNewMap();
@@ -296,7 +296,7 @@ public class RemoteDatastore implements Datastore
{
String metricName = event.getMetricName();
- if (m_prefixFilter != null)
+ if (!StringUtils.isNullOrEmpty(m_prefixFilter))
{
boolean prefixMatch = false;
for (String prefixFilter : m_prefixFilterArray)
