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

Properties and items logged at evaluation with legacy loggers for single-process builds #7219

Open
KirillOsenkov opened this issue Jan 5, 2022 · 4 comments
Labels
Area: Debuggability Issues impacting the diagnosability of builds, including logging and clearer error messages. Area: Logging For consideration Used for items on the backlog to raise them to the top of that list for discussion triaged

Comments

@KirillOsenkov
Copy link
Member

We have an unexpected behavior for single-process builds (/bl), where if there are legacy loggers that haven't opted in via IEventSource4.IncludeEvaluationPropertiesAndItems(), and the environment variable MSBUILDLOGPROPERTIESANDITEMSAFTEREVALUATION is not set, we still enable the new behavior if there is at least one "enlightened" logger.

See test results here:
#7217 (comment)

See related:

@KirillOsenkov KirillOsenkov added needs-triage Have yet to determine what bucket this goes in. Area: Logging Area: Debuggability Issues impacting the diagnosability of builds, including logging and clearer error messages. labels Jan 5, 2022
@rainersigwald
Copy link
Member

Looked at this a bit this morning. Loggers work with an event-based approach, where one "SourceSink" of events can feed multiple loggers.

For a build with the default console logger, the binlog, and a random unenlightened logger, I see only one _eventSinkDictionary here:

var sinks = _eventSinkDictionary.Values.OfType<EventSourceSink>();
// .All() on an empty list defaults to true, we want to default to false
_includeEvaluationPropertiesAndItems = sinks.Any() && sinks.All(sink => sink.IncludeEvaluationPropertiesAndItems);

I can also see the ProjectCollection.ReusableLogger's internal state here

_includeEvaluationPropertiesAndItems = true;

getting toggled while registering the ParallelConsoleLogger.

The second logger gets registered through this path:

// We have already create a forwarding logger and have a single eventSink which
// a logger can listen to inorder to get all events in the system
EventSourceSink eventSource = (EventSourceSink)_eventSinkDictionary[_centralForwardingLoggerSinkId];
// Initialize and register the logger
InitializeLogger(logger, eventSource);

So it sees only the EventSourceSink created in the first logger, which had IncludeEvaluationPropertiesAndItems toggled on.

In the multiproc case, we actually pass only the non-console loggers to the ProjectCollection, because the console logger is a DistributedLoggerRecord which are treated separately

msbuild/src/MSBuild/XMake.cs

Lines 3202 to 3220 in b827bf5

// Check to see if there is a possibility we will be logging from an out-of-proc node.
// If so (we're multi-proc or the in-proc node is disabled), we register a distributed logger.
if (cpuCount == 1 && Environment.GetEnvironmentVariable("MSBUILDNOINPROCNODE") != "1")
{
// We've decided to use the MP logger even in single proc mode.
// Switch it on here, rather than in the logger, so that other hosts that use
// the existing ConsoleLogger don't see the behavior change in single proc.
logger.Parameters = $"ENABLEMPLOGGING;{consoleParameters}";
loggers.Add(logger);
}
else
{
logger.Parameters = consoleParameters;
// For performance, register this logger using the forwarding logger mechanism, rather than as an old-style
// central logger.
DistributedLoggerRecord forwardingLoggerRecord = CreateForwardingLoggerRecord(logger, consoleParameters, verbosity);
distributedLoggerRecords.Add(forwardingLoggerRecord);
}

msbuild/src/MSBuild/XMake.cs

Lines 1027 to 1030 in b827bf5

foreach (DistributedLoggerRecord distRecord in distributedLoggerRecords)
{
remoteLoggerRecords.Add(new ForwardingLoggerRecord(distRecord.CentralLogger, distRecord.ForwardingLoggerDescription));
}

and passed to the BuildParameters rather than the ProjectCollection

parameters.ForwardingLoggers = remoteLoggerRecords;

So I think the current filtering mechanism just doesn't work, and we've been squeaking by with luck :(

@rainersigwald rainersigwald added this to the VS 17.1 milestone Jan 5, 2022
@KirillOsenkov
Copy link
Member Author

Thanks for looking. When I added support for IncludePropertiesAndItems I copy pasted existing support for other settings, which probably have the same issue :|

@Forgind Forgind modified the milestones: VS 17.1, VS 17.2 Jan 6, 2022
@Forgind Forgind added For consideration Used for items on the backlog to raise them to the top of that list for discussion and removed needs-triage Have yet to determine what bucket this goes in. labels Jan 6, 2022
@marcpopMSFT marcpopMSFT removed this from the VS 17.2 milestone Dec 6, 2022
@KirillOsenkov
Copy link
Member Author

I just noticed that MuxLogger.SubmissionRecord only supports IEventSource2.

I think It needs to be enlightened to support IEventSource4:

IEventSource2

Here I think:

if (_eventSourceForBuild is IEventSource2 eventSource2)

@KirillOsenkov
Copy link
Member Author

Hmm, that's probably fine. I'm not even sure what SubmissionRecord is used for or whether that is relevant in any way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Debuggability Issues impacting the diagnosability of builds, including logging and clearer error messages. Area: Logging For consideration Used for items on the backlog to raise them to the top of that list for discussion triaged
Projects
None yet
Development

No branches or pull requests

5 participants