public static Metric getMetricToAnnotate ( String metric ) { Metric result = null ; if ( metric != null && ! metric . isEmpty ( ) ) { Pattern pattern = Pattern . compile ( "([\\w,\\-,\\.,/]+):([\\w,\\-,\\.,/]+)(\\{(?:[\\w,\\-,\\.,/]+=[\\w,\\-,\\.,/,\\*,|]+)(?:,[\\w,\\-,\\.,/]+=[\\w,\\-,\\.,/,\\*,|]+)*\\})?:([\\w,\\-,\\.,/]+)" ) ; Matcher matcher = pattern . matcher ( metric . replaceAll ( "\\s" , "" ) ) ; if ( matcher . matches ( ) ) { String scopeName = matcher . group ( 1 ) ; String metricName = matcher . group ( 2 ) ; String tagString = matcher . group ( 3 ) ; Map < String , String > tags = new HashMap <> ( ) ; if ( tagString != null ) { tagString = tagString . replaceAll ( "\\{" , "" ) . replaceAll ( "\\}" , "" ) ; for ( String tag : tagString . split ( "," ) ) { String [ ] entry = tag . split ( "=" ) ; tags . put ( entry [ 0 ] , entry [ 1 ] ) ; } } result = new Metric ( scopeName , metricName ) ; result . setTags ( tags ) ; } } return result ; }
Given a metric to annotate expression return a corresponding metric object .