// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/writer/PrometheusFormatWriter.java
// public class PrometheusFormatWriter {
//     private final StringWriter writer = new StringWriter();
//     private final Map<String, String> globalLabels;
// 
//     public PrometheusFormatWriter(Map<String, String> globalLabels) {
//         this.globalLabels = globalLabels;
//     }
// 
//     public SingleMetricsDefinitionBuilder addGauge(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.GAUGE, writer, name, globalLabels);
//     }
// 
//     public SingleMetricsDefinitionBuilder addCounter(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.COUNTER, writer, name, globalLabels);
//     }
// 
//     public SummaryMetricsDefinitionBuilder addSummary(String name) {
//         return new SummaryMetricsDefinitionBuilder(writer, name, globalLabels);
//     }
// 
//     public String toString() {
//         return writer.toString();
//     }
// }
// 
// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/writer/SingleValueWriter.java
// public final class SingleValueWriter {
//     private final ValueWriter valueWriter;
//     private final String name;
// 
//     SingleValueWriter(StringWriter writer, String name, Map<String, String> globalLabels) {
//         this.valueWriter = new ValueWriter(writer, globalLabels);
//         this.name = name;
//     }
// 
//     public SingleValueWriter withSharedLabel(String labelName, String labelValue) {
//         valueWriter.addSharedLabel(labelName, labelValue);
//         return this;
//     }
// 
//     public void value(double value) {
//         this.value(value, Collections.emptyMap());
//     }
// 
//     public SingleValueWriter value(double value, Map<String, String> labels) {
//         valueWriter.writeValue(name, value, labels);
//         return this;
//     }
// 
// 
//     public SingleValueWriter value(double value, String...labels) {
//         if (labels.length % 2 != 0) {
//             throw new IllegalArgumentException("Wrong number of labels, should be in pairs..");
//         }
// 
//         Map<String, String> paramsMap = new LinkedHashMap<>();
//         for (int i = 0; i < labels.length; i++) {
//             paramsMap.put(labels[i], labels[++i]);
//         }
// 
//         return this.value(value, paramsMap);
//     }
// 
// 
// 
//     public void summary(long collectionCount, long millis, String...labels) {
//         if (labels.length % 2 != 0) {
//             throw new IllegalArgumentException("Wrong number of labels, should be in pairs..");
//         }
//         Map<String, String> paramsMap = new LinkedHashMap<>();
//         for (int i = 0; i < labels.length; i++) {
//             paramsMap.put(labels[i], labels[++i]);
//         }
//         valueWriter.writeValue(name + "_count", collectionCount, paramsMap);
//         valueWriter.writeValue(name + "_sum", millis, paramsMap);
//     }
// }


import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.indices.breaker.AllCircuitBreakerStats;
import org.elasticsearch.indices.breaker.CircuitBreakerStats;
import pl.suchenia.elasticsearchPrometheusMetrics.writer.PrometheusFormatWriter;
import pl.suchenia.elasticsearchPrometheusMetrics.writer.SingleValueWriter;
package pl.suchenia.elasticsearchPrometheusMetrics.generators;


public class CircuitBreakerMetricsGenerator extends MetricsGenerator<AllCircuitBreakerStats> {
    private static final Logger logger = Loggers.getLogger(CircuitBreakerMetricsGenerator.class, "init");
    private static final String LABEL_NAME = "circuit_name";

