This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #449 from ArgusMonitoring/develop
merge develop into master for release
- Loading branch information
Showing
56 changed files
with
3,106 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,15 +32,16 @@ | |
package com.salesforce.dva.argus.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.google.common.base.Objects; | ||
import com.salesforce.dva.argus.service.tsdb.MetricQuery; | ||
import com.salesforce.dva.argus.system.SystemAssert; | ||
|
||
import java.io.Serializable; | ||
import java.text.MessageFormat; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.SortedMap; | ||
import java.util.TreeMap; | ||
|
||
import static com.salesforce.dva.argus.system.SystemAssert.requireArgument; | ||
|
@@ -58,16 +59,21 @@ | |
* @author Tom Valine ([email protected]), Bhinav Sura ([email protected]) | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class Metric extends TSDBEntity implements Serializable { | ||
public class Metric extends TSDBEntity implements Serializable, Comparable<Metric> { | ||
|
||
private static final Comparator<Metric> METRIC_COMPARATOR = Comparator | ||
.comparing((Metric m) -> m.getScope().toLowerCase()) | ||
.thenComparing(m -> m.getMetric().toLowerCase()) | ||
.thenComparing(m -> m.getTags().toString().toLowerCase()); | ||
|
||
//~ Instance fields ****************************************************************************************************************************** | ||
|
||
private String _namespace; | ||
private String _displayName; | ||
private String _units; | ||
private final Map<Long, Double> _datapoints; | ||
private final SortedMap<Long, Double> _datapoints; | ||
private MetricQuery _query; | ||
private MetatagsRecord _metatagsRecord = null; | ||
private MetatagsRecord _metatagsRecord = null; | ||
|
||
//~ Constructors ********************************************************************************************************************************* | ||
|
||
|
@@ -146,7 +152,7 @@ public void setNamespace(String namespace) { | |
* @return The map of time series data points. Will never be null, but may be empty. | ||
*/ | ||
public Map<Long, Double> getDatapoints() { | ||
return Collections.unmodifiableMap(_datapoints); | ||
return Collections.unmodifiableSortedMap(_datapoints); | ||
} | ||
|
||
/** | ||
|
@@ -380,5 +386,10 @@ public MetatagsRecord getMetatagsRecord() { | |
public void setMetatagsRecord(MetatagsRecord metatagsRec) { | ||
_metatagsRecord = metatagsRec; | ||
} | ||
|
||
@Override | ||
public int compareTo(Metric m) { | ||
return METRIC_COMPARATOR.compare(this, m); | ||
} | ||
} | ||
/* Copyright (c) 2016, Salesforce.com, Inc. All rights reserved. */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
ArgusCore/src/main/java/com/salesforce/dva/argus/service/AnnotationStorageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.salesforce.dva.argus.service; | ||
|
||
import java.util.List; | ||
|
||
import com.salesforce.dva.argus.entity.Annotation; | ||
import com.salesforce.dva.argus.service.tsdb.AnnotationQuery; | ||
|
||
/** | ||
* Provides methods for putting or retrieving annotations from storage. | ||
* | ||
* @author Dilip Devaraj ([email protected]) | ||
*/ | ||
public interface AnnotationStorageService extends Service{ | ||
/** | ||
* Writes annotation data. Any existing data is overwritten. | ||
* | ||
* @param annotations The list of annotations to write. Cannot be null, but may be empty. | ||
*/ | ||
void putAnnotations(List<Annotation> annotations); | ||
|
||
/** | ||
* Reads annotation data. | ||
* | ||
* @param queries The list of queries to execute. Cannot be null, but may be empty. | ||
* | ||
* @return The query results. Will never be null, but may be empty. | ||
*/ | ||
List<Annotation> getAnnotations(List<AnnotationQuery> queries); | ||
} |
131 changes: 131 additions & 0 deletions
131
ArgusCore/src/main/java/com/salesforce/dva/argus/service/ArgusTransport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package com.salesforce.dva.argus.service; | ||
|
||
import com.salesforce.dva.argus.service.alert.notifier.GusTransport; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.config.Registry; | ||
import org.apache.http.config.RegistryBuilder; | ||
import org.apache.http.conn.socket.ConnectionSocketFactory; | ||
import org.apache.http.conn.socket.PlainConnectionSocketFactory; | ||
import org.apache.http.conn.ssl.NoopHostnameVerifier; | ||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; | ||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import java.security.KeyManagementException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Optional; | ||
|
||
import static com.salesforce.dva.argus.system.SystemAssert.requireArgument; | ||
|
||
public class ArgusTransport { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ArgusTransport.class); | ||
private static final int CONNECTION_TIMEOUT_MILLIS = 10000; | ||
private static final int READ_TIMEOUT_MILLIS = 10000; | ||
|
||
protected final CloseableHttpClient httpClient; | ||
|
||
public ArgusTransport(Optional<String> proxyHost, | ||
Optional<Integer> proxyPort, | ||
int connectionPoolMaxSize, | ||
int connectionPoolMaxPerRoute) { | ||
this.httpClient = buildHttpClient(proxyHost, proxyPort, connectionPoolMaxSize, connectionPoolMaxPerRoute); | ||
} | ||
|
||
public ArgusTransport(String proxyHost, String proxyPort, int connectionPoolMaxSize, int connectionPoolMaxPerRoute) { | ||
this(validateProxyHostAndPortStrings(proxyHost, proxyPort) ? Optional.of(proxyHost) : Optional.empty(), | ||
validateProxyHostAndPortStrings(proxyHost, proxyPort) ? Optional.of(Integer.parseInt(proxyPort)) : Optional.empty(), | ||
connectionPoolMaxSize, connectionPoolMaxPerRoute); | ||
} | ||
|
||
public static boolean validateProxyHostAndPortStrings(String proxyHost, String proxyPort) { | ||
requireArgument(StringUtils.isBlank(proxyPort) || StringUtils.isNumeric(proxyPort), | ||
"proxyPort must be numeric if present"); | ||
return StringUtils.isNotBlank(proxyHost) && StringUtils.isNotBlank(proxyPort) && StringUtils.isNumeric(proxyPort); | ||
} | ||
|
||
/** | ||
* Get HttpClient. | ||
* | ||
* @return HttpClient | ||
*/ | ||
public CloseableHttpClient getHttpClient() { | ||
return httpClient; | ||
} | ||
|
||
protected static SSLContext getSSLContext() { | ||
SSLContext sslContext = null; | ||
try { | ||
sslContext = SSLContext.getInstance("TLS"); | ||
sslContext.init(null, null, null); | ||
} catch (NoSuchAlgorithmException | KeyManagementException e) { | ||
LOGGER.error("Failed to init SSLContext", e); | ||
} | ||
return sslContext; | ||
} | ||
|
||
protected static PoolingHttpClientConnectionManager buildConnectionManager(int connectionPoolMaxSize, | ||
int connectionPoolMaxPerRoute, | ||
SSLContext sslContext) { | ||
requireArgument(connectionPoolMaxSize > 0, | ||
String.format("connectionPoolMaxSize(%d) must be > 0", connectionPoolMaxSize)); | ||
requireArgument(connectionPoolMaxPerRoute > 0, | ||
String.format("connectionPoolMaxPerRoute(%d) must be > 0", connectionPoolMaxPerRoute)); | ||
|
||
RegistryBuilder<ConnectionSocketFactory> rb = RegistryBuilder.<ConnectionSocketFactory>create() | ||
.register("http", PlainConnectionSocketFactory.getSocketFactory()); | ||
if (sslContext != null) { | ||
rb.register("https", new SSLConnectionSocketFactory(sslContext)); | ||
} | ||
Registry<ConnectionSocketFactory> r = rb.build(); | ||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(r); | ||
cm.setMaxTotal(connectionPoolMaxSize); | ||
cm.setDefaultMaxPerRoute(connectionPoolMaxPerRoute); | ||
LOGGER.info(String.format("Creating connection manager with maxPoolSize=%d, maxPerRoute=%d", | ||
connectionPoolMaxSize, | ||
connectionPoolMaxPerRoute)); | ||
return cm; | ||
} | ||
|
||
protected static CloseableHttpClient buildHttpClient(Optional<String> proxyHost, | ||
Optional<Integer> proxyPort, | ||
int connectionPoolMaxSize, | ||
int connectionPoolMaxPerRoute) { | ||
requireArgument(!proxyHost.isPresent() || StringUtils.isNotBlank(proxyHost.get()), | ||
String.format("proxyHost must not be blank if present", proxyHost.isPresent() ? proxyHost.get() : "null")); | ||
requireArgument(!proxyPort.isPresent() || proxyPort.get() > 0, | ||
String.format("proxyPort(%s) must > 0 if present", proxyPort.isPresent() ? proxyPort.get().toString() : "null")); | ||
|
||
SSLContext sslContext = getSSLContext(); | ||
PoolingHttpClientConnectionManager cm = buildConnectionManager(connectionPoolMaxSize, connectionPoolMaxPerRoute, sslContext); | ||
|
||
RequestConfig requestConfig = RequestConfig.custom() | ||
.setConnectTimeout(CONNECTION_TIMEOUT_MILLIS) | ||
.setConnectionRequestTimeout(CONNECTION_TIMEOUT_MILLIS) | ||
.setSocketTimeout(READ_TIMEOUT_MILLIS) | ||
.build(); | ||
|
||
HttpClientBuilder builder = HttpClients.custom() | ||
.setDefaultRequestConfig(requestConfig) | ||
.setConnectionManager(cm); | ||
if (sslContext != null) { | ||
builder = builder | ||
.setSSLContext(sslContext) | ||
.setSSLHostnameVerifier(new NoopHostnameVerifier()); | ||
} | ||
if (proxyHost.isPresent() && proxyHost.get().length() > 0 && proxyPort.isPresent()) { | ||
HttpHost proxy = new HttpHost(proxyHost.get(), proxyPort.get().intValue()); | ||
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); | ||
builder = builder.setRoutePlanner(routePlanner); | ||
} | ||
return builder.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.