Ejemplo n.º 1
0
        protected override async Task <Option <IEnumerable <ModuleLogsResponse> > > HandleRequestInternal(Option <ModuleLogsRequest> payloadOption, CancellationToken cancellationToken)
        {
            ModuleLogsRequest payload = payloadOption.Expect(() => new ArgumentException("Request payload not found"));

            if (ExpectedSchemaVersion.CompareMajorVersion(payload.SchemaVersion, "logs upload request schema") != 0)
            {
                Events.MismatchedMinorVersions(payload.SchemaVersion, ExpectedSchemaVersion);
            }

            Events.ProcessingRequest(payload);

            ILogsRequestToOptionsMapper requestToOptionsMapper = new LogsRequestToOptionsMapper(
                this.runtimeInfoProvider,
                payload.Encoding,
                payload.ContentType,
                LogOutputFraming.None,
                Option.None <LogsOutputGroupingConfig>(),
                false);

            IList <(string id, ModuleLogOptions logOptions)> logOptionsList = await requestToOptionsMapper.MapToLogOptions(payload.Items, cancellationToken);

            int messageSize = 0;
            IEnumerable <Task <ModuleLogsResponse> > uploadLogsTasks = logOptionsList.Select(
                async l =>
            {
                byte[] moduleLogs = await this.logsProvider.GetLogs(l.id, l.logOptions, cancellationToken);

                Events.ReceivedModuleLogs(moduleLogs, l.id);

                if (l.logOptions.ContentEncoding == LogsContentEncoding.Gzip)
                {
                    Interlocked.Add(ref messageSize, moduleLogs.Length);
                    return(new ModuleLogsResponse(l.id, moduleLogs));
                }
                else
                {
                    string encodedLogs = moduleLogs.FromBytes();
                    Interlocked.Add(ref messageSize, encodedLogs.Length);

                    return(new ModuleLogsResponse(l.id, encodedLogs));
                }
            });

            IEnumerable <ModuleLogsResponse> response = await Task.WhenAll(uploadLogsTasks);

            if (messageSize > MaxPayloadSize)
            {
                string message = Events.LargePayload(messageSize, logOptionsList.Select(o => o.logOptions));
                throw new ArgumentException(message);
            }

            return(Option.Some(response));
        }
        protected override async Task <Option <IEnumerable <ModuleLogsResponse> > > HandleRequestInternal(Option <ModuleLogsRequest> payloadOption, CancellationToken cancellationToken)
        {
            ModuleLogsRequest payload = payloadOption.Expect(() => new ArgumentException("Request payload not found"));

            if (ExpectedSchemaVersion.CompareMajorVersion(payload.SchemaVersion, "logs upload request schema") != 0)
            {
                Events.MismatchedMinorVersions(payload.SchemaVersion, ExpectedSchemaVersion);
            }

            Events.ProcessingRequest(payload);

            ILogsRequestToOptionsMapper requestToOptionsMapper = new LogsRequestToOptionsMapper(
                this.runtimeInfoProvider,
                payload.Encoding,
                payload.ContentType,
                LogOutputFraming.None,
                Option.None <LogsOutputGroupingConfig>(),
                false);

            IList <(string id, ModuleLogOptions logOptions)> logOptionsList = await requestToOptionsMapper.MapToLogOptions(payload.Items, cancellationToken);

            IEnumerable <Task <ModuleLogsResponse> > uploadLogsTasks = logOptionsList.Select(
                async l =>
            {
                Events.ReceivedLogOptions(l);
                ModuleLogOptions logOptions = l.logOptions.Filter.Tail
                                              .Filter(t => t < MaxTailValue)
                                              .Map(t => l.logOptions)
                                              .GetOrElse(
                    () =>
                {
                    var filter = new ModuleLogFilter(Option.Some(MaxTailValue), l.logOptions.Filter.Since, l.logOptions.Filter.Until, l.logOptions.Filter.LogLevel, l.logOptions.Filter.RegexString);
                    return(new ModuleLogOptions(l.logOptions.ContentEncoding, l.logOptions.ContentType, filter, l.logOptions.OutputFraming, l.logOptions.OutputGroupingConfig, l.logOptions.Follow));
                });

                byte[] moduleLogs = await this.logsProvider.GetLogs(l.id, logOptions, cancellationToken);

                Events.ReceivedModuleLogs(moduleLogs, l.id);
                return(logOptions.ContentEncoding == LogsContentEncoding.Gzip
                        ? new ModuleLogsResponse(l.id, moduleLogs)
                        : new ModuleLogsResponse(l.id, moduleLogs.FromBytes()));
            });
            IEnumerable <ModuleLogsResponse> response = await Task.WhenAll(uploadLogsTasks);

            return(Option.Some(response));
        }
Ejemplo n.º 3
0
 public static void ProcessingRequest(ModuleLogsRequest payload)
 {
     Log.LogInformation((int)EventIds.ProcessingRequest, $"Processing request to get logs for {payload.ToJson()}");
 }