async getStats(request) {
    if (!this.enabled) {
      throw errorStats.get("not_available");
    }

    const response = {
      hits: [],
      total: null,
    };
    const currentDate = new Date().getTime();
    let startTime;
    let stopTime;

    if (request && request.input.args && request.input.args.startTime) {
      startTime = isNaN(request.input.args.startTime)
        ? new Date(request.input.args.startTime).getTime()
        : request.input.args.startTime;
    }

    if (request && request.input.args && request.input.args.stopTime) {
      stopTime = isNaN(request.input.args.stopTime)
        ? new Date(request.input.args.stopTime).getTime()
        : request.input.args.stopTime;
    }

    if (startTime !== undefined && isNaN(startTime)) {
      throw errorApiAssert.get("invalid_argument", "startTime", "number");
    }

    if (stopTime !== undefined && isNaN(stopTime)) {
      throw errorApiAssert.get("invalid_argument", "stopTime", "number");
    }

    if (startTime !== undefined && startTime >= currentDate) {
      response.total = response.hits.length;
      return response;
    }

    const stats = {
      completedRequests: Object.fromEntries(
        this.currentStats.completedRequests,
      ),
      connections: Object.fromEntries(this.currentStats.connections),
      failedRequests: Object.fromEntries(this.currentStats.failedRequests),
      ongoingRequests: Object.fromEntries(this.currentStats.ongoingRequests),
    };

    if (!this.lastFrame) {
      if (!stopTime || stopTime >= currentDate) {
        response.hits.push(
          Object.assign({ timestamp: new Date(currentDate).getTime() }, stats),
        );
      }

      response.total = response.hits.length;

      return response;
    }

    const frames = await global.kuzzle.ask(
      "core:cache:internal:searchKeys",
      `${this.cacheKeyPrefix}*`,
    );

    // Statistics keys are timestamp.
    // Ordering them guarantees stats frames to be returned in the right order
    const values = await global.kuzzle.ask(
      "core:cache:internal:mget",
      frames.sort(),
    );

    values.forEach((v, idx) => {
      const regex = new RegExp(`^${this.cacheKeyPrefix}`);
      const frameDate = new Date(Number(frames[idx].replace(regex, "")));
      const frameDateTime = frameDate.getTime();

      if (
        (!startTime || startTime <= frameDateTime) &&
        (!stopTime || stopTime >= frameDateTime)
      ) {
        response.hits.push(
          Object.assign(JSON.parse(v), {
            timestamp: new Date(frameDateTime).getTime(),
          }),
        );
      }
    });

    response.total = response.hits.length;

    return response;
  }
Gets the last saved statistics frame from a date

@param {Request} request
@returns {Promise<Object>}