Beispiel #1
0
  private void doGetLogs(
      HttpResponder responder,
      LoggingContext loggingContext,
      long fromTimeSecsParam,
      long toTimeSecsParam,
      boolean escape,
      String filterStr,
      @Nullable RunRecord runRecord) {
    try {
      TimeRange timeRange = parseTime(fromTimeSecsParam, toTimeSecsParam, responder);
      if (timeRange == null) {
        return;
      }

      Filter filter = FilterParser.parse(filterStr);

      ReadRange readRange =
          new ReadRange(
              timeRange.getFromMillis(), timeRange.getToMillis(), LogOffset.INVALID_KAFKA_OFFSET);
      readRange = adjustReadRange(readRange, runRecord);

      ChunkedLogReaderCallback logCallback =
          new ChunkedLogReaderCallback(responder, logPattern, escape);
      logReader.getLog(
          loggingContext, readRange.getFromMillis(), readRange.getToMillis(), filter, logCallback);
      logCallback.close();
    } catch (SecurityException e) {
      responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
    } catch (IllegalArgumentException e) {
      responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (Throwable e) {
      LOG.error("Caught exception", e);
      responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
  }
Beispiel #2
0
  @GET
  @Path("/system/{component-id}/{service-id}/logs/prev")
  public void sysPrev(
      HttpRequest request,
      HttpResponder responder,
      @PathParam("component-id") String componentId,
      @PathParam("service-id") String serviceId,
      @QueryParam("max") @DefaultValue("50") int maxEvents,
      @QueryParam("fromOffset") @DefaultValue("") String fromOffsetStr,
      @QueryParam("escape") @DefaultValue("true") boolean escape,
      @QueryParam("filter") @DefaultValue("") String filterStr) {
    try {
      Filter filter = FilterParser.parse(filterStr);

      LoggingContext loggingContext =
          LoggingContextHelper.getLoggingContext(
              Constants.SYSTEM_NAMESPACE, componentId, serviceId);
      LogReaderCallback logCallback = new LogReaderCallback(responder, logPattern, escape);
      LogOffset logOffset = FormattedLogEvent.parseLogOffset(fromOffsetStr);
      ReadRange readRange = ReadRange.createToRange(logOffset);
      logReader.getLogPrev(loggingContext, readRange, maxEvents, filter, logCallback);
      logCallback.close();
    } catch (IllegalArgumentException e) {
      responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (Throwable e) {
      LOG.error("Caught exception", e);
      responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
  }
Beispiel #3
0
  private void doPrev(
      HttpResponder responder,
      LoggingContext loggingContext,
      int maxEvents,
      String fromOffsetStr,
      boolean escape,
      String filterStr,
      @Nullable RunRecord runRecord) {
    try {
      Filter filter = FilterParser.parse(filterStr);

      LogReaderCallback logCallback = new LogReaderCallback(responder, logPattern, escape);
      LogOffset logOffset = FormattedLogEvent.parseLogOffset(fromOffsetStr);
      ReadRange readRange = ReadRange.createToRange(logOffset);
      readRange = adjustReadRange(readRange, runRecord);
      logReader.getLogPrev(loggingContext, readRange, maxEvents, filter, logCallback);
      logCallback.close();
    } catch (SecurityException e) {
      responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
    } catch (IllegalArgumentException e) {
      responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (Throwable e) {
      LOG.error("Caught exception", e);
      responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
  }
Beispiel #4
0
  /**
   * If readRange is outside runRecord's range, then the readRange is adjusted to fall within
   * runRecords range.
   */
  private ReadRange adjustReadRange(ReadRange readRange, @Nullable RunRecord runRecord) {
    if (runRecord == null) {
      return readRange;
    }

    long fromTimeMillis = readRange.getFromMillis();
    long toTimeMillis = readRange.getToMillis();

    long runStartMillis = TimeUnit.SECONDS.toMillis(runRecord.getStartTs());
    if (fromTimeMillis < runStartMillis) {
      fromTimeMillis = runStartMillis;
    }
    if (runRecord.getStopTs() != null) {
      long runStopMillis = TimeUnit.SECONDS.toMillis(runRecord.getStopTs());
      if (toTimeMillis > runStopMillis) {
        toTimeMillis = runStopMillis;
      }
    }
    return new ReadRange(fromTimeMillis, toTimeMillis, readRange.getKafkaOffset());
  }