@@ -57,29 +57,34 @@ void registryIntegration() {
5757 // end::registry_integration_factory[]
5858
5959 // @formatter:off
60- // tag::registry_integration_full_config []
60+ // tag::registry_integration_builder []
6161 registry .config ().withHighCardinalityTagsDetector (r ->
62- new HighCardinalityTagsDetector (
63- r ,
64- 1000 , // 1000 different meters with the same name
65- Duration .ofMinutes (5 ), // check ~every 5 minutes
66- name -> alert ("High cardinality meter: " + name )
67- )
62+ new HighCardinalityTagsDetector .Builder (r )
63+ .threshold (1000 ) // 1000 different meters with the same name
64+ .delay (Duration .ofMinutes (5 )) // check ~every 5 minutes
65+ .highCardinalityMeterInfoConsumer (info -> alert ("Nooo!" ))
66+ .build ()
6867 );
69- // end::registry_integration_full_config []
68+ // end::registry_integration_builder []
7069 // @formatter:on
7170 }
7271
7372 @ Test
7473 void oneTimeCheck () {
7574 // tag::one_time_check[]
76- try (HighCardinalityTagsDetector detector = new HighCardinalityTagsDetector (registry , 10 ,
77- Duration . ofMinutes ( 1 ) )) {
75+ try (HighCardinalityTagsDetector detector = new HighCardinalityTagsDetector . Builder (registry ). threshold ( 10 )
76+ . build ( )) {
7877 // Create meters with a high cardinality tag (uid)
7978 for (int i = 0 ; i < 15 ; i ++) {
8079 registry .counter ("requests" , "uid" , String .valueOf (i )).increment ();
8180 }
81+
8282 assertThat (detector .findFirst ()).isNotEmpty ().get ().isEqualTo ("requests" );
83+ assertThat (detector .findFirstHighCardinalityMeterInfo ()).isNotEmpty ().get ().satisfies (info -> {
84+ assertThat (info .getName ()).isEqualTo ("requests" );
85+ assertThat (info .getCount ()).isEqualTo (15 );
86+ });
87+
8388 }
8489 // detector.close() is implicit here but don't forget to close it otherwise!
8590 // end::one_time_check[]
@@ -94,7 +99,9 @@ void customConsumer() {
9499 // @formatter:off
95100 // tag::custom_consumer_config[]
96101 registry .config ().withHighCardinalityTagsDetector (r ->
97- new HighCardinalityTagsDetector (r , 10 , Duration .ofMinutes (1 ), this ::recordHighCardinalityEvent )
102+ new HighCardinalityTagsDetector .Builder (r ).threshold (10 )
103+ .highCardinalityMeterInfoConsumer (this ::recordHighCardinalityEvent )
104+ .build ()
98105 );
99106 // end::custom_consumer_config[]
100107 // @formatter:on
@@ -104,9 +111,9 @@ void customConsumer() {
104111 }
105112
106113 // tag::custom_consumer[]
107- void recordHighCardinalityEvent (String name ) {
108- alert ("High cardinality meter: " + name );
109- registry .counter ("highCardinality.detections" ).increment ();
114+ void recordHighCardinalityEvent (HighCardinalityTagsDetector . HighCardinalityMeterInfo info ) {
115+ alert ("High cardinality detected in " + info . getName () + " with " + info . getCount () + " meters!" );
116+ registry .counter ("highCardinality.detections" , "meter" , info . getName () ).increment ();
110117 }
111118 // end::custom_consumer[]
112119
0 commit comments