Example #1
0
  @Override
  public AsyncFuture<Void> run(final ShellIO io, final TaskParameters base) throws Exception {
    final Parameters params = (Parameters) base;

    final String queryString = params.query.stream().collect(Collectors.joining(" "));

    final ObjectMapper indent = mapper.copy();
    indent.configure(SerializationFeature.INDENT_OUTPUT, true);

    final QueryOptions.Builder optionsBuilder = QueryOptions.builder().tracing(params.tracing);

    params.dataLimit.ifPresent(optionsBuilder::dataLimit);
    params.groupLimit.ifPresent(optionsBuilder::groupLimit);
    params.seriesLimit.ifPresent(optionsBuilder::seriesLimit);

    final QueryOptions options = optionsBuilder.build();

    final Optional<QueryDateRange> range =
        Optional.of(new QueryDateRange.Relative(TimeUnit.DAYS, 1));

    return query
        .useGroup(params.group)
        .query(
            query
                .newQueryFromString(queryString)
                .options(Optional.of(options))
                .rangeIfAbsent(range)
                .build())
        .directTransform(
            result -> {
              for (final RequestError e : result.getErrors()) {
                io.out().println(String.format("ERR: %s", e.toString()));
              }

              io.out().println(String.format("LIMITS: %s", result.getLimits().getLimits()));

              for (final ShardedResultGroup resultGroup : result.getGroups()) {
                final MetricCollection group = resultGroup.getMetrics();

                io.out()
                    .println(
                        String.format(
                            "%s: %s %s",
                            group.getType(),
                            resultGroup.getShard(),
                            indent.writeValueAsString(resultGroup.getSeries())));
                io.out().println(indent.writeValueAsString(group.getData()));
                io.out().flush();
              }

              io.out().println("TRACE:");
              result.getTrace().formatTrace(io.out());
              io.out().flush();

              return null;
            });
  }
Example #2
0
  @Override
  public AsyncFuture<Void> run(final ShellIO io, TaskParameters base) throws Exception {
    final Parameters params = (Parameters) base;

    final BackendKey backendKey =
        mapper.readValue(params.key, BackendKeyArgument.class).toBackendKey();

    return metrics
        .useGroup(params.group)
        .serializeKeyToHex(backendKey)
        .directTransform(
            result -> {
              int i = 0;

              for (final String key : result) {
                io.out().println(String.format("%d: %s", i++, key));
              }

              return null;
            });
  }