Java Code Examples for io.micrometer.core.instrument.Tag#of()

The following examples show how to use io.micrometer.core.instrument.Tag#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RntbdTransportClientTest.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
private FakeEndpoint(
    final Config config, final RntbdRequestTimer timer, final URI physicalAddress,
    final RntbdResponse... expected
) {

    final ArrayBlockingQueue<RntbdResponse> responses = new ArrayBlockingQueue<>(
        expected.length, true, Arrays.asList(expected)
    );

    RntbdRequestManager requestManager = new RntbdRequestManager(new RntbdClientChannelHealthChecker(config), 30);
    this.physicalAddress = physicalAddress;
    this.requestTimer = timer;

    this.fakeChannel = new FakeChannel(responses,
        new RntbdContextNegotiator(requestManager, config.userAgent()),
        new RntbdRequestEncoder(),
        new RntbdResponseDecoder(),
        requestManager
    );

    this.tag = Tag.of(FakeEndpoint.class.getSimpleName(), this.fakeChannel.remoteAddress().toString());
}
 
Example 2
Source File: WebMvcTags.java    From foremast with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@code uri} tag based on the URI of the given {@code request}. Uses the
 * {@link HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE} best matching pattern if
 * available. Falling back to {@code REDIRECTION} for 3xx responses, {@code NOT_FOUND}
 * for 404 responses, {@code root} for requests with no path info, and {@code UNKNOWN}
 * for all other requests.
 *
 * @param request the request
 * @param response the response
 * @return the uri tag derived from the request
 */
public static Tag uri(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response) {
    if (request != null) {
        String pattern = getMatchingPattern(request);
        if (pattern != null) {
            return Tag.of("uri", pattern);
        } else if (response != null) {
            HttpStatus status = extractStatus(response);
            if (status != null && status.is3xxRedirection()) {
                return URI_REDIRECTION;
            }
            if (status != null && status.equals(HttpStatus.NOT_FOUND)) {
                return URI_NOT_FOUND;
            }
        }
        String pathInfo = getPathInfo(request);
        if (pathInfo.isEmpty()) {
            return URI_ROOT;
        }
    }
    return URI_UNKNOWN;
}
 
Example 3
Source File: PingPongApp.java    From spring-cloud-rsocket with Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
	ConfigurableEnvironment env = event.getApplicationContext().getEnvironment();
	Integer pongDelay = env.getProperty("pong.delay", Integer.class, 5000);
	try {
		Thread.sleep(pongDelay);
	}
	catch (InterruptedException e) {
		e.printStackTrace();
	}
	log.info("Starting Pong");
	Integer gatewayPort = env.getProperty("spring.rsocket.server.port",
			Integer.class, 7002);
	MicrometerRSocketInterceptor interceptor = new MicrometerRSocketInterceptor(
			meterRegistry, Tag.of("component", "pong"));

	ByteBuf announcementMetadata = getRouteSetupMetadata(strategies, "pong", 3L);
	RSocketFactory.connect().metadataMimeType(COMPOSITE_MIME_TYPE.toString())
			.setupPayload(
					DefaultPayload.create(EMPTY_BUFFER, announcementMetadata))
			.addRequesterPlugin(interceptor).acceptor(this::accept)
			.transport(TcpClientTransport.create(gatewayPort)) // proxy
			.start().block();
}
 
Example 4
Source File: JettyClientTags.java    From micrometer with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@code uri} tag based on the URI of the given {@code result}.
 * {@code REDIRECTION} for 3xx responses, {@code NOT_FOUND} for 404 responses.
 *
 * @param result the request result
 * @param successfulUriPattern successful URI pattern
 * @return the uri tag derived from the request result
 */
public static Tag uri(Result result, Function<Result, String> successfulUriPattern) {
    Response response = result.getResponse();
    if (response != null) {
        int status = response.getStatus();
        if (HttpStatus.isRedirection(status)) {
            return URI_REDIRECTION;
        }
        if (status == 404) {
            return URI_NOT_FOUND;
        }
    }

    String matchingPattern = successfulUriPattern.apply(result);
    matchingPattern = MULTIPLE_SLASH_PATTERN.matcher(matchingPattern).replaceAll("/");
    if (matchingPattern.equals("/")) {
        return URI_ROOT;
    }
    matchingPattern = TRAILING_SLASH_PATTERN.matcher(matchingPattern).replaceAll("");
    return Tag.of("uri", matchingPattern);
}
 
