-
Notifications
You must be signed in to change notification settings - Fork 53
/
validation.go
80 lines (73 loc) · 2.05 KB
/
validation.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
package node
import (
"github.com/prometheus/common/model"
"github.com/rancher/opni/pkg/validation"
)
func (s *SyncRequest) Validate() error {
if s.CurrentConfig == nil {
return validation.Errorf("%w: %s", validation.ErrMissingRequiredField, "CurrentConfig")
}
if s.CurrentConfig.Spec == nil {
return validation.Errorf("%w: %s", validation.ErrMissingRequiredField, "CurrentConfig.Spec")
}
return s.CurrentConfig.Spec.Validate()
}
func (m *MetricsCapabilitySpec) Validate() error {
if m.GetPrometheus() != nil && m.GetOtel() != nil {
return validation.Errorf("Only one configuration can be set at a time: Prometheus, Otel")
}
if m.GetPrometheus() == nil && m.GetOtel() == nil {
return validation.Errorf("one of Prometheus or Otel specs must be set")
}
if m.GetOtel() != nil {
return m.GetOtel().Validate()
}
return nil
}
func (o *OTELSpec) Validate() error {
if len(o.AdditionalScrapeConfigs) > 0 {
for _, config := range o.AdditionalScrapeConfigs {
if err := config.Validate(); err != nil {
return err
}
}
}
if o.Wal != nil {
if err := o.Wal.Validate(); err != nil {
return err
}
}
return nil
}
func (w *WALConfig) Validate() error {
if w.Enabled {
if w.BufferSize <= 0 {
return validation.Error("WAL BufferSize must be greater than 0")
}
if w.TruncateFrequency == nil {
return validation.Error("WALConfig TruncateFrequency must be set")
}
}
return nil
}
func (s *ScrapeConfig) Validate() error {
if s.JobName == "" {
return validation.Errorf("%w: %s", validation.ErrMissingRequiredField, "JobName")
}
if len(s.Targets) == 0 {
return validation.Errorf("%w: %s", validation.ErrMissingRequiredField, "Targets")
}
for _, t := range s.Targets {
if t == "" {
return validation.Errorf("%w: %s", validation.ErrMissingRequiredField, "Target")
}
}
if s.ScrapeInterval == "" {
return validation.Errorf("%w: %s", validation.ErrMissingRequiredField, "ScrapeInterval")
}
_, err := model.ParseDuration(s.ScrapeInterval)
if err != nil {
return validation.Errorf("invalid ScrapeInterval: %s", err)
}
return nil
}