ElasticSearchAnnotationService extends DefaultService implements AnnotationStorageService { @VisibleForTesting static String getHashedSearchIdentifier(AnnotationQuery annotationQuery) { HashFunction hf = Hashing.murmur3_128(); String searchIdentifier = new StringBuilder().append(annotationQuery.getScope()).append(annotationQuery.getMetric()) .append(annotationQuery.getTags().toString()).append(annotationQuery.getType()).toString(); return hf.newHasher().putString(searchIdentifier, Charset.defaultCharset()).hash().toString(); } @Inject  ElasticSearchAnnotationService(SystemConfiguration config, MonitorService monitorService, ElasticSearchUtils esUtils); @Override void dispose(); @Override void putAnnotations(List<Annotation> annotations); @Override List<Annotation> getAnnotations(List<AnnotationQuery> queries); static final int ANNOTATION_INDEX_MAX_RESULT_WINDOW; static String ANNOTATION_INDEX_TEMPLATE_PATTERN_START; }
@Test public void testHashedSearchIdentifierAnnotationAndAnnotationQueryMatch(){ Map<String, String> annotationQueryTags = new HashMap<>(); annotationQueryTags.put("device","device1"); annotationQueryTags.put("podName","pod1"); AnnotationQuery annotationQuery = new AnnotationQuery("scope1", "metric1", annotationQueryTags, "transactionId", 1557809359073L, 1557809599073L); Annotation annotation = new Annotation("source", "16ab4b56311", "transactionId", "scope1", "metric1", 1557809559073L); annotation.setTags(annotationQueryTags); assertEquals(AnnotationRecordList.getHashedSearchIdentifier(annotation), ElasticSearchAnnotationService.getHashedSearchIdentifier(annotationQuery)); Map<String, String> annotationQueryTags2 = new HashMap<>(); annotationQueryTags2.put("podName","pod1"); annotationQueryTags2.put("device","device1"); AnnotationQuery annotationQuery2 = new AnnotationQuery("scope1", "metric1", annotationQueryTags2, "transactionId", 1557809359073L, 1557809599073L); assertEquals(AnnotationRecordList.getHashedSearchIdentifier(annotation), ElasticSearchAnnotationService.getHashedSearchIdentifier(annotationQuery2)); }