private static String encodeMetricFilters(String metricString,Map<String,String> mapper){
  String finalString=metricString;
  int counter=0;
  int startIndex=0;
  int endIndex=0;
  for (int i=0; i < metricString.length(); i++) {
    char currentChar=metricString.charAt(i);
    startIndex=(currentChar == '(' && counter == 0) ? i : startIndex;
    counter=(currentChar == '(') ? counter + 1 : counter;
    if (currentChar == ')') {
      endIndex=i;
      counter=counter - 1;
    }
    if (counter == 0 && startIndex != 0) {
      String filterString=metricString.substring(startIndex,endIndex + 1);
      finalString=finalString.replace(filterString,"-" + startIndex);
      mapper.put("-" + startIndex,filterString);
      startIndex=0;
    }
  }
  return finalString;
}

private static String encodeMetricFilters ( String metricString , Map < String , String > mapper ) { String finalString = metricString ; int counter = 0 ; int startIndex = 0 ; int endIndex = 0 ; for ( int i = 0 ; i < metricString . length ( ) ; i ++ ) { char currentChar = metricString . charAt ( i ) ; startIndex = ( currentChar == '(' && counter == 0 ) ? i : startIndex ; counter = ( currentChar == '(' ) ? counter + 1 : counter ; if ( currentChar == ')' ) { endIndex = i ; counter = counter - 1 ; } if ( counter == 0 && startIndex != 0 ) { String filterString = metricString . substring ( startIndex , endIndex + 1 ) ; finalString = finalString . replace ( filterString , "-" + startIndex ) ; mapper . put ( "-" + startIndex , filterString ) ; startIndex = 0 ; } } return finalString ; }
returns modified metrics string . aggregated metric filter details are stripped and stored in mapper . metric filter is replaced by hashkey which can be used to retrieve the filter from the mapper
