iotdb
iotdb copied to clipboard
[Bug] Alerting with triggers
Search before asking
- [X] I searched in the issues and found nothing similar.
Version
- IoTDB Verions: 1.2.2 (Build: 5d0bfb0)
- Java Version: java 21.0.2 2024-01-16 LTS
Describe the bug and provide the minimal reproduce step
I got some error while trying to add a trigger with quite litterally the documentation provided example:
ClusterAlertingExample.java File
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package org.apache.iotdb.trigger;
import org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerConfiguration;
import org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerEvent;
import org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerHandler;
import org.apache.iotdb.trigger.api.Trigger;
import org.apache.iotdb.trigger.api.TriggerAttributes;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.write.record.Tablet;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
public class ClusterAlertingExample implements Trigger {
private final AlertManagerHandler alertManagerHandler = new AlertManagerHandler();
private final AlertManagerConfiguration alertManagerConfiguration =
new AlertManagerConfiguration("http://127.0.0.1:9093/api/v2/alerts");
private String alertname;
private final HashMap<String, String> labels = new HashMap<>();
private final HashMap<String, String> annotations = new HashMap<>();
@Override
public void onCreate(TriggerAttributes attributes) throws Exception {
alertname = "alert_test";
labels.put("series", "root.Firewall");
labels.put("value", "");
labels.put("severity", "");
annotations.put("summary", "high temperature");
annotations.put("description", "{{.alertname}}: {{.series}} is {{.value}}");
alertManagerHandler.open(alertManagerConfiguration);
}
@Override
public void onDrop() throws IOException {
alertManagerHandler.close();
}
@Override
public boolean fire(Tablet tablet) throws Exception {
List<MeasurementSchema> measurementSchemaList = tablet.getSchemas();
for (int i = 0, n = measurementSchemaList.size(); i < n; i++) {
if (measurementSchemaList.get(i).getType().equals(TSDataType.DOUBLE)) {
// for example, we only deal with the columns of Double type
double[] values = (double[]) tablet.values[i];
for (double value : values) {
if (value > 100.0) {
labels.put("value", String.valueOf(value));
labels.put("severity", "critical");
AlertManagerEvent alertManagerEvent =
new AlertManagerEvent(alertname, labels, annotations);
alertManagerHandler.onEvent(alertManagerEvent);
} else if (value > 50.0) {
labels.put("value", String.valueOf(value));
labels.put("severity", "warning");
AlertManagerEvent alertManagerEvent =
new AlertManagerEvent(alertname, labels, annotations);
alertManagerHandler.onEvent(alertManagerEvent);
}
}
}
}
return true;
}
}
pom.xml File
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>apache.iotdb</groupId>
<artifactId>cluster_alerting</artifactId>
<version>1.0-SNAPSHOT</version>
<name>cluster_alerting</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-server</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
</project>
The schema file is like this
i'm missing something?
cluster_alerting
├── src/main/java/org/apache/iotdb/trigger/
│ └── ClusterAlertingExample.java
└── pom.xml
################################################################################################
- I have builded the jar file using
mvn compile->mvn packagecommand - Then using the
jar tvfcommand i got this output:
93 Thu Feb 22 09:48:48 UTC 2024 META-INF/MANIFEST.MF
0 Thu Feb 22 09:48:48 UTC 2024 META-INF/
0 Thu Feb 22 09:47:38 UTC 2024 org/
0 Thu Feb 22 09:47:38 UTC 2024 org/apache/
0 Thu Feb 22 09:47:38 UTC 2024 org/apache/iotdb/
0 Thu Feb 22 09:47:40 UTC 2024 org/apache/iotdb/trigger/
0 Thu Feb 22 09:48:48 UTC 2024 META-INF/maven/
0 Thu Feb 22 09:48:48 UTC 2024 META-INF/maven/apache.iotdb/
0 Thu Feb 22 09:48:48 UTC 2024 META-INF/maven/apache.iotdb/cluster_alerting/
3835 Thu Feb 22 09:48:40 UTC 2024 org/apache/iotdb/trigger/ClusterAlertingExample.class
2905 Thu Feb 22 09:47:34 UTC 2024 META-INF/maven/apache.iotdb/cluster_alerting/pom.xml
101 Thu Feb 22 09:48:48 UTC 2024 META-INF/maven/apache.iotdb/cluster_alerting/pom.properties
As you can see i have a java class called org/apache/iotdb/trigger/ClusterAlertingExample.class
but on IoTDB while i try to create the trigger i got this error:
IoTDB> CREATE STATELESS TRIGGER test
> BEFORE INSERT
> ON root.Firewall.**
> AS 'org.apache.iotdb.trigger.ClusterAlertingExample'
> USING URI 'file:///home/sean/apache-iotdb/ext/trigger/install/cluster_alerting-1.0-SNAPSHOT.jar'
Msg: 1303: Failed to load class 'org.apache.iotdb.trigger.ClusterAlertingExample', because it's not found in jar file: file:///home/sean/apache-iotdb/ext/trigger/install/cluster_alerting-1.0-SNAPSHOT.jar
What did you expect to see?
I'll expect to see a succesfully statement while execute the CREATE STATELESS TRIGGER function
IoTDB> CREATE STATELESS TRIGGER test
> BEFORE INSERT
> ON root.Firewall.**
> AS 'org.apache.iotdb.trigger.ClusterAlertingExample'
> USING URI 'file:///home/sean/apache-iotdb/ext/trigger/install/cluster_alerting-1.0-SNAPSHOT.jar'
Msg: The statement is executed successfully.
What did you see instead?
I got an error statement while execute the CREATE STATELESS TRIGGER function saying that the class is missing in the jar file
IoTDB> CREATE STATELESS TRIGGER test
> BEFORE INSERT
> ON root.Firewall.**
> AS 'org.apache.iotdb.trigger.ClusterAlertingExample'
> USING URI 'file:///home/sean/apache-iotdb/ext/trigger/install/cluster_alerting-1.0-SNAPSHOT.jar'
Msg: 1303: Failed to load class 'org.apache.iotdb.trigger.ClusterAlertingExample', because it's not found in jar file: file:///home/sean/apache-iotdb/ext/trigger/install/cluster_alerting-1.0-SNAPSHOT.jar
Anything else?
No response
Are you willing to submit a PR?
- [ ] I'm willing to submit a PR!