Просмотр исходного кода

Add event tracking for counts of matched compile log entries (#16615)

GitOrigin-RevId: 65f0efde77db5130cf8a709bb899d3231c3bdec4
Alf Eaton 2 лет назад
Родитель
Сommit
3ea151d129

+ 7 - 0
services/web/frontend/js/features/pdf-preview/util/output-files.js

@@ -163,6 +163,13 @@ export function buildLogEntryAnnotations(entries, fileTreeData, rootDocId) {
   return logEntryAnnotations
   return logEntryAnnotations
 }
 }
 
 
+export const countRules = (entries = []) =>
+  entries.reduce((counts, entry) => {
+    const { ruleId } = entry
+    counts[ruleId] = counts[ruleId] ? counts[ruleId] + 1 : 1
+    return counts
+  }, {})
+
 function buildURL(file, pdfDownloadDomain) {
 function buildURL(file, pdfDownloadDomain) {
   if (file.build && pdfDownloadDomain) {
   if (file.build && pdfDownloadDomain) {
     // Downloads from the compiles domain must include a build id.
     // Downloads from the compiles domain must include a build id.

+ 31 - 14
services/web/frontend/js/shared/context/local-compile-context.jsx

@@ -15,11 +15,13 @@ import useAbortController from '../hooks/use-abort-controller'
 import DocumentCompiler from '../../features/pdf-preview/util/compiler'
 import DocumentCompiler from '../../features/pdf-preview/util/compiler'
 import {
 import {
   send,
   send,
+  sendMB,
   sendMBOnce,
   sendMBOnce,
   sendMBSampled,
   sendMBSampled,
 } from '../../infrastructure/event-tracking'
 } from '../../infrastructure/event-tracking'
 import {
 import {
   buildLogEntryAnnotations,
   buildLogEntryAnnotations,
+  countRules,
   handleLogFiles,
   handleLogFiles,
   handleOutputFiles,
   handleOutputFiles,
 } from '../../features/pdf-preview/util/output-files'
 } from '../../features/pdf-preview/util/output-files'
@@ -32,6 +34,7 @@ import { useUserContext } from './user-context'
 import { useFileTreeData } from '@/shared/context/file-tree-data-context'
 import { useFileTreeData } from '@/shared/context/file-tree-data-context'
 import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
 import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
 import { useUserSettingsContext } from '@/shared/context/user-settings-context'
 import { useUserSettingsContext } from '@/shared/context/user-settings-context'
+import { useSplitTestContext } from '@/shared/context/split-test-context'
 
 
 export const LocalCompileContext = createContext()
 export const LocalCompileContext = createContext()
 
 
@@ -333,6 +336,8 @@ export function LocalCompileProvider({ children }) {
     }
     }
   }, [compiling, isProjectOwner, features])
   }, [compiling, isProjectOwner, features])
 
 
+  const { splitTestVariants } = useSplitTestContext()
+
   // handle the data returned from a compile request
   // handle the data returned from a compile request
   // note: this should _only_ run when `data` changes,
   // note: this should _only_ run when `data` changes,
   // the other dependencies must all be static
   // the other dependencies must all be static
@@ -378,21 +383,32 @@ export function LocalCompileProvider({ children }) {
             )
             )
 
 
             // sample compile stats for real users
             // sample compile stats for real users
-            if (
-              !window.user.alphaProgram &&
-              ['success', 'stopped-on-first-error'].includes(data.status)
-            ) {
-              sendMBSampled(
-                'compile-result',
-                {
-                  errors: result.logEntries.errors.length,
-                  warnings: result.logEntries.warnings.length,
-                  typesetting: result.logEntries.typesetting.length,
-                  newPdfPreview: true, // TODO: is this useful?
+            if (!window.user.alphaProgram) {
+              if (['success', 'stopped-on-first-error'].includes(data.status)) {
+                sendMBSampled(
+                  'compile-result',
+                  {
+                    errors: result.logEntries.errors.length,
+                    warnings: result.logEntries.warnings.length,
+                    typesetting: result.logEntries.typesetting.length,
+                    newPdfPreview: true, // TODO: is this useful?
+                    stopOnFirstError: data.options.stopOnFirstError,
+                  },
+                  0.01
+                )
+              }
+
+              if (splitTestVariants['compile-log-events'] === 'enabled') {
+                sendMB('compile-log-entries', {
+                  status: data.status,
                   stopOnFirstError: data.options.stopOnFirstError,
                   stopOnFirstError: data.options.stopOnFirstError,
-                },
-                0.01
-              )
+                  isAutoCompileOnLoad: !!data.options.isAutoCompileOnLoad,
+                  isAutoCompileOnChange: !!data.options.isAutoCompileOnChange,
+                  errors: countRules(result.logEntries.errors),
+                  warnings: countRules(result.logEntries.warnings),
+                  typesetting: countRules(result.logEntries.typesetting),
+                })
+              }
             }
             }
           }
           }
         )
         )
@@ -470,6 +486,7 @@ export function LocalCompileProvider({ children }) {
     setLogEntries,
     setLogEntries,
     setLogEntryAnnotations,
     setLogEntryAnnotations,
     setPdfFile,
     setPdfFile,
+    splitTestVariants,
   ])
   ])
 
 
   // switch to logs if there's an error
   // switch to logs if there's an error