@Override
  public void onComplete(final Request request) {

    final RequestInfo requestInfo = getRequestInfo(request);

    final List<Tag> tags = new ArrayList<>(5);
    tags.add(Tag.of(PATH_TAG, requestInfo.path()));
    tags.add(Tag.of(METHOD_TAG, requestInfo.method()));
    tags.add(Tag.of(STATUS_CODE_TAG, String.valueOf(requestInfo.statusCode())));
    tags.add(Tag.of(TRAFFIC_SOURCE_TAG, TrafficSource.HTTP.name().toLowerCase()));

    final Tag platformTag = UserAgentTagUtil.getPlatformTag(requestInfo.userAgent());
    tags.add(platformTag);

    meterRegistry.counter(REQUEST_COUNTER_NAME, tags).increment();

    UserAgentTagUtil.getClientVersionTag(requestInfo.userAgent(), clientReleaseManager).ifPresent(
        clientVersionTag -> meterRegistry.counter(REQUESTS_BY_VERSION_COUNTER_NAME,
            Tags.of(clientVersionTag, platformTag)).increment());
  }
@Test
  @SuppressWarnings("unchecked")
  void testRequests() {
    final String path = "/test";
    final String method = "GET";
    final int statusCode = 200;

    final HttpURI httpUri = mock(HttpURI.class);
    when(httpUri.getPath()).thenReturn(path);

    final Request request = mock(Request.class);
    when(request.getMethod()).thenReturn(method);
    when(request.getHeader(HttpHeaders.USER_AGENT)).thenReturn("Signal-Android/4.53.7 (Android 8.1)");
    when(request.getHttpURI()).thenReturn(httpUri);

    final Response response = mock(Response.class);
    when(response.getStatus()).thenReturn(statusCode);
    when(request.getResponse()).thenReturn(response);
    final ExtendedUriInfo extendedUriInfo = mock(ExtendedUriInfo.class);
    when(request.getAttribute(MetricsHttpChannelListener.URI_INFO_PROPERTY_NAME)).thenReturn(extendedUriInfo);
    when(extendedUriInfo.getMatchedTemplates()).thenReturn(List.of(new UriTemplate(path)));

    final ArgumentCaptor<Iterable<Tag>> tagCaptor = ArgumentCaptor.forClass(Iterable.class);

    listener.onComplete(request);

    verify(requestCounter).increment();

    verify(meterRegistry).counter(eq(MetricsHttpChannelListener.REQUEST_COUNTER_NAME), tagCaptor.capture());

    final Set<Tag> tags = new HashSet<>();
    for (final Tag tag : tagCaptor.getValue()) {
      tags.add(tag);
    }

    assertEquals(5, tags.size());
    assertTrue(tags.contains(Tag.of(MetricsHttpChannelListener.PATH_TAG, path)));
    assertTrue(tags.contains(Tag.of(MetricsHttpChannelListener.METHOD_TAG, method)));
    assertTrue(tags.contains(Tag.of(MetricsHttpChannelListener.STATUS_CODE_TAG, String.valueOf(statusCode))));
    assertTrue(
        tags.contains(Tag.of(MetricsHttpChannelListener.TRAFFIC_SOURCE_TAG, TrafficSource.HTTP.name().toLowerCase())));
    assertTrue(tags.contains(Tag.of(UserAgentTagUtil.PLATFORM_TAG, "android")));
  }