Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report errors from build telemetry #4054

Merged
merged 2 commits into from
Sep 12, 2024

Conversation

pepone
Copy link
Member

@pepone pepone commented Sep 11, 2024

This PR updates the telemetry reporter to report errors, that are then treated as warning and allow the build to continue:

For example, with a disconnected network:

C:\Users\jose\source\repos\icerpc-csharp\examples\slice\Greeter\Server>dotnet build
Restore complete (0.3s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  Server succeeded with 1 warning(s) (1.4s) → bin\Any CPU\Debug\net8.0\Server.dll
    C:\Users\jose\.nuget\packages\icerpc.slice.tools\0.4.0-preview1\build\IceRpc.Slice.Tools.targets(76,5): warning MSB3073: The command "dotnet IceRpc.BuildTelemetry.Reporter.dll --idl slice --hash=0e7817f6cb2092323a7ee81a42bd5301177621e819f3178a04c4522cd8fae240 --contains-slice1=False --contains-slice2=True --src-file-count=1 --ref-file-count=11" exited with code -532462766.

Build succeeded with 1 warning(s) in 2.1s

or with detailed logging enabled /v:d

C:\Users\jose\source\repos\icerpc-csharp\examples\slice\Greeter\Server>dotnet build /v:d
Restore complete (0.3s)
    Determining projects to restore...
    All projects are up-to-date for restore.
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  Server succeeded with 1 warning(s) (1.4s) → bin\Any CPU\Debug\net8.0\Server.dll
    Unhandled exception. IceRpc.IceRpcException: An IceRpc call failed with error 'IceRpcError'.
     ---> System.Net.Sockets.SocketException (11001): No such host is known.
       at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
       at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
       at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
       at IceRpc.Transports.Tcp.Internal.TcpClientConnection.ConnectAsyncCore(CancellationToken cancellationToken) in C:\Users\jose\source\repos\icerpc-csharp\src\IceRpc\Transports\Tcp\Internal\TcpConnection.cs:line 332
       --- End of inner exception stack trace ---
       at IceRpc.Transports.Tcp.Internal.TcpClientConnection.ConnectAsyncCore(CancellationToken cancellationToken) in C:\Users\jose\source\repos\icerpc-csharp\src\IceRpc\Transports\Tcp\Internal\TcpConnection.cs:line 358
       at IceRpc.Transports.Slic.Internal.SlicConnection.<>c__DisplayClass56_0.<<ConnectAsync>g__PerformConnectAsync|0>d.MoveNext() in C:\Users\jose\source\repos\icerpc-csharp\src\IceRpc\Transports\Slic\Internal\SlicConnection.cs:line 149
    --- End of stack trace from previous location ---
       at IceRpc.Transports.Slic.Internal.SlicConnection.<DisposeAsync>g__PerformDisposeAsync|59_0() in C:\Users\jose\source\repos\icerpc-csharp\src\IceRpc\Transports\Slic\Internal\SlicConnection.cs:line 478
       at Program.<Main>$(String[] args) in C:\Users\jose\source\repos\icerpc-csharp\tools\IceRpc.BuildTelemetry.Reporter\Program.cs:line 93
       at Program.<Main>(String[] args)
    C:\Users\jose\.nuget\packages\icerpc.slice.tools\0.4.0-preview1\build\IceRpc.Slice.Tools.targets(76,5): warning MSB3073: The command "dotnet IceRpc.BuildTelemetry.Reporter.dll --idl slice --hash=0e7817f6cb2092323a7ee81a42bd5301177621e819f3178a04c4522cd8fae240 --contains-slice1=False --contains-slice2=True --src-file-count=1 --ref-file-count=11" exited with code -532462766.

Build succeeded with 1 warning(s) in 2.2s

@pepone pepone force-pushed the buildtelemetry-simplifications branch from 3308d8c to dbb7f12 Compare September 11, 2024 16:01
// Shutdown the connection.
await connection.ShutdownAsync(cts.Token);
}
catch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just removed this catch block that was ignoring all exceptions

@@ -75,13 +75,11 @@
</OutputHashTask>

<!-- Run build telemetry -->
<BuildTelemetryTask
<Exec
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the standard Exec task to call the reporter, no need for a custom task.

Condition="'$(IceRpcBuildTelemetry)' != 'false'"
ContinueOnError="true"
/>
ContinueOnError="true" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we can use IgnoreExitCode parameter from Exec task. The difference is that errors would be reported as regular messages instead of warnings.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that IgnoreExitCode would be preferable.

Maybe our collective sentiment has changed, but I think that a telemetry failure should have no impact on whether your build succeeds or not; and emitting warnings would still cause a failure if warnings are being treated as errors (something that seems to be at least slightly common).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably ContinueOnError=true means we keep going on error.

Keeping in mind this process (slice compilation) is under our control here.

Copy link
Member

@InsertCreativityHere InsertCreativityHere Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstood, but #4049 made it sound like ContinueOnError was insufficient.
Even though, "keep going on error" is definitely the impression you get from it's name.
(maybe only if you treat warnings as errors? But, to be fair, that is something that many developers do.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstood, but #4049 made it sound like ContinueOnError was insufficient.

That was my impression too when I created the bug. But it is not correct. When you set ContinueOnError warnings doesn't make the build fail even if you set treat warnings as errors.

Copy link
Member

@externl externl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Copy link
Member

@InsertCreativityHere InsertCreativityHere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much simpler!

tools/IceRpc.Slice.Tools/IceRpc.Slice.Tools.targets Outdated Show resolved Hide resolved
WorkingDirectory="$(IceRpcBuildTelemetryScriptPath)"
CompilationHash="$(Hash)"
SourceFileCount="$(FileCount)"
Command="dotnet IceRpc.BuildTelemetry.Reporter.dll --idl protobuf --hash=$(Hash) --src-file-count=$(FileCount)"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with no equals after the idl switch.

Condition="'$(IceRpcBuildTelemetry)' != 'false'"
ContinueOnError="true"
/>
ContinueOnError="true" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that IgnoreExitCode would be preferable.

Maybe our collective sentiment has changed, but I think that a telemetry failure should have no impact on whether your build succeeds or not; and emitting warnings would still cause a failure if warnings are being treated as errors (something that seems to be at least slightly common).

try
// Create a cancellation token source to cancel the telemetry upload if it
// takes too long.
using var cts = new CancellationTokenSource(timeout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this code oddly written. We use timeout only here, no need for var timeout.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I just removed the try/catch would rewrite this in a follow up PR where we split the program in protobuf/slice versions.

using var cts = new CancellationTokenSource(timeout);

// Create a client connection
var clientAuthenticationOptions = new SslClientAuthenticationOptions();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this extra variable.

var reporter = new ReporterProxy(connection);

// Parse the IDL
string? idl = args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the expression below, doesn't sound like in can be null.

.Skip(1)
.FirstOrDefault(), out int referenceFileCountResult) ? referenceFileCountResult : 0;

BuildTelemetry buildTelemetry = idl.ToLower() switch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given how trivial this program is, I would prefer to have separate versions for IceRpc.Protobuf.Tools and IceRpc.Slice.Tools. For a follow-up PR.

Then no need for an "idl" argument to the program.

Also note that most (maybe all) arguments are IDL-specific. --contains-slice1/--contains-slice2/--ref-file-count is Slice-only, which is not clear with the current setup.

@@ -2,98 +2,92 @@

using IceRpc;
using IceRpc.BuildTelemetry;
using Microsoft.Extensions.Logging;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we use Logging?

@pepone pepone merged commit 70b0be5 into icerpc:main Sep 12, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants