Skip to content

Commit 7b03d39

Browse files
committed
SF-3622 Definitively associate draft generation metrics
Records SF request id to help find related events. Drafting event metrics that are associated with the same NMT draft generation request have a 'tags.draftGenerationRequestId' written to them with an SF-specific id. This id is transferred around by Activity.Current.Tags, by method arguments, and looked up by finding a BuildProjectAsync event with a Serval build id. When SMT is used, `null` is passed for draftGenerationRequestId method arguments. The frontend draft-jobs component considers event metrics using both the older grouping logic as well as a new grouping system which uses the draftGenerationRequestId to group events. The new system considers the BuildCompletedAsync event to be the finishing event for a job, but also allows RetrievePreTranslationStatusAsync events with a result field equaling the Serval build id to count as a finishing event, for easier use in development. A bug represented in the sample data was corrected to show the incorrect behaviour of recording sf project id in the "userId" field, rather than recording sf user id as a sf project id. Grouping draft jobs by the draft job generation request id instead of timing is optional, to give opportunity to test the new system.
1 parent c1d2325 commit 7b03d39

24 files changed

+1958
-169
lines changed

.github/copilot-instructions.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,35 @@ This repository contains three interconnected applications:
4242

4343
- Write unit tests for new components and services
4444
- Follow existing patterns for mocking dependencies
45-
- Use TestEnvironment pattern from existing tests. Use the TestEnvironment class pattern rather than using a `beforeEach`.
45+
- Use TestEnvironment pattern from existing tests. Use the TestEnvironment class pattern rather than using a `beforeEach`. Do not put helper functions outside of TestEnvironment classes; helper functions or setup functions should be in the TestEnvironment class.
4646
- Test both online and offline scenarios
4747
- Test permission boundaries
48+
- When a TestEnvironment class is being given many optional arguments, prefer using object destructuring with default values, and the argument type definition specified inline rather than as an interface. For example,
49+
```typescript
50+
class TestEnvironment {
51+
constructor({
52+
someRequired,
53+
someOptional = 'abc',
54+
}: {
55+
someRequired: string;
56+
someOptional?: string;
57+
}) {
58+
...
59+
}
60+
}
61+
```
62+
Example using `= {}` when all items are optional:
63+
```typescript
64+
class TestEnvironment {
65+
constructor({
66+
someOptional = 'abc',
67+
}: {
68+
someOptional?: string;
69+
} = {}) {
70+
...
71+
}
72+
}
73+
```
4874

4975
# Code comments
5076

@@ -53,14 +79,20 @@ This repository contains three interconnected applications:
5379
- Do not add method comments unless the method would be unclear to an experienced developer.
5480
- Do put comments into the code to make it more clear what is going on if it would not be obvious to an experienced developer.
5581
- Do put comments into the code if the intent is not clear from the code.
56-
- All classes should have a comment to briefly explain why it is there and what its purpose is in the overall system, even if it seems obvious.
57-
- Please do not fail to add a comment to any classes that are created. All classes should have a comment.
82+
- All classes and interfaces should have a comment to briefly explain why it is there and what its purpose is in the overall system, even if it seems obvious.
83+
- Please do not fail to add a comment to any classes or interfaces that are created. All classes and interfaces should have a comment.
5884

5985
# TypeScript language
6086

