alibaba / alibaba/Sentinel

Proposal about expand more channel for metric export

Open
#3,314 0 comments 0 reactions 0 assignees View on GitHub
area/metrics kind/feature
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

## Issue Description
Hi, community. I am a new learner for sentinel whose design is amazing to me. When i was reading the source code, i found that the mertic export is so simple currently which can be found in `MetricWriter`. The channel for exporting is only to export to a file. And this has been hard code in project which makes it difficult to extern, for example, we hope to collect all app metric into database, mongodb and so on to do data analysis but no way with current design.

### Describe what feature you want
Add the more channel or way to expand for metric exporting.

### Describe your initial design (if present)
I wanna to design a interface to do mertic export. Here are definition:
```java
public interface MetricExporter {
// Timed call in MetricTimerListener
void export(Map> metric);
}
```
The default implement is the origin way to export: file export.
```java
public class DefaultExporter implements MetricExporter {
private static final MetricWriter metricWriter = new MetricWriter(SentinelConfig.singleMetricFileSize(),
SentinelConfig.totalMetricFileCount());
@Override
public void export(Map> metric){
for (Entry> entry : maps.entrySet()) {
try {
metricWriter.write(entry.getKey(), entry.getValue());
} catch (Exception e) {
RecordLog.warn("[MetricTimerListener] Write metric error", e);
}
}
}
}
```
This interface will be held in `MetricTimerListener`.
```java
public class MetricTimerListener implements Runnable {
public static final MetricExporter exporter = null;
static {
exporter = SpiLoader.of(MetricExporter .class).loadFirstInstanceOrDefault();
}
@Override
public void run() {
....
exporter.export(maps);
}
}
```
I am not sure whether my idea is right. Please correct me if any mistake. Thanks.
### Additional context

Add any other context or screenshots about the feature request here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.