Skip to content

Commit

Permalink
Fix bug on Alerters initialization (#391)
Browse files Browse the repository at this point in the history
- Existing triggers are not loaded
Unify HttpLibrary in Prometheus/Elasticsearch Alerter
- This will save additional dependencies
Enable Prometheus Alerter by default
  • Loading branch information
lucasponce authored and jshaughn committed Jul 14, 2017
1 parent f6d6478 commit da70387
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 550 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.hawkular.alerts.actions.standalone;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -53,18 +55,28 @@ public void init() {
definitions = StandaloneAlerts.getDefinitionsService();
actions = StandaloneAlerts.getActionsService();
Map<String, ActionPluginListener> plugins = ActionPlugins.getPlugins();
Collection<String> existingPlugins = Collections.EMPTY_LIST;
try {
existingPlugins = definitions.getActionPlugins();
} catch (Exception e) {
log.error("Error querying the existing plugins", e);
}
for (String actionPlugin : plugins.keySet()) {
ActionPluginListener actionPluginListener = plugins.get(actionPlugin);
Set<String> properties = actionPluginListener.getProperties();
Map<String, String> defaultProperties = actionPluginListener.getDefaultProperties();
try {
if (defaultProperties != null && !defaultProperties.isEmpty() ) {
definitions.addActionPlugin(actionPlugin, defaultProperties);
} else {
definitions.addActionPlugin(actionPlugin, properties);
if (existingPlugins.contains(actionPlugin)) {
log.infof("Plugin [%s] is already registered", actionPlugin);
} else {
ActionPluginListener actionPluginListener = plugins.get(actionPlugin);
Set<String> properties = actionPluginListener.getProperties();
Map<String, String> defaultProperties = actionPluginListener.getDefaultProperties();
try {
if (defaultProperties != null && !defaultProperties.isEmpty() ) {
definitions.addActionPlugin(actionPlugin, defaultProperties);
} else {
definitions.addActionPlugin(actionPlugin, properties);
}
} catch (Exception e) {
log.errorCannotRegisterPlugin(actionPlugin, e.toString());
}
} catch (Exception e) {
log.errorCannotRegisterPlugin(actionPlugin, e.toString());
}
}
ActionListener actionListener = new StandaloneActionPluginListener(ActionPlugins.getPlugins(), executor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.hawkular.alerter.elasticsearch;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -218,6 +219,7 @@ public void init(DefinitionsService definitions, AlertsService alerts, ExecutorS

if (elasticSearchAlerter) {
this.definitions.registerDistributedListener(events -> refresh(events));
initialRefresh();
}
}

Expand Down Expand Up @@ -261,6 +263,16 @@ private void refresh(Set<DistributedEvent> distEvents) {
});
}

private void initialRefresh() {
try {
Collection<Trigger> triggers = definitions.getAllTriggersByTag(ALERTER_NAME, "*");
triggers.stream().forEach(trigger -> activeTriggers.put(new TriggerKey(trigger.getTenantId(), trigger.getId()), trigger));
update();
} catch (Exception e) {
log.error("Failed to fetch Triggers for external conditions.", e);
}
}

private synchronized void update() {
final Set<TriggerKey> existingKeys = queryFutures.keySet();
final Set<TriggerKey> activeKeys = activeTriggers.keySet();
Expand Down
26 changes: 20 additions & 6 deletions alerters/alerters-plugins/alerters-prometheus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,29 @@
<dependencies>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${version.com.squareup.okhttp3}</version>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${version.org.apache.httpcomponents.httpclient}</version>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-ws</artifactId>
<version>${version.com.squareup.okhttp3}</version>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>${version.org.apache.httpcomponents.httpcore}</version>
</dependency>

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${version.org.codehaus.groovy}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.codehaus.groovy.modules.http-builder</groupId>
<artifactId>http-builder</artifactId>
<version>${version.org.codehaus.groovy.modules.http-builder}</version>
<scope>test</scope>
</dependency>

<dependency>
Expand Down

0 comments on commit da70387

Please sign in to comment.