|
14 | 14 | package com.rabbitmq.stream.observation.micrometer; |
15 | 15 |
|
16 | 16 | import com.rabbitmq.stream.ObservationCollector; |
| 17 | +import io.micrometer.observation.Observation; |
| 18 | +import io.micrometer.observation.ObservationConvention; |
17 | 19 | import io.micrometer.observation.ObservationRegistry; |
| 20 | +import java.util.function.Supplier; |
18 | 21 |
|
| 22 | +/** |
| 23 | + * Builder to configure and create <a href="https://micrometer.io/docs/observation">Micrometer |
| 24 | + * Observation</a> implementation of {@link ObservationCollector}. |
| 25 | + * |
| 26 | + * @since 0.12.0 |
| 27 | + */ |
19 | 28 | public class MicrometerObservationCollectorBuilder { |
20 | 29 |
|
21 | 30 | private ObservationRegistry registry = ObservationRegistry.NOOP; |
22 | | - private PublishObservationConvention customPublishConvention; |
23 | | - private PublishObservationConvention defaultPublishConvention = |
| 31 | + private PublishObservationConvention customPublishObservationConvention; |
| 32 | + private PublishObservationConvention defaultPublishObservationConvention = |
24 | 33 | new DefaultPublishObservationConvention(); |
25 | | - private ProcessObservationConvention customProcessConvention; |
26 | | - private ProcessObservationConvention defaultProcessConvention = |
| 34 | + private ProcessObservationConvention customProcessObservationConvention; |
| 35 | + private ProcessObservationConvention defaultProcessObservationConvention = |
27 | 36 | new DefaultProcessObservationConvention(); |
28 | 37 |
|
| 38 | + /** |
| 39 | + * Set the {@link ObservationRegistry} to use. |
| 40 | + * |
| 41 | + * <p>Default is {@link ObservationRegistry#NOOP}. |
| 42 | + * |
| 43 | + * @param registry the registry |
| 44 | + * @return this builder instance |
| 45 | + */ |
29 | 46 | public MicrometerObservationCollectorBuilder registry(ObservationRegistry registry) { |
30 | 47 | this.registry = registry; |
31 | 48 | return this; |
32 | 49 | } |
33 | 50 |
|
34 | | - public MicrometerObservationCollectorBuilder customPublishConvention( |
35 | | - PublishObservationConvention customPublishConvention) { |
36 | | - this.customPublishConvention = customPublishConvention; |
| 51 | + /** |
| 52 | + * Custom convention for publishing. |
| 53 | + * |
| 54 | + * <p>If not null, it will override any pre-configured conventions. |
| 55 | + * |
| 56 | + * <p>Default is <code>null</code>. |
| 57 | + * |
| 58 | + * @param customPublishObservationConvention the convention |
| 59 | + * @return this builder instance |
| 60 | + * @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention, |
| 61 | + * ObservationConvention, Supplier, ObservationRegistry) |
| 62 | + */ |
| 63 | + public MicrometerObservationCollectorBuilder customPublishObservationConvention( |
| 64 | + PublishObservationConvention customPublishObservationConvention) { |
| 65 | + this.customPublishObservationConvention = customPublishObservationConvention; |
37 | 66 | return this; |
38 | 67 | } |
39 | 68 |
|
40 | | - public MicrometerObservationCollectorBuilder defaultPublishConvention( |
41 | | - PublishObservationConvention defaultPublishConvention) { |
42 | | - this.defaultPublishConvention = defaultPublishConvention; |
| 69 | + /** |
| 70 | + * Default convention for publishing. |
| 71 | + * |
| 72 | + * <p>It will be picked if there was neither custom convention nor a pre-configured one via {@link |
| 73 | + * ObservationRegistry}. |
| 74 | + * |
| 75 | + * <p>Default is {@link DefaultPublishObservationConvention}. |
| 76 | + * |
| 77 | + * @param defaultPublishObservationConvention the convention |
| 78 | + * @return this builder instance |
| 79 | + * @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention, |
| 80 | + * ObservationConvention, Supplier, ObservationRegistry) |
| 81 | + */ |
| 82 | + public MicrometerObservationCollectorBuilder defaultPublishObservationConvention( |
| 83 | + PublishObservationConvention defaultPublishObservationConvention) { |
| 84 | + this.defaultPublishObservationConvention = defaultPublishObservationConvention; |
43 | 85 | return this; |
44 | 86 | } |
45 | 87 |
|
46 | | - public MicrometerObservationCollectorBuilder customProcessConvention( |
47 | | - ProcessObservationConvention customProcessConvention) { |
48 | | - this.customProcessConvention = customProcessConvention; |
| 88 | + /** |
| 89 | + * Custom convention for consuming. |
| 90 | + * |
| 91 | + * <p>If not null, it will override any pre-configured conventions. |
| 92 | + * |
| 93 | + * <p>Default is <code>null</code>. |
| 94 | + * |
| 95 | + * @param customProcessObservationConvention the convention |
| 96 | + * @return this builder instance |
| 97 | + * @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention, |
| 98 | + * ObservationConvention, Supplier, ObservationRegistry) |
| 99 | + */ |
| 100 | + public MicrometerObservationCollectorBuilder customProcessObservationConvention( |
| 101 | + ProcessObservationConvention customProcessObservationConvention) { |
| 102 | + this.customProcessObservationConvention = customProcessObservationConvention; |
49 | 103 | return this; |
50 | 104 | } |
51 | 105 |
|
52 | | - public MicrometerObservationCollectorBuilder defaultProcessConvention( |
53 | | - ProcessObservationConvention defaultProcessConvention) { |
54 | | - this.defaultProcessConvention = defaultProcessConvention; |
| 106 | + /** |
| 107 | + * Default convention for consuming. |
| 108 | + * |
| 109 | + * <p>It will be picked if there was neither custom convention nor a pre-configured one via {@link |
| 110 | + * ObservationRegistry}. |
| 111 | + * |
| 112 | + * <p>Default is {@link DefaultProcessObservationConvention}. |
| 113 | + * |
| 114 | + * @param defaultProcessObservationConvention the convention |
| 115 | + * @return this builder instance |
| 116 | + * @see io.micrometer.observation.docs.ObservationDocumentation#observation(ObservationConvention, |
| 117 | + * ObservationConvention, Supplier, ObservationRegistry) |
| 118 | + * @since 0.12.0 |
| 119 | + */ |
| 120 | + public MicrometerObservationCollectorBuilder defaultProcessObservationConvention( |
| 121 | + ProcessObservationConvention defaultProcessObservationConvention) { |
| 122 | + this.defaultProcessObservationConvention = defaultProcessObservationConvention; |
55 | 123 | return this; |
56 | 124 | } |
57 | 125 |
|
58 | | - public ObservationCollector build() { |
| 126 | + /** |
| 127 | + * Create the Micrometer {@link ObservationCollector}. |
| 128 | + * |
| 129 | + * @return the Micrometer observation collector |
| 130 | + */ |
| 131 | + public ObservationCollector<Observation> build() { |
59 | 132 | return new MicrometerObservationCollector( |
60 | 133 | this.registry, |
61 | | - this.customPublishConvention, |
62 | | - this.defaultPublishConvention, |
63 | | - this.customProcessConvention, |
64 | | - this.defaultProcessConvention); |
| 134 | + this.customPublishObservationConvention, |
| 135 | + this.defaultPublishObservationConvention, |
| 136 | + this.customProcessObservationConvention, |
| 137 | + this.defaultProcessObservationConvention); |
65 | 138 | } |
66 | 139 | } |
0 commit comments