Example 5
Source File: JerseyTags.java    From micrometer with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@code uri} tag based on the URI of the given {@code event}. Uses the
 * {@link ExtendedUriInfo#getMatchedTemplates()} if
 * available. {@code REDIRECTION} for 3xx responses, {@code NOT_FOUND} for 404 responses.
 * @param event the request event
 * @return the uri tag derived from the request event
 */
public static Tag uri(RequestEvent event) {
    ContainerResponse response = event.getContainerResponse();
    if (response != null) {
        int status = response.getStatus();
        if (isRedirection(status)) {
            return URI_REDIRECTION;
        }
        if (status == 404) {
            return URI_NOT_FOUND;
        }
    }
    String matchingPattern = getMatchingPattern(event);
    if (matchingPattern.equals("/")) {
        return URI_ROOT;
    }
    return Tag.of("uri", matchingPattern);
}
 
Example 6
Source File: WebMvcTags.java    From foremast with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@code uri} tag based on the URI of the given {@code request}. Uses the
 * {@link HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE} best matching pattern if
 * available. Falling back to {@code REDIRECTION} for 3xx responses, {@code NOT_FOUND}
 * for 404 responses, {@code root} for requests with no path info, and {@code UNKNOWN}
 * for all other requests.
 *
 * @param request the request
 * @param response the response
 * @return the uri tag derived from the request
 */
public static Tag uri(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response) {
    if (request != null) {
        String pattern = getMatchingPattern(request);
        if (pattern != null) {
            return Tag.of("uri", pattern);
        } else if (response != null) {
            HttpStatus status = extractStatus(response);
            if (status != null && status.is3xxRedirection()) {
                return URI_REDIRECTION;
            }
            if (status != null && status.equals(HttpStatus.NOT_FOUND)) {
                return URI_NOT_FOUND;
            }
        }
        String pathInfo = getPathInfo(request);
        if (pathInfo.isEmpty()) {
            return URI_ROOT;
        }
    }
    return URI_UNKNOWN;
}
 
Example 7
Source File: RntbdServiceEndpoint.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
private RntbdServiceEndpoint(
    final Provider provider, final Config config, final NioEventLoopGroup group, final RntbdRequestTimer timer,
    final URI physicalAddress
) {

    final Bootstrap bootstrap = new Bootstrap()
        .channel(NioSocketChannel.class)
        .group(group)
        .option(ChannelOption.ALLOCATOR, config.allocator())
        .option(ChannelOption.AUTO_READ, true)
        .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.connectionTimeoutInMillis())
        .option(ChannelOption.RCVBUF_ALLOCATOR, receiveBufferAllocator)
        .option(ChannelOption.SO_KEEPALIVE, true)
        .remoteAddress(physicalAddress.getHost(), physicalAddress.getPort());

    this.channelPool = new RntbdClientChannelPool(this, bootstrap, config);
    this.remoteAddress = bootstrap.config().remoteAddress();
    this.concurrentRequests = new AtomicInteger();
    this.lastRequestTime = new AtomicLong();
    this.closed = new AtomicBoolean();
    this.requestTimer = timer;

    this.tag = Tag.of(TAG_NAME, RntbdMetrics.escape(this.remoteAddress.toString()));
    this.id = instanceCount.incrementAndGet();
    this.provider = provider;

    this.metrics = new RntbdMetrics(provider.transportClient, this);
}
 
Example 8
Source File: MossMetricsEndpoint.java    From Moss with Apache License 2.0 5 votes vote down vote up
private Tag parseTag(String tag) {
    String[] parts = tag.split(":", 2);
    if (parts.length != 2) {
        throw new InvalidEndpointRequestException(
                "Each tag parameter must be in the form 'key:value' but was: " + tag,
                "Each tag parameter must be in the form 'key:value'");
    }
    return Tag.of(parts[0], parts[1]);
}
 
Example 9
Source File: CallerWebMvcTagsProvider.java    From foremast with Apache License 2.0 5 votes vote down vote up
public Tag caller(HttpServletRequest request) {
    if (request != null) {
        String header = request.getHeader(headerName);
        return header != null ? Tag.of("caller", header.trim()) : CALLER_UNKNOWN;
    }
    return CALLER_UNKNOWN;
}
 
Example 10
Source File: JerseyTags.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@code status} tag based on the status of the given {@code response}.
 * @param response the container response
 * @return the status tag derived from the status of the response
 */
public static Tag status(ContainerResponse response) {
    /* In case there is no response we are dealing with an unmapped exception. */
    return (response != null)
            ? Tag.of("status", Integer.toString(response.getStatus()))
            : STATUS_SERVER_ERROR;
}
 
Example 11
Source File: WeighBridgeMetricsTest.java    From data-highway with Apache License 2.0 4 votes vote down vote up
static Matcher<Tag> tag(String key, String value) {
  return new TagMatcher(Tag.of(key, value));
}
 
Example 12
Source File: KafkaOffsetMetricsTest.java    From data-highway with Apache License 2.0 4 votes vote down vote up
static Matcher<Tag> tag(String key, String value) {
  return new TagMatcher(Tag.of(key, value));
}
 
