@Test public void testHostAnnotator() throws Exception { ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class); Channel channel = createMock(Channel.class); InetSocketAddress remote = new InetSocketAddress(InetAddress.getLocalHost(), 2878); expect(ctx.channel()).andReturn(channel).anyTimes(); expect(channel.remoteAddress()).andReturn(remote).anyTimes(); replay(channel, ctx); SharedGraphiteHostAnnotator annotator = new SharedGraphiteHostAnnotator( ImmutableList.of("tag1", "tag2", "tag3"), x -> "default"); String point; point = "request.count 1 source=test.wavefront.com"; assertEquals(point, annotator.apply(ctx, point)); point = "\"request.count\" 1 \"source\"=\"test.wavefront.com\""; assertEquals(point, annotator.apply(ctx, point)); point = "request.count 1 host=test.wavefront.com"; assertEquals(point, annotator.apply(ctx, point)); point = "request.count 1 \"host\"=test.wavefront.com"; assertEquals(point, annotator.apply(ctx, point)); point = "request.count 1 tag1=test.wavefront.com"; assertEquals(point, annotator.apply(ctx, point)); point = "request.count 1 tag2=\"test.wavefront.com\""; assertEquals(point, annotator.apply(ctx, point)); point = "request.count 1 tag3=test.wavefront.com"; assertEquals(point, annotator.apply(ctx, point)); point = "request.count 1 tag4=test.wavefront.com"; assertEquals("request.count 1 tag4=test.wavefront.com source=\"default\"", annotator.apply(ctx, point)); }
public String apply(ChannelHandlerContext ctx, String msg) { for (int i = 0; i < sourceTags.size(); i++) { String tag = sourceTags.get(i); int strIndex = msg.indexOf(tag); if (strIndex > -1 && msg.length() - strIndex - tag.length() > 0 && msg.charAt(strIndex + tag.length()) > ' ') { return msg; } } return msg + " source=\"" + hostnameResolver.apply(getRemoteAddress(ctx)) + "\""; }
SharedGraphiteHostAnnotator { public String apply(ChannelHandlerContext ctx, String msg) { for (int i = 0; i < sourceTags.size(); i++) { String tag = sourceTags.get(i); int strIndex = msg.indexOf(tag); if (strIndex > -1 && msg.length() - strIndex - tag.length() > 0 && msg.charAt(strIndex + tag.length()) > ' ') { return msg; } } return msg + " source=\"" + hostnameResolver.apply(getRemoteAddress(ctx)) + "\""; } }
SharedGraphiteHostAnnotator { public String apply(ChannelHandlerContext ctx, String msg) { for (int i = 0; i < sourceTags.size(); i++) { String tag = sourceTags.get(i); int strIndex = msg.indexOf(tag); if (strIndex > -1 && msg.length() - strIndex - tag.length() > 0 && msg.charAt(strIndex + tag.length()) > ' ') { return msg; } } return msg + " source=\"" + hostnameResolver.apply(getRemoteAddress(ctx)) + "\""; } SharedGraphiteHostAnnotator(@Nullable List<String> customSourceTags,
                                     @Nonnull Function<InetAddress, String> hostnameResolver); }
SharedGraphiteHostAnnotator { public String apply(ChannelHandlerContext ctx, String msg) { for (int i = 0; i < sourceTags.size(); i++) { String tag = sourceTags.get(i); int strIndex = msg.indexOf(tag); if (strIndex > -1 && msg.length() - strIndex - tag.length() > 0 && msg.charAt(strIndex + tag.length()) > ' ') { return msg; } } return msg + " source=\"" + hostnameResolver.apply(getRemoteAddress(ctx)) + "\""; } SharedGraphiteHostAnnotator(@Nullable List<String> customSourceTags,
                                     @Nonnull Function<InetAddress, String> hostnameResolver); String apply(ChannelHandlerContext ctx, String msg); }
SharedGraphiteHostAnnotator { public String apply(ChannelHandlerContext ctx, String msg) { for (int i = 0; i < sourceTags.size(); i++) { String tag = sourceTags.get(i); int strIndex = msg.indexOf(tag); if (strIndex > -1 && msg.length() - strIndex - tag.length() > 0 && msg.charAt(strIndex + tag.length()) > ' ') { return msg; } } return msg + " source=\"" + hostnameResolver.apply(getRemoteAddress(ctx)) + "\""; } SharedGraphiteHostAnnotator(@Nullable List<String> customSourceTags,
                                     @Nonnull Function<InetAddress, String> hostnameResolver); String apply(ChannelHandlerContext ctx, String msg);  }