@@ -107,6 +107,7 @@ async function mineEventPatterns(logs: string[], pyodide: any) {
107107export const PATTERN_COLUMN_ALIAS = '__hdx_pattern_field' ;
108108export const TIMESTAMP_COLUMN_ALIAS = '__hdx_timestamp' ;
109109export const SEVERITY_TEXT_COLUMN_ALIAS = '__hdx_severity_text' ;
110+ export const STATUS_CODE_COLUMN_ALIAS = '__hdx_status_code' ;
110111
111112export type SampleLog = {
112113 [ PATTERN_COLUMN_ALIAS ] : string ;
@@ -126,12 +127,14 @@ function usePatterns({
126127 samples,
127128 bodyValueExpression,
128129 severityTextExpression,
130+ statusCodeExpression,
129131 enabled = true ,
130132} : {
131133 config : ChartConfigWithDateRange ;
132134 samples : number ;
133135 bodyValueExpression : string ;
134136 severityTextExpression ?: string ;
137+ statusCodeExpression ?: string ;
135138 enabled ?: boolean ;
136139} ) {
137140 const configWithPrimaryAndPartitionKey = useConfigWithPrimaryAndPartitionKey ( {
@@ -143,6 +146,9 @@ function usePatterns({
143146 ...( severityTextExpression
144147 ? [ `${ severityTextExpression } as ${ SEVERITY_TEXT_COLUMN_ALIAS } ` ]
145148 : [ ] ) ,
149+ ...( statusCodeExpression
150+ ? [ `${ statusCodeExpression } as ${ STATUS_CODE_COLUMN_ALIAS } ` ]
151+ : [ ] ) ,
146152 ] . join ( ',' ) ,
147153 // TODO: Proper sampling
148154 orderBy : [ { ordering : 'DESC' , valueExpression : 'rand()' } ] ,
@@ -210,13 +216,15 @@ export function useGroupedPatterns({
210216 samples,
211217 bodyValueExpression,
212218 severityTextExpression,
219+ statusCodeExpression,
213220 totalCount,
214221 enabled = true ,
215222} : {
216223 config : ChartConfigWithDateRange ;
217224 samples : number ;
218225 bodyValueExpression : string ;
219226 severityTextExpression ?: string ;
227+ statusCodeExpression ?: string ;
220228 totalCount ?: number ;
221229 enabled ?: boolean ;
222230} ) {
@@ -229,15 +237,9 @@ export function useGroupedPatterns({
229237 samples,
230238 bodyValueExpression,
231239 severityTextExpression,
240+ statusCodeExpression,
232241 enabled,
233242 } ) ;
234- const columnMap = useMemo ( ( ) => {
235- return selectColumnMapWithoutAdditionalKeys (
236- results ?. meta ,
237- results ?. additionalKeysLength ,
238- ) ;
239- } , [ results ] ) ;
240- const columns = useMemo ( ( ) => Array . from ( columnMap . keys ( ) ) , [ columnMap ] ) ;
241243
242244 const sampledRowCount = results ?. data . length ;
243245 const sampleMultiplier = useMemo ( ( ) => {
@@ -283,12 +285,15 @@ export function useGroupedPatterns({
283285
284286 // return at least 1
285287 const count = Math . max ( Math . round ( rows . length * sampleMultiplier ) , 1 ) ;
288+ const lastRow = rows . at ( - 1 ) ;
289+
286290 fullPatternGroups [ patternId ] = {
287291 id : patternId ,
288- pattern : rows [ rows . length - 1 ] . __hdx_pattern , // last pattern is usually the most up to date templated pattern
292+ pattern : lastRow ? .__hdx_pattern , // last pattern is usually the most up to date templated pattern
289293 count,
290294 countStr : `~${ count } ` ,
291- severityText : rows [ rows . length - 1 ] . __hdx_severity_text , // last severitytext is usually representative of the entire pattern set
295+ severityText : lastRow ?. [ SEVERITY_TEXT_COLUMN_ALIAS ] , // last severitytext is usually representative of the entire pattern set
296+ statusCode : lastRow ?. [ STATUS_CODE_COLUMN_ALIAS ] ,
292297 samples : rows ,
293298 __hdx_pattern_trend : {
294299 data : Object . entries ( bucketCounts ) . map ( ( [ bucket , count ] ) => ( {
0 commit comments