Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal about expand more channel for metric export #3314

Open
Daydreamer-ia opened this issue Jan 24, 2024 · 0 comments
Open

Proposal about expand more channel for metric export #3314

Daydreamer-ia opened this issue Jan 24, 2024 · 0 comments
Labels
area/metrics Issues or PRs related to metrics and monitoring kind/feature Category issues or prs related to feature request.

Comments

@Daydreamer-ia
Copy link

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:

public interface MetricExporter {
   // Timed call in MetricTimerListener
   void export(Map<Long, List<MetricNode>> metric);
}

The default implement is the origin way to export: file export.

public class DefaultExporter implements MetricExporter {
    private static final MetricWriter metricWriter = new MetricWriter(SentinelConfig.singleMetricFileSize(),
        SentinelConfig.totalMetricFileCount());
   @Override
   public void export(Map<Long, List<MetricNode>> metric){
       for (Entry<Long, List<MetricNode>> 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.

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.

@sczyh30 sczyh30 added kind/feature Category issues or prs related to feature request. area/metrics Issues or PRs related to metrics and monitoring labels Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/metrics Issues or PRs related to metrics and monitoring kind/feature Category issues or prs related to feature request.
Projects
None yet
Development

No branches or pull requests

2 participants