18
18
package org .apache .flink .connector .prometheus .sink ;
19
19
20
20
import org .apache .flink .annotation .PublicEvolving ;
21
- import org .apache .flink .connector .base .sink .AsyncSinkBase ;
22
21
import org .apache .flink .connector .base .sink .AsyncSinkBaseBuilder ;
22
+ import org .apache .flink .connector .base .sink .writer .ElementConverter ;
23
23
import org .apache .flink .connector .prometheus .sink .http .PrometheusAsyncHttpClientBuilder ;
24
24
import org .apache .flink .connector .prometheus .sink .prometheus .Types ;
25
25
30
30
31
31
/** Builder for Sink implementation. */
32
32
@ PublicEvolving
33
- public class PrometheusSinkBuilder
34
- extends AsyncSinkBaseBuilder <
35
- PrometheusTimeSeries , Types .TimeSeries , PrometheusSinkBuilder > {
33
+ public class PrometheusSinkBuilder <InputT >
34
+ extends AsyncSinkBaseBuilder <InputT , Types .TimeSeries , PrometheusSinkBuilder <InputT >> {
36
35
private static final Logger LOG = LoggerFactory .getLogger (PrometheusSinkBuilder .class );
37
36
38
37
// Max batch size, in number of samples
@@ -52,14 +51,21 @@ public class PrometheusSinkBuilder
52
51
private Integer socketTimeoutMs ;
53
52
private PrometheusRequestSigner requestSigner = null ;
54
53
private Integer maxBatchSizeInSamples ;
55
- private Integer maxRecordSizeInSamples ;
54
+ private Long maxRecordSizeInSamples ;
56
55
private String httpUserAgent = null ;
57
56
private PrometheusSinkConfiguration .SinkWriterErrorHandlingBehaviorConfiguration
58
57
errorHandlingBehaviorConfig = null ;
58
+ private ElementConverter <InputT , Types .TimeSeries > elementConverter ;
59
59
private String metricGroupName = null ;
60
60
61
+ public PrometheusSinkBuilder <InputT > setElementConverter (
62
+ ElementConverter <InputT , Types .TimeSeries > elementConverter ) {
63
+ this .elementConverter = elementConverter ;
64
+ return this ;
65
+ }
66
+
61
67
@ Override
62
- public AsyncSinkBase < PrometheusTimeSeries , Types . TimeSeries > build () {
68
+ public PrometheusSink < InputT > build () {
63
69
64
70
int actualMaxBatchSizeInSamples =
65
71
Optional .ofNullable (maxBatchSizeInSamples )
@@ -69,8 +75,9 @@ public AsyncSinkBase<PrometheusTimeSeries, Types.TimeSeries> build() {
69
75
long actualMaxTimeInBufferMS =
70
76
Optional .ofNullable (getMaxTimeInBufferMS ()).orElse (DEFAULT_MAX_TIME_IN_BUFFER_MS );
71
77
72
- int actualMaxRecordSizeInSamples =
73
- Optional .ofNullable (maxRecordSizeInSamples ).orElse (actualMaxBatchSizeInSamples );
78
+ long actualMaxRecordSizeInSamples =
79
+ Optional .ofNullable (maxRecordSizeInSamples )
80
+ .orElse ((long ) actualMaxBatchSizeInSamples );
74
81
75
82
int actualSocketTimeoutMs =
76
83
Optional .ofNullable (socketTimeoutMs )
@@ -116,8 +123,8 @@ public AsyncSinkBase<PrometheusTimeSeries, Types.TimeSeries> build() {
116
123
actualErrorHandlingBehaviorConfig .getOnMaxRetryExceeded (),
117
124
actualErrorHandlingBehaviorConfig .getOnPrometheusNonRetryableError ());
118
125
119
- return new PrometheusSink (
120
- new PrometheusTimeSeriesConverter ( ),
126
+ return new PrometheusSink <> (
127
+ Optional . ofNullable ( elementConverter ). orElse ( new PrometheusTimeSeriesConverter <>() ),
121
128
MAX_IN_FLIGHT_REQUESTS ,
122
129
actualMaxBufferedRequests ,
123
130
actualMaxBatchSizeInSamples ,
@@ -132,50 +139,51 @@ public AsyncSinkBase<PrometheusTimeSeries, Types.TimeSeries> build() {
132
139
actualMetricGroupName );
133
140
}
134
141
135
- public PrometheusSinkBuilder setPrometheusRemoteWriteUrl (String prometheusRemoteWriteUrl ) {
142
+ public PrometheusSinkBuilder <InputT > setPrometheusRemoteWriteUrl (
143
+ String prometheusRemoteWriteUrl ) {
136
144
this .prometheusRemoteWriteUrl = prometheusRemoteWriteUrl ;
137
145
return this ;
138
146
}
139
147
140
- public PrometheusSinkBuilder setRequestSigner (PrometheusRequestSigner requestSigner ) {
148
+ public PrometheusSinkBuilder < InputT > setRequestSigner (PrometheusRequestSigner requestSigner ) {
141
149
this .requestSigner = requestSigner ;
142
150
return this ;
143
151
}
144
152
145
- public PrometheusSinkBuilder setMaxBatchSizeInSamples (int maxBatchSizeInSamples ) {
153
+ public PrometheusSinkBuilder < InputT > setMaxBatchSizeInSamples (int maxBatchSizeInSamples ) {
146
154
this .maxBatchSizeInSamples = maxBatchSizeInSamples ;
147
155
return this ;
148
156
}
149
157
150
- public PrometheusSinkBuilder setMaxRecordSizeInSamples (int maxRecordSizeInSamples ) {
158
+ public PrometheusSinkBuilder < InputT > setMaxRecordSizeInSamples (long maxRecordSizeInSamples ) {
151
159
this .maxRecordSizeInSamples = maxRecordSizeInSamples ;
152
160
return this ;
153
161
}
154
162
155
- public PrometheusSinkBuilder setRetryConfiguration (
163
+ public PrometheusSinkBuilder < InputT > setRetryConfiguration (
156
164
PrometheusSinkConfiguration .RetryConfiguration retryConfiguration ) {
157
165
this .retryConfiguration = retryConfiguration ;
158
166
return this ;
159
167
}
160
168
161
- public PrometheusSinkBuilder setSocketTimeoutMs (int socketTimeoutMs ) {
169
+ public PrometheusSinkBuilder < InputT > setSocketTimeoutMs (int socketTimeoutMs ) {
162
170
this .socketTimeoutMs = socketTimeoutMs ;
163
171
return this ;
164
172
}
165
173
166
- public PrometheusSinkBuilder setHttpUserAgent (String httpUserAgent ) {
174
+ public PrometheusSinkBuilder < InputT > setHttpUserAgent (String httpUserAgent ) {
167
175
this .httpUserAgent = httpUserAgent ;
168
176
return this ;
169
177
}
170
178
171
- public PrometheusSinkBuilder setErrorHandlingBehaviorConfiguration (
179
+ public PrometheusSinkBuilder < InputT > setErrorHandlingBehaviorConfiguration (
172
180
PrometheusSinkConfiguration .SinkWriterErrorHandlingBehaviorConfiguration
173
181
errorHandlingBehaviorConfig ) {
174
182
this .errorHandlingBehaviorConfig = errorHandlingBehaviorConfig ;
175
183
return this ;
176
184
}
177
185
178
- public PrometheusSinkBuilder setMetricGroupName (String metricGroupName ) {
186
+ public PrometheusSinkBuilder < InputT > setMetricGroupName (String metricGroupName ) {
179
187
this .metricGroupName = metricGroupName ;
180
188
return this ;
181
189
}
@@ -184,20 +192,20 @@ public PrometheusSinkBuilder setMetricGroupName(String metricGroupName) {
184
192
185
193
/** Not supported. Use setMaxBatchSizeInSamples(int) instead */
186
194
@ Override
187
- public PrometheusSinkBuilder setMaxBatchSize (int maxBatchSize ) {
195
+ public PrometheusSinkBuilder < InputT > setMaxBatchSize (int maxBatchSize ) {
188
196
throw new UnsupportedOperationException ("maxBatchSize is not supported by this sink" );
189
197
}
190
198
191
199
/** Not supported. Use setMaxBatchSizeInSamples(int) instead */
192
200
@ Override
193
- public PrometheusSinkBuilder setMaxBatchSizeInBytes (long maxBatchSizeInBytes ) {
201
+ public PrometheusSinkBuilder < InputT > setMaxBatchSizeInBytes (long maxBatchSizeInBytes ) {
194
202
throw new UnsupportedOperationException (
195
203
"maxBatchSizeInBytes is not supported by this sink" );
196
204
}
197
205
198
206
/** Not supported. Use setMaxRecordSizeInSamples(int) instead */
199
207
@ Override
200
- public PrometheusSinkBuilder setMaxRecordSizeInBytes (long maxRecordSizeInBytes ) {
208
+ public PrometheusSinkBuilder < InputT > setMaxRecordSizeInBytes (long maxRecordSizeInBytes ) {
201
209
throw new UnsupportedOperationException (
202
210
"maxRecordSizeInBytes is not supported by this sink" );
203
211
}
0 commit comments