Add metrics for generated suggestions - add first logs to track experiment This is under feature flag UiFeature__ml_suggested_edit It is still prototype that will be tested. UI is still not final. Release-Notes: skip Google-Bug-Id: b/293257977 Change-Id: Id835d5b33d008aadf77944dbb948532ae9d2338c
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts index 9661547..0266610 100644 --- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts +++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -52,7 +52,7 @@ ValueChangedEvent, } from '../../../types/events'; import {fire} from '../../../utils/event-util'; -import {assertIsDefined, assert} from '../../../utils/common-util'; +import {assertIsDefined, assert, uuid} from '../../../utils/common-util'; import {Key, Modifier, whenVisible} from '../../../utils/dom-util'; import {commentsModelToken} from '../../../models/comments/comments-model'; import {sharedStyles} from '../../../styles/shared-styles'; @@ -75,6 +75,7 @@ commentModelToken, } from '../gr-comment-model/gr-comment-model'; import {formStyles} from '../../../styles/form-styles'; +import {Interaction} from '../../../constants/reporting'; // visible for testing export const AUTO_SAVE_DEBOUNCE_DELAY_MS = 2000; @@ -187,9 +188,6 @@ autoSaving?: Promise<DraftInfo>; @state() - generatedReplacement?: string; - - @state() changeNum?: NumericChangeId; @state() @@ -209,6 +207,12 @@ @state() generateSuggestion = true; + @state() + generatedReplacement?: string; + + @state() + generatedReplacementId?: string; + @property({type: Boolean, attribute: 'show-patchset'}) showPatchset = false; @@ -576,6 +580,7 @@ html`<gr-suggestion-diff-preview .showAddSuggestionButton=${true} .suggestion=${this.generatedReplacement} + .uuid=${this.generatedReplacementId} ></gr-suggestion-diff-preview>` )} </div> @@ -943,6 +948,11 @@ } else { this.generateSuggestionTrigger$.next(); } + this.reporting.reportInteraction( + this.generateSuggestion + ? Interaction.GENERATE_SUGGESTION_ENABLED + : Interaction.GENERATE_SUGGESTION_DISABLED + ); }} /> Generate Suggestion${numberOfSuggestions} @@ -964,6 +974,10 @@ if (suggestionsPlugins.length === 0) return; if (!this.changeNum || !this.comment?.patch_set || !this.comments?.[0].path) return; + this.generatedReplacementId = uuid(); + this.reporting.reportInteraction(Interaction.GENERATE_SUGGESTION_REQUEST, { + uuid: this.generatedReplacementId, + }); const suggestion = await suggestionsPlugins[0].provider.suggestCode({ prompt: this.messageText, changeNumber: this.changeNum, @@ -972,6 +986,10 @@ range: this.comments?.[0].range, lineNumber: this.comments?.[0].line, }); + this.reporting.reportInteraction(Interaction.GENERATE_SUGGESTION_RESPONSE, { + uuid: this.generatedReplacementId, + response: suggestion.responseCode, + }); const replacement = suggestion.suggestions?.[0]?.replacement; if (!replacement) return; this.generatedReplacement = replacement;