Skip to content

Commit 47c49af

Browse files
committed
Make it possible to send projectstarted events that represent the node the project lived on when sending cached results
1 parent 550731c commit 47c49af

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

src/Build/BackEnd/Components/Logging/NodeLoggingContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ internal ProjectLoggingContext LogProjectStarted(BuildRequestEntry requestEntry)
7979
internal ProjectLoggingContext LogProjectStarted(BuildRequest request, BuildRequestConfiguration configuration)
8080
{
8181
ErrorUtilities.VerifyThrow(this.IsValid, "Build not started.");
82-
return new ProjectLoggingContext(this, request, configuration.ProjectFullPath, configuration.ToolsVersion, configuration.ProjectEvaluationId);
82+
return new ProjectLoggingContext(this, request, configuration);
8383
}
8484

8585
/// <summary>

src/Build/BackEnd/Components/Logging/ProjectLoggingContext.cs

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ internal ProjectLoggingContext(NodeLoggingContext nodeLoggingContext, BuildReque
4646
requestEntry.RequestConfiguration.Project.ItemsToBuildWith,
4747
requestEntry.Request.ParentBuildEventContext,
4848
requestEntry.RequestConfiguration.ProjectEvaluationId,
49-
requestEntry.Request.ProjectContextId)
49+
requestEntry.Request.ProjectContextId,
50+
requestEntry.Request.ScheduledNodeId)
5051
{
5152
}
5253

@@ -56,22 +57,22 @@ internal ProjectLoggingContext(NodeLoggingContext nodeLoggingContext, BuildReque
5657
internal ProjectLoggingContext(
5758
NodeLoggingContext nodeLoggingContext,
5859
BuildRequest request,
59-
string projectFullPath,
60-
string toolsVersion,
61-
int evaluationId)
60+
BuildRequestConfiguration configuration)
6261
: this
6362
(
6463
nodeLoggingContext,
6564
request.SubmissionId,
6665
request.ConfigurationId,
67-
projectFullPath,
66+
configuration.ProjectFullPath,
6867
request.Targets,
69-
toolsVersion,
68+
configuration.ToolsVersion,
7069
projectProperties: null,
7170
projectItems: null,
7271
request.ParentBuildEventContext,
73-
evaluationId,
74-
request.ProjectContextId)
72+
// if the project was built on a different node, the evaluation id will be a lie anyway, make that super clear
73+
configuration.ResultsNodeId != nodeLoggingContext.BuildEventContext.NodeId ? int.MaxValue : configuration.ProjectEvaluationId,
74+
request.ProjectContextId,
75+
configuration.ResultsNodeId)
7576
{
7677
}
7778

@@ -93,7 +94,9 @@ public static (ProjectStartedEventArgs, ProjectLoggingContext) CreateLoggingCont
9394
requestEntry.RequestConfiguration.Project.ItemsToBuildWith,
9495
requestEntry.Request.ParentBuildEventContext,
9596
requestEntry.RequestConfiguration.ProjectEvaluationId,
96-
requestEntry.Request.ProjectContextId);
97+
requestEntry.Request.ProjectContextId,
98+
// in this scenario we are on the same node, so just use the current node id
99+
nodeLoggingContext.BuildEventContext.NodeId);
97100

98101
return (args, new ProjectLoggingContext(nodeLoggingContext, args));
99102
}
@@ -117,6 +120,18 @@ private ProjectLoggingContext(
117120
/// <summary>
118121
/// Constructs a project logging contexts.
119122
/// </summary>
123+
/// <param name="nodeLoggingContext">The node logging context for the currently executing node.</param>
124+
/// <param name="submissionId">The submission id for this project.</param>
125+
/// <param name="configurationId">The configuration id for this project.</param>
126+
/// <param name="projectFullPath">The full path to the project file.</param>
127+
/// <param name="targets">The targets being built in this project.</param>
128+
/// <param name="toolsVersion">The tools version for this project.</param>
129+
/// <param name="projectProperties">The properties in the project.</param>
130+
/// <param name="projectItems">The items in the project.</param>
131+
/// <param name="parentBuildEventContext">The parent build event context.</param>
132+
/// <param name="evaluationId">The evaluation id for this project.</param>
133+
/// <param name="projectContextId">The project context id for this project.</param>
134+
/// <param name="hostNodeId">The node id hosting this project - may be different from that of the nodeLoggingContext if this project was actually started/built on another node</param>
120135
private ProjectLoggingContext(
121136
NodeLoggingContext nodeLoggingContext,
122137
int submissionId,
@@ -128,7 +143,8 @@ private ProjectLoggingContext(
128143
IItemDictionary<ProjectItemInstance> projectItems,
129144
BuildEventContext parentBuildEventContext,
130145
int evaluationId,
131-
int projectContextId)
146+
int projectContextId,
147+
int hostNodeId)
132148
: base(nodeLoggingContext,
133149
CreateInitialContext(nodeLoggingContext,
134150
submissionId,
@@ -140,7 +156,8 @@ private ProjectLoggingContext(
140156
projectItems,
141157
parentBuildEventContext,
142158
evaluationId,
143-
projectContextId))
159+
projectContextId,
160+
hostNodeId))
144161
{
145162
_projectFullPath = projectFullPath;
146163

@@ -164,7 +181,8 @@ private static BuildEventContext CreateInitialContext(
164181
IItemDictionary<ProjectItemInstance> projectItems,
165182
BuildEventContext parentBuildEventContext,
166183
int evaluationId,
167-
int projectContextId)
184+
int projectContextId,
185+
int hostNodeId)
168186
{
169187
ProjectStartedEventArgs args = CreateProjectStarted(
170188
nodeLoggingContext,
@@ -177,7 +195,8 @@ private static BuildEventContext CreateInitialContext(
177195
projectItems,
178196
parentBuildEventContext,
179197
evaluationId,
180-
projectContextId);
198+
projectContextId,
199+
hostNodeId);
181200

182201
nodeLoggingContext.LoggingService.LogProjectStarted(args);
183202

@@ -195,7 +214,8 @@ private static ProjectStartedEventArgs CreateProjectStarted(
195214
IItemDictionary<ProjectItemInstance> projectItems,
196215
BuildEventContext parentBuildEventContext,
197216
int evaluationId,
198-
int projectContextId)
217+
int projectContextId,
218+
int hostNodeId)
199219
{
200220
IEnumerable<DictionaryEntry> properties = null;
201221
IEnumerable<DictionaryEntry> items = null;
@@ -246,7 +266,8 @@ private static ProjectStartedEventArgs CreateProjectStarted(
246266
}
247267

248268
return loggingService.CreateProjectStarted(
249-
nodeLoggingContext.BuildEventContext,
269+
// adjust the message to come from the node that actually built the project
270+
nodeLoggingContext.BuildEventContext.WithNodeId(hostNodeId),
250271
submissionId,
251272
configurationId,
252273
parentBuildEventContext,

src/Build/BackEnd/Components/RequestBuilder/RequestBuilder.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,9 +1143,7 @@ private async Task<BuildResult> BuildProject()
11431143
_projectLoggingContext = new ProjectLoggingContext(
11441144
_nodeLoggingContext,
11451145
_requestEntry.Request,
1146-
_requestEntry.RequestConfiguration.ProjectFullPath,
1147-
_requestEntry.RequestConfiguration.ToolsVersion,
1148-
_requestEntry.RequestConfiguration.ProjectEvaluationId);
1146+
_requestEntry.RequestConfiguration);
11491147

11501148
throw;
11511149
}

0 commit comments

Comments
 (0)