Пример #1
0
        public void Convert_StackdriverBreakpointWithError()
        {
            var breakpoint = new Breakpoint
            {
                Id       = _id,
                Location = new SourceLocation
                {
                    Path = _path,
                    Line = _line
                },
                CreateTime = Timestamp.FromDateTime(DateTime.UtcNow),
                FinalTime  = Timestamp.FromDateTime(DateTime.UtcNow.AddSeconds(10)),
                Status     = new Status
                {
                    Message = "This is an error",
                    Iserror = true
                }
            };

            StackdriverBreakpoint sdBreakpoint = breakpoint.Convert();

            Assert.Equal(_id, sdBreakpoint.Id);
            Assert.Equal(_path.Replace('\\', '/'), sdBreakpoint.Location.Path);
            Assert.Equal(_line, sdBreakpoint.Location.Line);
            Assert.Equal(breakpoint.CreateTime, sdBreakpoint.CreateTime);
            Assert.Equal(breakpoint.FinalTime, sdBreakpoint.FinalTime);
            Assert.Equal(breakpoint.Status.Message, sdBreakpoint.Status.Description.Format);
            Assert.Equal(breakpoint.Status.Iserror, sdBreakpoint.Status.IsError);
        }
Пример #2
0
        public void Convert_Breakpoint()
        {
            var sdBreakpoint = new StackdriverBreakpoint
            {
                Id       = _id,
                Location = new StackdriverSourceLocation
                {
                    Path = _path,
                    Line = _line
                },
                CreateTime       = Timestamp.FromDateTime(DateTime.UtcNow),
                Condition        = _condition,
                Expressions      = { _expressions },
                LogMessageFormat = "Message format",
                LogLevel         = StackdriverBreakpoint.Types.LogLevel.Error
            };

            var breakpoint = sdBreakpoint.Convert();

            Assert.Equal(_id, breakpoint.Id);
            Assert.Equal(_path, breakpoint.Location.Path);
            Assert.Equal(_line, breakpoint.Location.Line);
            Assert.True(breakpoint.Activated);
            Assert.Null(breakpoint.CreateTime);
            Assert.Equal(_condition, breakpoint.Condition);
            Assert.Equal(_expressions, breakpoint.Expressions);
            Assert.Equal(breakpoint.LogMessageFormat, sdBreakpoint.LogMessageFormat);
            Assert.Equal(Breakpoint.Types.LogLevel.Err, breakpoint.LogLevel);
        }
Пример #3
0
        /// <summary>
        /// Substitutes the log message format in breakpoint and writes
        /// the result as a log entry to the log _logName.
        /// </summary>
        /// <returns>WriteLogEntriesResponse from the API.</returns>
        public WriteLogEntriesResponse WriteLogEntry(StackdriverBreakpoint breakpoint)
        {
            LogEntry logEntry = new LogEntry
            {
                LogName  = _logName.ToString(),
                Severity = _logSeverityConversion[breakpoint.LogLevel],
            };

            if (breakpoint.Status?.IsError ?? false)
            {
                // The .NET Debugger does not use parameters field so we can just use format directly.
                logEntry.TextPayload = $"{LogpointMessageStart}Error evaluating logpoint \"{breakpoint.LogMessageFormat}\": {breakpoint.Status?.Description?.Format}.";
            }
            else
            {
                logEntry.TextPayload = SubstituteLogMessageFormat(
                    breakpoint.LogMessageFormat,
                    breakpoint.EvaluatedExpressions.ToList());
            }

            // TODO(quoct): Detect whether we are on gke and use gke_container.
            MonitoredResource resource = new MonitoredResource {
                Type = "global"
            };

            return(_logClient.WriteLogEntries(LogNameOneof.From(_logName), resource, null, new[] { logEntry }));
        }
Пример #4
0
        /// <summary>
        /// Blocks and reads a breakpoint from the <see cref="IBreakpointServer"/>
        /// and then sends the sends the breakpoint to the debugger API.
        /// </summary>
        internal override void MainAction()
        {
            Breakpoint readBreakpoint = _server.ReadBreakpointAsync().Result;

            if (readBreakpoint.KillServer)
            {
                _cts.Cancel();
                return;
            }
            StackdriverBreakpoint breakpoint = readBreakpoint.Convert();

            breakpoint.IsFinalState = true;
            _client.UpdateBreakpoint(breakpoint);
        }
Пример #5
0
 /// <summary>
 /// Converts a <see cref="StackdriverBreakpoint"/> to a <see cref="Breakpoint"/>.
 /// Converts ID and location and sets "Activated" to true.
 /// </summary>
 public static Breakpoint Convert(this StackdriverBreakpoint breakpoint)
 {
     GaxPreconditions.CheckNotNull(breakpoint, nameof(breakpoint));
     return(new Breakpoint
     {
         Id = breakpoint.Id,
         Activated = true,
         Location = new SourceLocation
         {
             Line = breakpoint.Location?.Line ?? 0,
             Path = breakpoint.Location?.Path,
         },
         Condition = breakpoint.Condition,
         Expressions = { breakpoint.Expressions }
     });
 }
 /// <summary>
 /// Converts a <see cref="StackdriverBreakpoint"/> to a <see cref="Breakpoint"/>.
 /// Converts ID and location and sets "Activated" to true.
 /// </summary>
 public static Breakpoint Convert(this StackdriverBreakpoint breakpoint)
 {
     GaxPreconditions.CheckNotNull(breakpoint, nameof(breakpoint));
     return(new Breakpoint
     {
         Id = breakpoint.Id,
         Activated = true,
         Location = new SourceLocation
         {
             Line = breakpoint.Location?.Line ?? 0,
             Path = breakpoint.Location?.Path,
         },
         Condition = breakpoint.Condition,
         Expressions = { breakpoint.Expressions },
         LogPoint = breakpoint.Action == StackdriverBreakpoint.Types.Action.Log,
         LogMessageFormat = breakpoint.LogMessageFormat,
         LogLevel = (Breakpoint.Types.LogLevel)breakpoint.LogLevel
     });
 }
        /// <summary>
        /// Blocks and reads a breakpoint from the <see cref="IBreakpointServer"/>
        /// and then sends the sends the breakpoint to the debugger API.
        /// </summary>
        internal override void MainAction()
        {
            Breakpoint readBreakpoint = _server.ReadBreakpointAsync().Result;

            if (readBreakpoint.KillServer)
            {
                _cts.Cancel();
                return;
            }
            StackdriverBreakpoint breakpoint = readBreakpoint.Convert();

            if (breakpoint.Action == StackdriverBreakpoint.Types.Action.Log)
            {
                _loggingClient.WriteLogEntry(breakpoint);
            }
            else
            {
                breakpoint.IsFinalState = true;
            }
            _debuggerClient.UpdateBreakpoint(breakpoint);
        }