|
23 | 23 | import io.micrometer.core.instrument.Tag;
|
24 | 24 | import io.micrometer.core.instrument.Tags;
|
25 | 25 |
|
26 |
| -import java.util.Collection; |
27 | 26 | import java.util.Collections;
|
28 | 27 | import java.util.concurrent.atomic.AtomicLong;
|
29 | 28 |
|
@@ -69,6 +68,10 @@ public MicrometerMetricsCollector(final MeterRegistry registry, final String pre
|
69 | 68 | }
|
70 | 69 |
|
71 | 70 | public MicrometerMetricsCollector(final MeterRegistry registry, final String prefix, final String ... tags) {
|
| 71 | + this(registry, prefix, Tags.zip(tags)); |
| 72 | + } |
| 73 | + |
| 74 | + public MicrometerMetricsCollector(final MeterRegistry registry, final String prefix, final Iterable<Tag> tags) { |
72 | 75 | this(new MetricsCreator() {
|
73 | 76 | @Override
|
74 | 77 | public Object create(Metrics metric) {
|
@@ -153,56 +156,55 @@ public Counter getRejectedMessages() {
|
153 | 156 | public enum Metrics {
|
154 | 157 | CONNECTIONS {
|
155 | 158 | @Override
|
156 |
| - Object create(MeterRegistry registry, String prefix, String... tags) { |
157 |
| - return registry.gauge(prefix + ".connections", tags(tags), new AtomicLong(0)); |
| 159 | + Object create(MeterRegistry registry, String prefix, Iterable<Tag> tags) { |
| 160 | + return registry.gauge(prefix + ".connections", tags, new AtomicLong(0)); |
158 | 161 | }
|
159 | 162 | },
|
160 | 163 | CHANNELS {
|
161 | 164 | @Override
|
162 |
| - Object create(MeterRegistry registry, String prefix, String... tags) { |
163 |
| - return registry.gauge(prefix + ".channels", tags(tags), new AtomicLong(0)); |
| 165 | + Object create(MeterRegistry registry, String prefix, Iterable<Tag> tags) { |
| 166 | + return registry.gauge(prefix + ".channels", tags, new AtomicLong(0)); |
164 | 167 | }
|
165 | 168 | },
|
166 | 169 | PUBLISHED_MESSAGES {
|
167 | 170 | @Override
|
168 |
| - Object create(MeterRegistry registry, String prefix, String... tags) { |
| 171 | + Object create(MeterRegistry registry, String prefix, Iterable<Tag> tags) { |
169 | 172 | return registry.counter(prefix + ".published", tags);
|
170 | 173 | }
|
171 | 174 | },
|
172 | 175 | CONSUMED_MESSAGES {
|
173 | 176 | @Override
|
174 |
| - Object create(MeterRegistry registry, String prefix, String... tags) { |
| 177 | + Object create(MeterRegistry registry, String prefix, Iterable<Tag> tags) { |
175 | 178 | return registry.counter(prefix + ".consumed", tags);
|
176 | 179 | }
|
177 | 180 | },
|
178 | 181 | ACKNOWLEDGED_MESSAGES {
|
179 | 182 | @Override
|
180 |
| - Object create(MeterRegistry registry, String prefix, String... tags) { |
| 183 | + Object create(MeterRegistry registry, String prefix, Iterable<Tag> tags) { |
181 | 184 | return registry.counter(prefix + ".acknowledged", tags);
|
182 | 185 | }
|
183 | 186 | },
|
184 | 187 | REJECTED_MESSAGES {
|
185 | 188 | @Override
|
186 |
| - Object create(MeterRegistry registry, String prefix, String... tags) { |
| 189 | + Object create(MeterRegistry registry, String prefix, Iterable<Tag> tags) { |
187 | 190 | return registry.counter(prefix + ".rejected", tags);
|
188 | 191 | }
|
189 | 192 | };
|
190 | 193 |
|
| 194 | + /** |
| 195 | + * |
| 196 | + * @param registry |
| 197 | + * @param prefix |
| 198 | + * @deprecated will be removed in 6.0.0 |
| 199 | + * @return |
| 200 | + */ |
| 201 | + @Deprecated |
191 | 202 | Object create(MeterRegistry registry, String prefix) {
|
192 |
| - return this.create(registry, prefix, new String[] {}); |
| 203 | + return this.create(registry, prefix, Collections.EMPTY_LIST); |
193 | 204 | }
|
194 | 205 |
|
195 |
| - abstract Object create(MeterRegistry registry, String prefix, String... tags); |
| 206 | + abstract Object create(MeterRegistry registry, String prefix, Iterable<Tag> tags); |
196 | 207 |
|
197 |
| - private static Iterable<Tag> tags(String... tagStrings) { |
198 |
| - Collection<Tag> tags; |
199 |
| - if (tagStrings != null && tagStrings.length > 0) { |
200 |
| - tags = Tags.zip(tagStrings); |
201 |
| - } else { |
202 |
| - tags = Collections.emptyList(); |
203 |
| - } |
204 |
| - return tags; |
205 |
| - } |
206 | 208 | }
|
207 | 209 |
|
208 | 210 | public interface MetricsCreator {
|
|
0 commit comments