[Bug] Alerting with triggers
- Vorherrschende Sprache
- Java
- Sterne
- 6.4k
- Forks
- 1.2k
- Ø Merge
- 1 T. 23 Std.
- Gemergte PRs (30 T.)
- 115
Beschreibung
### Search before asking
- [X] I searched in the [issues](https://github.com/apache/iotdb/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
```java
/*
* 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 labels = new HashMap<>();
private final HashMap 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 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
4.0.0
apache.iotdb
cluster_alerting
1.0-SNAPSHOT
cluster_alerting
http://www.example.com
UTF-8
1.7
1.7
maven-clean-plugin
3.1.0
maven-resources-plugin
3.0.2
maven-compiler-plugin
3.8.0
maven-surefire-plugin
2.22.1
maven-jar-plugin
3.0.2
maven-install-plugin
2.5.2
maven-deploy-plugin
2.8.2
maven-site-plugin
3.7.1
maven-project-info-reports-plugin
3.0.0
org.apache.iotdb
iotdb-server
1.2.0
```
# The schema file is like this
i'm missing something?
```plaintext
cluster_alerting
├── src/main/java/org/apache/iotdb/trigger/
│ └── ClusterAlertingExample.java
└── pom.xml
```
################################################################################################
- I have builded the jar file using `mvn compile` -> `mvn package` command
- Then using the `jar tvf` command i got this output:
```plaintext
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:
```bash
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
```bash
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
```bash
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!
Beitragsleitfaden
Rechercherichtung
Beginne mit dem Befehl CREATE STATELESS TRIGGER und der jar-Auflistung für ClusterAlertingExample.java und vergleiche anschließend die Abhängigkeitsversion in der pom.xml des Beispiels mit IoTDB 1.2.2. Reproduziere den Fehler beim Laden der Klasse mithilfe der bereitgestellten URI und überprüfe, ob die Trigger-Klasse geladen werden kann; abgeschlossen ist die Aufgabe, wenn das dokumentierte Alerting-Beispiel erfolgreich erstellt wird oder die erforderliche Korrektur dokumentiert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- database
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 30/100