Skip to content

Commit 581e6eb

Browse files
committed
fix xid errors
Signed-off-by: Davanum Srinivas <[email protected]>
1 parent 9ada771 commit 581e6eb

File tree

5 files changed

+717
-249
lines changed

5 files changed

+717
-249
lines changed

health-events-analyzer/pkg/config/rules.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@ import (
2020
"github.com/nvidia/nvsentinel/commons/pkg/configmanager"
2121
)
2222

23-
type SequenceStep struct {
24-
Criteria map[string]interface{} `toml:"criteria"`
25-
ErrorCount int `toml:"errorCount"`
26-
}
27-
2823
type HealthEventsAnalyzerRule struct {
29-
Name string `toml:"name"`
30-
Description string `toml:"description"`
31-
TimeWindow string `toml:"time_window"`
32-
Sequence []SequenceStep `toml:"sequence"`
33-
RecommendedAction string `toml:"recommended_action"`
24+
Name string `toml:"name"`
25+
Description string `toml:"description"`
26+
Stage []string `toml:"stage"`
27+
RecommendedAction string `toml:"recommended_action"`
3428
}
3529

3630
type TomlConfig struct {

health-events-analyzer/pkg/parser/parser.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,80 @@ import (
2525
datamodels "github.com/nvidia/nvsentinel/data-models/pkg/model"
2626
)
2727

28+
// ParseSequenceStage parses a JSON stage string and replaces "this." references with actual event values
29+
func ParseSequenceStage(stage string, event datamodels.HealthEventWithStatus) (map[string]interface{}, error) {
30+
var stageMap map[string]interface{}
31+
if err := json.Unmarshal([]byte(stage), &stageMap); err != nil {
32+
return nil, fmt.Errorf("failed to unmarshal stage '%s': %w", stage, err)
33+
}
34+
35+
for key, value := range stageMap {
36+
processedValue, err := processValue(value, event)
37+
if err != nil {
38+
return nil, err
39+
}
40+
41+
stageMap[key] = processedValue
42+
}
43+
44+
return stageMap, nil
45+
}
46+
47+
// processValue recursively processes any value type and replaces "this." references with actual event values
48+
func processValue(value interface{}, event datamodels.HealthEventWithStatus) (interface{}, error) {
49+
switch v := value.(type) {
50+
case string:
51+
if strings.HasPrefix(v, "this.") {
52+
fieldPath := strings.TrimPrefix(v, "this.")
53+
54+
resolvedValue, err := getValueFromPath(fieldPath, event)
55+
if err != nil {
56+
return nil, fmt.Errorf("error in getting value from path '%s': %w", fieldPath, err)
57+
}
58+
59+
return resolvedValue, nil
60+
}
61+
62+
return v, nil
63+
case map[string]interface{}:
64+
return processMapValue(v, event)
65+
case []interface{}:
66+
return processArrayValue(v, event)
67+
default:
68+
return v, nil
69+
}
70+
}
71+
72+
func processMapValue(v map[string]interface{}, event datamodels.HealthEventWithStatus) (map[string]interface{}, error) {
73+
result := make(map[string]interface{})
74+
75+
for key, val := range v {
76+
processedVal, err := processValue(val, event)
77+
if err != nil {
78+
return nil, err
79+
}
80+
81+
result[key] = processedVal
82+
}
83+
84+
return result, nil
85+
}
86+
87+
func processArrayValue(v []interface{}, event datamodels.HealthEventWithStatus) ([]interface{}, error) {
88+
result := make([]interface{}, len(v))
89+
90+
for i, val := range v {
91+
processedVal, err := processValue(val, event)
92+
if err != nil {
93+
return nil, err
94+
}
95+
96+
result[i] = processedVal
97+
}
98+
99+
return result, nil
100+
}
101+
28102
// ParseSequenceString converts a criteria map into a database filter map
29103
// This uses the same map[string]interface{} type as store-client filters
30104
func ParseSequenceString(

0 commit comments

Comments
 (0)