Example 13
Source File: WeighBridgeMetrics.java    From data-highway with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public void update(Broker broker) {
  List<Row> diskFreeRows = new ArrayList<>();
  List<Row> diskTotalRows = new ArrayList<>();
  List<Row> diskUsedRows = new ArrayList<>();
  List<Row> sizeOnDiskRows = new ArrayList<>();
  List<Row> logSizeRows = new ArrayList<>();
  List<Row> beginningOffsetRows = new ArrayList<>();
  List<Row> endOffsetRows = new ArrayList<>();
  List<Row> recordCountRows = new ArrayList<>();

  Tag brokerTag = Tag.of("broker", String.valueOf(broker.getId()));
  Tag rackTag = Tag.of("rack", broker.getRack());

  for (LogDir logDir : broker.getLogDirs()) {
    Tag logDirTag = Tag.of("logdir", logDir.getPath());

    Tags logDirTags = Tags.of(brokerTag, rackTag, logDirTag);
    diskFreeRows.add(Row.of(logDirTags, logDir.getDiskFree()));
    diskTotalRows.add(Row.of(logDirTags, logDir.getDiskTotal()));
    diskUsedRows.add(Row.of(logDirTags, logDir.getDiskTotal() - logDir.getDiskFree()));

    for (Topic topic : logDir.getTopics()) {
      Tag topicTag = Tag.of("topic", topic.getName());

      for (PartitionReplica replica : topic.getPartitionReplicas()) {
        Tag partitionTag = Tag.of("partition", String.valueOf(replica.getPartition()));
        Tag leaderTag = Tag.of("leader", String.valueOf(replica.isLeader()));
        Tag inSyncTag = Tag.of("inSync", String.valueOf(replica.isInSync()));

        Tags replicaTags = Tags.of(brokerTag, rackTag, logDirTag, topicTag, partitionTag, leaderTag, inSyncTag);
        sizeOnDiskRows.add(Row.of(replicaTags, replica.getSizeOnDisk()));
        logSizeRows.add(Row.of(replicaTags, replica.getLogSize()));
        beginningOffsetRows.add(Row.of(replicaTags, replica.getBeginningOffset()));
        endOffsetRows.add(Row.of(replicaTags, replica.getEndOffset()));
        recordCountRows.add(Row.of(replicaTags, replica.getRecordCount()));
      }
    }
  }

  diskFree.register(diskFreeRows, true);
  diskTotal.register(diskTotalRows, true);
  diskUsed.register(diskUsedRows, true);
  sizeOnDisk.register(sizeOnDiskRows, true);
  logSize.register(logSizeRows, true);
  beginningOffset.register(beginningOffsetRows, true);
  endOffset.register(endOffsetRows, true);
  recordCount.register(recordCountRows, true);
}
 
Example 14
Source File: WebMvcTags.java    From foremast with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@code method} tag based on the {@link HttpServletRequest#getMethod()
 * method} of the given {@code request}.
 *
 * @param request the request
 * @return the method tag whose value is a capitalized method (e.g. GET).
 */
public static Tag method(@Nullable HttpServletRequest request) {
    return request == null ? METHOD_UNKNOWN : Tag.of("method", request.getMethod());
}
 
Example 15
Source File: JerseyTags.java    From micrometer with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@code method} tag based on the {@link ContainerRequest#getMethod()
 * method} of the given {@code request}.
 * @param request the container request
 * @return the method tag whose value is a capitalized method (e.g. GET).
 */
public static Tag method(ContainerRequest request) {
    return (request != null) ? Tag.of("method", request.getMethod()) : METHOD_UNKNOWN;
}
 
Example 16
Source File: WebMvcTags.java    From foremast with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@code method} tag based on the status of the given {@code response}.
 *
 * @param response the HTTP response
 * @return the status tag derived from the status of the response
 */
public static Tag status(@Nullable HttpServletResponse response) {
    return response == null || !(response instanceof MetricsServletResponse) ? STATUS_UNKNOWN : Tag.of("status",
            Integer.toString(((MetricsServletResponse)response).getStatus()));
}
 
Example 17
Source File: JettyClientTags.java    From micrometer with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@code method} tag based on the {@link Request#getMethod()
 * method} of the given {@code request}.
 *
 * @param request the request
 * @return the method tag whose value is a capitalized method (e.g. GET).
 */
public static Tag method(Request request) {
    return (request != null) ? Tag.of("method", request.getMethod()) : METHOD_UNKNOWN;
}
 
Example 18
Source File: HttpRequestTags.java    From micrometer with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@code status} tag based on the status of the given {@code response}.
 * @param response the HTTP response
 * @return the status tag derived from the status of the response
 */
public static Tag status(HttpServletResponse response) {
    return (response != null) ? Tag.of("status", Integer.toString(response.getStatus())) : STATUS_UNKNOWN;
}
 
Example 19
Source File: JettyClientTags.java    From micrometer with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@code status} tag based on the status of the given {@code result}.
 *
 * @param result the request result
 * @return the status tag derived from the status of the response
 */
public static Tag status(Result result) {
    return Tag.of("status", Integer.toString(result.getResponse().getStatus()));
}
 
Example 20
Source File: HttpRequestTags.java    From micrometer with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@code method} tag based on the {@link HttpServletRequest#getMethod()
 * method} of the given {@code request}.
 * @param request the request
 * @return the method tag whose value is a capitalized method (e.g. GET).
 */
public static Tag method(HttpServletRequest request) {
    return (request != null) ? Tag.of("method", request.getMethod()) : METHOD_UNKNOWN;
}