6187
- Use explicit true/false/null/undefined rather than truthy/falsy
6288
- Never rely on JavaScript's truthy or falsy. Instead, work with actual true, false, null, and undefined values, rather than relying on their interpretation as truthy or falsy. For example, if `count` might be null, or undefined, or zero, don't write code like `if (count)` or `const foo:string = someVariable ? 'a' : 'b'`. Instead, inspect for the null, undefined, or zero rather than letting the value be interpreted as truthy for falsy. For example, use `if (count == null)` or `const foo:string = someVariable != null 'a' : 'b'` or `if (count > 0)`.
63-
- Specify types where not obvious, such as when declaring variables and arguments, and for function return types.
89+
- Specify types when declaring variables, arguments, and for function return types. For example, don't write
90+
`const projectId = this.determineProjectId();` or
91+
`const buildEvents = eventsSorted.filter(...);` or
92+
`const buildEvent = buildEvents[0];`. Instead, write
93+
`const projectId: string | undefined = this.determineProjectId();` and
94+
`const buildEvents: EventMetric[] = eventsSorted.filter(...);` and
95+
`const buildEvent: EventMetric | undefined = buildEvents[0];`.
6496
- Use `@if {}` syntax rather than `*ngIf` syntax.
6597
- Although interacting with existing code and APIs may necessitate the use of `null`, when writing new code, prefer using `undefined` rather than `null`.
6698
- Fields that are of type Subject or BehaviorSubject should have names that end with a `$`.
@@ -72,6 +104,7 @@ This repository contains three interconnected applications:
72104
- It is better to write code that is verbose and understandable than terse and concise.
73105
- It is better to explicitly check for and handle problems, or prevent problems from happening, than to assume problems will not happen.
74106
- Corner-cases happen. They should be handled in code.
107+
- Please don't change existing code without good justification. Existing code largely works and changing it will cause work for code review. Leave existing code as is when possible.
75108

76109
# Running commands
77110

src/SIL.XForge.Scripture/ClientApp/src/app/app.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { BidiModule } from '@angular/cdk/bidi';
22
import { BreakpointObserver, BreakpointState } from '@angular/cdk/layout';
33
import { CdkScrollable } from '@angular/cdk/scrolling';
4-
import { AsyncPipe } from '@angular/common';
5-
import { Component, DestroyRef, DOCUMENT, HostBinding, Inject, OnDestroy, OnInit } from '@angular/core';
4+
import { AsyncPipe, DOCUMENT } from '@angular/common';
5+
import { Component, DestroyRef, HostBinding, Inject, OnDestroy, OnInit } from '@angular/core';
66
import { MatButton, MatIconAnchor, MatIconButton } from '@angular/material/button';
77
import { MatDivider } from '@angular/material/divider';
88
import { MatIcon } from '@angular/material/icon';

src/SIL.XForge.Scripture/ClientApp/src/app/event-metrics/event-metric.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface EventMetric {
99
timeStamp: string;
1010
userId?: string;
1111
executionTime?: string;
12+
tags?: { [key: string]: any | undefined };
1213
}
1314

1415
export enum EventScope {

src/SIL.XForge.Scripture/ClientApp/src/app/serval-administration/draft-jobs.component.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
}
2727
</div>
2828
}
29+
<div class="grouping-toggle">
30+
<div class="grouping-toggle-label">
31+
Determination
32+
<app-info
33+
text="Whether to determine build activity more strictly by using request ID where available, or always by using timing."
34+
></app-info>
35+
</div>
36+
<mat-button-toggle-group [value]="groupingMode" (valueChange)="onGroupingModeChange($event)">
37+
<mat-button-toggle value="requestId">Request ID</mat-button-toggle>
38+
<mat-button-toggle value="timing">Timing</mat-button-toggle>
39+
</mat-button-toggle-group>
40+
</div>
2941
</div>
3042

3143
@if (!isLoading) {

src/SIL.XForge.Scripture/ClientApp/src/app/serval-administration/draft-jobs.component.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@
130130
font-weight: 500;
131131
}
132132
}
133+
134+
.grouping-toggle {
135+
margin-bottom: 1rem;
136+
align-self: flex-start;
137+
display: flex;
138+
flex-direction: column;
139+
align-items: center;
140+
141+
> .grouping-toggle-label {
142+
display: flex;
143+
margin-bottom: 0.5rem;
144+
app-info {
145+
margin-left: 0.25rem;
146+
}
147+
}
148+
}
133149
}
134150

135151
.project-link {

0 commit comments

Comments
 (0)