    @Override
    public PrometheusFormatWriter generateMetrics(PrometheusFormatWriter writer, AllCircuitBreakerStats allStats) {
        logger.debug("Generating data about circuit breaker: {}", allStats);

        SingleValueWriter circuitBreakerLimit = writer
                .addGauge("es_breaker_limit_bytes")
                .withHelp("Memory limit of circuit breaker in bytes");

        SingleValueWriter circuitBreakerEstimated = writer
                .addGauge("es_breaker_estimated_bytes")
                .withHelp("Estimated memory of circuit breaker in bytes");

        SingleValueWriter circuitBreakerTripped = writer
                .addCounter("es_breaker_tripped")
                .withHelp("Counter of how many times circuit breaker tripped");


        SingleValueWriter circuitBreakerOverhead = writer.addGauge("es_breaker_overhead")
// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/writer/PrometheusFormatWriter.java
// public class PrometheusFormatWriter {
//     private final StringWriter writer = new StringWriter();
//     private final Map<String, String> globalLabels;
// 
//     public PrometheusFormatWriter(Map<String, String> globalLabels) {
//         this.globalLabels = globalLabels;
//     }
// 
//     public SingleMetricsDefinitionBuilder addGauge(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.GAUGE, writer, name, globalLabels);
//     }
// 
//     public SingleMetricsDefinitionBuilder addCounter(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.COUNTER, writer, name, globalLabels);
//     }
// 
//     public SummaryMetricsDefinitionBuilder addSummary(String name) {
//         return new SummaryMetricsDefinitionBuilder(writer, name, globalLabels);
//     }
// 
//     public String toString() {
//         return writer.toString();
//     }
// }
// 
// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/writer/SingleValueWriter.java
// public final class SingleValueWriter {
//     private final ValueWriter valueWriter;
//     private final String name;
// 
//     SingleValueWriter(StringWriter writer, String name, Map<String, String> globalLabels) {
//         this.valueWriter = new ValueWriter(writer, globalLabels);
//         this.name = name;
//     }
// 
//     public SingleValueWriter withSharedLabel(String labelName, String labelValue) {
//         valueWriter.addSharedLabel(labelName, labelValue);
//         return this;
//     }
// 
//     public void value(double value) {
//         this.value(value, Collections.emptyMap());
//     }
// 
//     public SingleValueWriter value(double value, Map<String, String> labels) {
//         valueWriter.writeValue(name, value, labels);
//         return this;
//     }
// 
// 
//     public SingleValueWriter value(double value, String...labels) {
//         if (labels.length % 2 != 0) {
//             throw new IllegalArgumentException("Wrong number of labels, should be in pairs..");
//         }
// 
//         Map<String, String> paramsMap = new LinkedHashMap<>();
//         for (int i = 0; i < labels.length; i++) {
//             paramsMap.put(labels[i], labels[++i]);
//         }
// 
//         return this.value(value, paramsMap);
//     }
// 
// 
// 
//     public void summary(long collectionCount, long millis, String...labels) {
//         if (labels.length % 2 != 0) {
//             throw new IllegalArgumentException("Wrong number of labels, should be in pairs..");
//         }
//         Map<String, String> paramsMap = new LinkedHashMap<>();
//         for (int i = 0; i < labels.length; i++) {
//             paramsMap.put(labels[i], labels[++i]);
//         }
//         valueWriter.writeValue(name + "_count", collectionCount, paramsMap);
//         valueWriter.writeValue(name + "_sum", millis, paramsMap);
//     }
// }


// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/generators/CircuitBreakerMetricsGenerator.java
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.indices.breaker.AllCircuitBreakerStats;
import org.elasticsearch.indices.breaker.CircuitBreakerStats;
import pl.suchenia.elasticsearchPrometheusMetrics.writer.PrometheusFormatWriter;
import pl.suchenia.elasticsearchPrometheusMetrics.writer.SingleValueWriter;

package pl.suchenia.elasticsearchPrometheusMetrics.generators;


public class CircuitBreakerMetricsGenerator extends MetricsGenerator<AllCircuitBreakerStats> {
    private static final Logger logger = Loggers.getLogger(CircuitBreakerMetricsGenerator.class, "init");
    private static final String LABEL_NAME = "circuit_name";

    @Override
    public PrometheusFormatWriter generateMetrics(PrometheusFormatWriter writer, AllCircuitBreakerStats allStats) {
        logger.debug("Generating data about circuit breaker: {}", allStats);

        SingleValueWriter circuitBreakerLimit = writer
                .addGauge("es_breaker_limit_bytes")
                .withHelp("Memory limit of circuit breaker in bytes");

        SingleValueWriter circuitBreakerEstimated = writer
                .addGauge("es_breaker_estimated_bytes")
                .withHelp("Estimated memory of circuit breaker in bytes");

        SingleValueWriter circuitBreakerTripped = writer
                .addCounter("es_breaker_tripped")
                .withHelp("Counter of how many times circuit breaker tripped");


        SingleValueWriter circuitBreakerOverhead = writer.addGauge("es_breaker_overhead")
                .withHelp("Overhead factor for circuit breaker");