1
1
package pkg
2
2
3
3
import (
4
- "encoding/json"
5
4
"fmt"
6
5
"strings"
7
6
"time"
8
7
9
8
"github.com/flanksource/canary-checker/api/external"
10
9
v1 "github.com/flanksource/canary-checker/api/v1"
11
10
"github.com/flanksource/commons/console"
12
- "github.com/mitchellh/mapstructure"
13
- "github.com/pkg/errors"
14
11
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
12
)
16
13
@@ -45,16 +42,15 @@ type CheckStatus struct {
45
42
}
46
43
47
44
type Check struct {
48
- Key string
45
+ Key string `json:"key"`
49
46
Type string `json:"type"`
50
47
Name string `json:"name"`
51
48
Description string `json:"description"`
49
+ Endpoint string `json:"endpoint"`
52
50
Uptime string `json:"uptime"`
53
51
Latency string `json:"latency"`
54
52
Statuses []CheckStatus `json:"checkStatuses" mapstructure:"-"`
55
- // CheckConf is the configuration
56
- CheckConf external.Check `json:"checkConf" mapstructure:"-"`
57
- CheckCanary * v1.Canary `json:"-"`
53
+ CheckCanary * v1.Canary `json:"-"`
58
54
}
59
55
60
56
type Checks []Check
@@ -78,51 +74,6 @@ func (c Check) GetDescription() string {
78
74
return c .Description
79
75
}
80
76
81
- func (c * Check ) UnmarshalJSON (data []byte ) error {
82
- // Unmarshalling checkStatuses because of custom JSONTime
83
- var objmap map [string ]json.RawMessage
84
- if err := json .Unmarshal (data , & objmap ); err != nil {
85
- return errors .Wrapf (err , "unmarshal map[string]json.RawMessage error" )
86
- }
87
-
88
- var statuses []CheckStatus
89
- if err := json .Unmarshal (objmap ["checkStatuses" ], & statuses ); err != nil {
90
- return errors .Wrapf (err , "unmarshal statuses error" )
91
- }
92
-
93
- // Unmarshalling to interface to getting proper CheckConf type
94
- var m map [string ]interface {}
95
- if err := json .Unmarshal (data , & m ); err != nil {
96
- return errors .Wrapf (err , "unmarshal map[string]interface{} error" )
97
- }
98
-
99
- checkType := fmt .Sprintf ("%v" , m ["type" ])
100
-
101
- var checkConf external.Check
102
- for _ , _c := range v1 .AllChecks {
103
- c := _c
104
- if c .GetType () == checkType {
105
- checkConf = c
106
- }
107
- }
108
- if checkConf == nil {
109
- return fmt .Errorf ("external check type not found %s" , checkType )
110
- }
111
-
112
- if err := mapstructure .Decode (m ["checkConf" ], & checkConf ); err != nil {
113
- return errors .Wrapf (err , "external check mapstructure err" )
114
- }
115
-
116
- // Decode rest of check fields
117
- if err := mapstructure .Decode (m , c ); err != nil {
118
- return errors .Wrapf (err , "check mapstructure err" )
119
- }
120
-
121
- c .CheckConf = checkConf
122
- c .Statuses = statuses
123
- return nil
124
- }
125
-
126
77
type Config struct {
127
78
HTTP []v1.HTTPCheck `yaml:"http,omitempty" json:"http,omitempty"`
128
79
DNS []v1.DNSCheck `yaml:"dns,omitempty" json:"dns,omitempty"`
0 commit comments