z3d1k commented on code in PR #1: URL: https://github.com/apache/flink-connector-prometheus/pull/1#discussion_r1501897480
########## prometheus-connector/src/main/java/org/apache/flink/connector/prometheus/sink/PrometheusSinkWriter.java: ########## @@ -0,0 +1,189 @@ +/* + * 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.flink.connector.prometheus.sink; + +import org.apache.flink.api.connector.sink2.Sink; +import org.apache.flink.connector.base.sink.writer.AsyncSinkWriter; +import org.apache.flink.connector.base.sink.writer.BufferedRequestState; +import org.apache.flink.connector.base.sink.writer.ElementConverter; +import org.apache.flink.connector.prometheus.sink.errorhandling.SinkWriterErrorHandlingBehaviorConfiguration; +import org.apache.flink.connector.prometheus.sink.prometheus.Remote; +import org.apache.flink.connector.prometheus.sink.prometheus.Types; + +import org.apache.hc.client5.http.async.methods.SimpleHttpRequest; +import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; +import org.apache.hc.core5.io.CloseMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xerial.snappy.Snappy; + +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; + +/** Writer, taking care of batching the {@link PrometheusTimeSeries} and handling retries. */ +public class PrometheusSinkWriter extends AsyncSinkWriter<PrometheusTimeSeries, Types.TimeSeries> { + + /** + * * Batching of this sink is in terms of Samples, not bytes. The goal is adaptively increase + * the number of Samples in each batch, a WriteRequest sent to Prometheus, to a configurable + * number. This is the parameter maxBatchSizeInBytes. + * + * <p>getSizeInBytes(requestEntry) returns the number of Samples (not bytes) and + * maxBatchSizeInBytes is actually in terms of Samples (not bytes). + * + * <p>In AsyncSinkWriter, maxBatchSize is in terms of requestEntries (TimeSeries). But because + * each TimeSeries contains 1+ Samples, we set maxBatchSize = maxBatchSizeInBytes. + * + * <p>maxRecordSizeInBytes is also calculated in the same unit assumed by getSizeInBytes(...). + * In our case is the max number of Samples in a single TimeSeries sent to the Sink. We are + * limiting the number of Samples in each TimeSeries to the max batch size, setting + * maxRecordSizeInBytes = maxBatchSizeInBytes. + */ Review Comment: Should be moved to class javadoc comment -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
