Skip to content

Commit

Permalink
hwkmetrics-507
Browse files Browse the repository at this point in the history
- make injecting CacheClient easier by moving it and CacheKey to its own jar
- add ignoreFiltering option to sendData/Events to allow clients to
  perform their own filtering and (java clients only for now)
  • Loading branch information
jshaughn committed Oct 13, 2016
1 parent 00e9b0b commit bfdb68a
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ void resolveAlertsForTrigger(String tenantId, String triggerId, String resolvedB
*/
void sendData(Collection<Data> data) throws Exception;

/**
* Send data into the alerting system for evaluation.
*
* @param data Not Null. The data to be evaluated by the alerting engine.
* @param ignoreFiltering An optimization. Set true *only* if you are sure the data is useful for evaluation.
* @throws Exception any problem.
*/
void sendData(Collection<Data> data, boolean ignoreFiltering) throws Exception;

/**
* Send event to the engine for alerts evaluation.
* The event sent is not persisted into the alerts engine.
Expand All @@ -234,4 +243,14 @@ void resolveAlertsForTrigger(String tenantId, String triggerId, String resolvedB
* @throws Exception
*/
void sendEvents(Collection<Event> events) throws Exception;

/**
* Send events to the engine for alerts evaluation.
* The event sent are not persisted into the alerts engine.
*
* @param events Not null. The events to be evaluated by the alerting engine.
* @param ignoreFiltering An optimization. Set true *only* if you are sure the data is useful for evaluation.
* @throws Exception
*/
void sendEvents(Collection<Event> events, boolean ignoreFiltering) throws Exception;
}
5 changes: 5 additions & 0 deletions hawkular-alerts-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<artifactId>hawkular-alerts-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hawkular.alerts</groupId>
<artifactId>hawkular-alerts-filter-api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.kie</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@

import org.hawkular.alerts.api.model.condition.CompareCondition;
import org.hawkular.alerts.api.model.condition.Condition;
import org.hawkular.alerts.api.model.data.CacheKey;
import org.hawkular.alerts.api.services.DefinitionsService;
import org.hawkular.alerts.api.services.PropertiesService;
import org.hawkular.alerts.engine.log.MsgLogger;
import org.hawkular.alerts.filter.CacheKey;
import org.infinispan.Cache;
import org.infinispan.CacheSet;
import org.jboss.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
import org.hawkular.alerts.api.services.AlertsService;
import org.hawkular.alerts.api.services.DefinitionsService;
import org.hawkular.alerts.api.services.EventsCriteria;
import org.hawkular.alerts.engine.cache.CacheClient;
import org.hawkular.alerts.engine.log.MsgLogger;
import org.hawkular.alerts.engine.service.AlertsEngine;
import org.hawkular.alerts.filter.CacheClient;
import org.jboss.logging.Logger;

import com.datastax.driver.core.BoundStatement;
Expand Down Expand Up @@ -1578,22 +1578,29 @@ private void handleResolveOptions(String tenantId, String triggerId, boolean che

@Override
public void sendData(Data data) throws Exception {
sendData(Collections.singleton(data));
sendData(Collections.singleton(data), false);
}

@Override
public void sendData(Collection<Data> data) throws Exception {
sendData(data, false);
}

@Override
public void sendData(Collection<Data> data, boolean ignoreFiltering) throws Exception {
if (isEmpty(data)) {
return;
}

// Front-line filtering to remove Data not used in trigger evaluation (globally not used in any condition).
if (!ignoreFiltering) {
data = dataIdCache.filterData(data);
if (data.isEmpty()) {
return;
}
}

// check to see if any data can be used to generate data-diven group members
// check to see if any data can be used to generate data-driven group members
checkDataDrivenGroupTriggers(data);

// forward to the engine for node-specific filtering, propagation to other nodes, and/or evaluation
Expand Down Expand Up @@ -1637,19 +1644,27 @@ public void sendEvent(Event event) throws Exception {
if (null == event) {
return;
}
sendEvents(Collections.singleton(event));
sendEvents(Collections.singleton(event), false);
}

@Override
public void sendEvents(Collection<Event> events) throws Exception {

sendEvents(events, false);
}

@Override
public void sendEvents(Collection<Event> events, boolean ignoreFiltering) throws Exception {
if (isEmpty(events)) {
return;
}

// Front-line filtering to remove Data not used in trigger evaluation (globally not used in any condition).
events = dataIdCache.filterEvents(events);
if (events.isEmpty()) {
return;
if (!ignoreFiltering) {
events = dataIdCache.filterEvents(events);
if (events.isEmpty()) {
return;
}
}

alertsEngine.sendEvents(events);
Expand Down
89 changes: 89 additions & 0 deletions hawkular-alerts-filter-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2015-2016 Red Hat, Inc. and/or its affiliates
and other contributors as indicated by the @author tags.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.hawkular.alerts</groupId>
<artifactId>hawkular-alerts</artifactId>
<version>1.2.3.Final-SNAPSHOT</version>
</parent>

<artifactId>hawkular-alerts-filter-api</artifactId>
<packaging>jar</packaging>

<name>Hawkular Alerting: Filter Cache API</name>

<dependencies>
<dependency>
<groupId>org.hawkular.alerts</groupId>
<artifactId>hawkular-alerts-api</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Wildfly dependencies -->
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${version.javaee.spec}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<scope>provided</scope>
<version>${version.org.infinispan.wildfly}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<scope>provided</scope>
</dependency>

<!-- Tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.alerts.engine.cache;
package org.hawkular.alerts.filter;

import java.util.Collection;
import java.util.Set;
Expand All @@ -23,7 +23,6 @@
import javax.annotation.Resource;
import javax.enterprise.context.ApplicationScoped;

import org.hawkular.alerts.api.model.data.CacheKey;
import org.hawkular.alerts.api.model.data.Data;
import org.hawkular.alerts.api.model.event.Event;
import org.infinispan.Cache;
Expand All @@ -41,7 +40,7 @@
@ApplicationScoped
public class CacheClient {

/** key=dataId, value="" */
/** key=CacheKey, value="" */
@Resource(lookup = "java:jboss/infinispan/cache/hawkular-alerts/publish")
private Cache<CacheKey, String> cache;

Expand Down Expand Up @@ -83,4 +82,10 @@ private CacheKey fillKey(CacheKey key, Event event) {
return key;
}

/**
* This is here for testing purposes only and should not be called in production code.
*/
public void addTestKey(CacheKey key, String value) {
cache.put(key, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.alerts.api.model.data;
package org.hawkular.alerts.filter;

import java.io.Serializable;

Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<modules>
<module>hawkular-alerts-api</module>
<module>hawkular-alerts-bus-api</module>
<module>hawkular-alerts-filter-api</module>
<module>hawkular-alerts-engine</module>
<module>hawkular-alerts-bus</module>
<module>hawkular-alerts-rest</module>
Expand All @@ -149,6 +150,7 @@
</properties>
<modules>
<module>hawkular-alerts-api</module>
<module>hawkular-alerts-filter-api</module>
<module>hawkular-alerts-engine</module>
<module>hawkular-alerts-rest</module>
<module>hawkular-alerts-actions</module>
Expand Down

0 comments on commit bfdb68a

Please sign in to comment.