@@ -23,6 +23,9 @@ const (
23
23
investigationStatusFailed investigationStatus = "failed"
24
24
)
25
25
26
+ // errorPatternLogExampleLimit controls how many log examples are fetched per error pattern.
27
+ const errorPatternLogExampleLimit = 3
28
+
26
29
type analysisStatus string
27
30
28
31
type investigationRequest struct {
@@ -39,10 +42,10 @@ type investigationRequest struct {
39
42
40
43
// Interesting: The analysis complete with results that indicate a probable cause for failure.
41
44
type analysisResult struct {
42
- Successful bool `json:"successful"`
43
- Interesting bool `json:"interesting"`
44
- Message string `json:"message"`
45
- Details map [string ]interface {} `json:"details"`
45
+ Successful bool `json:"successful"`
46
+ Interesting bool `json:"interesting"`
47
+ Message string `json:"message"`
48
+ Details map [string ]any `json:"details"`
46
49
}
47
50
48
51
type analysisMeta struct {
@@ -68,6 +71,12 @@ type analysis struct {
68
71
Result analysisResult `json:"result"`
69
72
}
70
73
74
+ type InvestigationDatasources struct {
75
+ LokiDatasource struct {
76
+ UID string `json:"uid"`
77
+ } `json:"lokiDatasource"`
78
+ }
79
+
71
80
type Investigation struct {
72
81
ID uuid.UUID `json:"id"`
73
82
CreatedAt time.Time `json:"created"`
@@ -89,6 +98,8 @@ type Investigation struct {
89
98
FailureReason string `json:"failureReason,omitempty"`
90
99
91
100
Analyses analysisMeta `json:"analyses"`
101
+
102
+ Datasources InvestigationDatasources `json:"datasources"`
92
103
}
93
104
94
105
// siftClient represents a client for interacting with the Sift API.
@@ -285,6 +296,20 @@ func findErrorPatternLogs(ctx context.Context, args FindErrorPatternLogsParams)
285
296
return nil , fmt .Errorf ("ErrorPatternLogs analysis not found in investigation %s" , completedInvestigation .ID )
286
297
}
287
298
299
+ datasourceUID := completedInvestigation .Datasources .LokiDatasource .UID
300
+
301
+ for _ , pattern := range errorPatternLogsAnalysis .Result .Details ["patterns" ].([]any ) {
302
+ patternMap , ok := pattern .(map [string ]any )
303
+ if ! ok {
304
+ continue
305
+ }
306
+ examples , err := fetchErrorPatternLogExamples (ctx , patternMap , datasourceUID )
307
+ if err != nil {
308
+ return nil , err
309
+ }
310
+ patternMap ["examples" ] = examples
311
+ }
312
+
288
313
return errorPatternLogsAnalysis , nil
289
314
}
290
315
@@ -550,3 +575,22 @@ func (c *siftClient) listSiftInvestigations(ctx context.Context, limit int) ([]I
550
575
551
576
return response .Data , nil
552
577
}
578
+
579
+ func fetchErrorPatternLogExamples (ctx context.Context , patternMap map [string ]any , datasourceUID string ) ([]string , error ) {
580
+ query , _ := patternMap ["query" ].(string )
581
+ logEntries , err := queryLokiLogs (ctx , QueryLokiLogsParams {
582
+ DatasourceUID : datasourceUID ,
583
+ LogQL : query ,
584
+ Limit : errorPatternLogExampleLimit ,
585
+ })
586
+ if err != nil {
587
+ return nil , fmt .Errorf ("querying Loki: %w" , err )
588
+ }
589
+ var examples []string
590
+ for _ , entry := range logEntries {
591
+ if entry .Line != "" {
592
+ examples = append (examples , entry .Line )
593
+ }
594
+ }
595
+ return examples , nil
596
+ }
0 commit comments