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