[Bug] Alerting with triggers
- Lingua principale
- Java
- Stelle
- 6.4k
- Fork
- 1.2k
- Merge medio
- 1g 23h
- PR unite (30g)
- 115
Descrizione
### 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!
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con il comando CREATE STATELESS TRIGGER e l’elenco del jar per ClusterAlertingExample.java, quindi confronta la versione della dipendenza nel pom.xml dell’esempio con IoTDB 1.2.2. Riproduci l’errore di caricamento della classe usando l’URI fornita e verifica se la classe del trigger può essere caricata; il lavoro è completato quando l’esempio di alerting documentato viene creato correttamente oppure viene documentata la correzione necessaria.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- database
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 30/100