-
Notifications
You must be signed in to change notification settings - Fork 347
/
log_pattern_config.go
89 lines (75 loc) · 2.24 KB
/
log_pattern_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package expconf
import (
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/determined-ai/determined/master/pkg/schemas"
"github.com/determined-ai/determined/master/pkg/union"
)
// LogPoliciesConfigV0 is a list of log policies.
type LogPoliciesConfigV0 []LogPolicyV0
// Merge implemenets the mergable interface.
func (b LogPoliciesConfigV0) Merge(
other LogPoliciesConfigV0,
) LogPoliciesConfigV0 {
var out LogPoliciesConfigV0
seen := make(map[string]bool)
for _, p := range append(other, b...) {
json, err := json.Marshal(p)
if err != nil {
log.Errorf("marshaling error %+v %v", p, err)
}
if seen[string(json)] {
continue
}
seen[string(json)] = true
out = append(out, p)
}
return out
}
// LogPolicyV0 is an action to take if we match against trial logs.
//
//go:generate ../gen.sh
type LogPolicyV0 struct {
RawPattern string `json:"pattern"`
RawAction LogActionV0 `json:"action"`
}
// LogActionV0 is a policy to take after matching.
//
//go:generate ../gen.sh
type LogActionV0 struct {
RawCancelRetries *LogActionCancelRetriesV0 `union:"type,cancel_retries" json:"-"`
RawExcludeNode *LogActionExcludeNodeV0 `union:"type,exclude_node" json:"-"`
}
// Merge implements schemas.Mergeable.
func (s LogActionV0) Merge(other LogActionV0) LogActionV0 {
return schemas.UnionMerge(s, other)
}
// MarshalJSON implements the json.Marshaler interface.
func (s LogActionV0) MarshalJSON() ([]byte, error) {
return union.MarshalEx(s, true)
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (s *LogActionV0) UnmarshalJSON(data []byte) error {
if err := union.Unmarshal(data, s); err != nil {
return err
}
type DefaultParser *LogActionV0
if err := json.Unmarshal(data, DefaultParser(s)); err != nil {
return fmt.Errorf("failed to parse searcher config: %w", err)
}
return nil
}
// LogActionCancelRetriesV0 doesn't retry the trial if it fails.
//
//go:generate ../gen.sh
type LogActionCancelRetriesV0 struct {
// This comment is needed to stop ../gen.sh from complaining.
}
// LogActionExcludeNodeV0 will exclude the node the log was seen on
// (only for that trial) and reschedule.
//
//go:generate ../gen.sh
type LogActionExcludeNodeV0 struct {
// This comment is needed to stop ../gen.sh from complaining.
}