Skip to content

Commit 712cf64

Browse files
committed
rename fields
Signed-off-by: Markus Blaschke <[email protected]>
1 parent 5a51526 commit 712cf64

File tree

4 files changed

+54
-54
lines changed

4 files changed

+54
-54
lines changed

prometheus/kusto/config.go

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ const (
2929

3030
type (
3131
Config struct {
32-
Queries []ConfigQuery `json:"queries"`
32+
Queries []Query `json:"queries"`
3333
}
3434

35-
ConfigQuery struct {
36-
*ConfigQueryMetric
35+
Query struct {
36+
*Metric
3737
QueryMode string `json:"queryMode"`
3838
Workspaces *[]string `json:"workspaces"`
3939
Metric string `json:"metric"`
@@ -43,33 +43,33 @@ type (
4343
Subscriptions *[]string `json:"subscriptions"`
4444
}
4545

46-
ConfigQueryMetric struct {
47-
Value *float64 `json:"value"`
48-
Fields []ConfigQueryMetricField `json:"fields"`
49-
Labels map[string]string `json:"labels"`
50-
DefaultField ConfigQueryMetricField `json:"defaultField"`
51-
Publish *bool `json:"publish"`
46+
Metric struct {
47+
Value *float64 `json:"value"`
48+
Fields []MetricField `json:"fields"`
49+
Labels map[string]string `json:"labels"`
50+
DefaultField MetricField `json:"defaultField"`
51+
Publish *bool `json:"publish"`
5252
}
5353

54-
ConfigQueryMetricField struct {
55-
Name string `json:"name"`
56-
Metric string `json:"metric"`
57-
Source string `json:"source"`
58-
Target string `json:"target"`
59-
Type string `json:"type"`
60-
Labels map[string]string `json:"labels"`
61-
Filters []ConfigQueryMetricFieldFilter `json:"filters"`
62-
Expand *ConfigQueryMetric `json:"expand"`
54+
MetricField struct {
55+
Name string `json:"name"`
56+
Metric string `json:"metric"`
57+
Source string `json:"source"`
58+
Target string `json:"target"`
59+
Type string `json:"type"`
60+
Labels map[string]string `json:"labels"`
61+
Filters []MetricFieldFilter `json:"filters"`
62+
Expand *Metric `json:"expand"`
6363
}
6464

65-
ConfigQueryMetricFieldFilter struct {
65+
MetricFieldFilter struct {
6666
Type string `json:"type"`
6767
RegExp string `json:"regexp"`
6868
Replacement string `json:"replacement"`
6969
parsedRegexp *regexp.Regexp
7070
}
7171

72-
ConfigQueryMetricFieldFilterParser struct {
72+
MetricFieldFilterParser struct {
7373
Type string `json:"type"`
7474
RegExp string `json:"regexp"`
7575
Replacement string `json:"replacement"`
@@ -90,15 +90,15 @@ func (c *Config) Validate() error {
9090
return nil
9191
}
9292

93-
func (c *ConfigQuery) Validate() error {
94-
if err := c.ConfigQueryMetric.Validate(); err != nil {
93+
func (c *Query) Validate() error {
94+
if err := c.Metric.Validate(); err != nil {
9595
return err
9696
}
9797

9898
return nil
9999
}
100100

101-
func (c *ConfigQueryMetric) Validate() error {
101+
func (c *Metric) Validate() error {
102102
// validate default field
103103
c.DefaultField.Name = "default"
104104
if err := c.DefaultField.Validate(); err != nil {
@@ -115,15 +115,15 @@ func (c *ConfigQueryMetric) Validate() error {
115115
return nil
116116
}
117117

118-
func (c *ConfigQueryMetric) IsPublished() bool {
118+
func (c *Metric) IsPublished() bool {
119119
if c.Publish != nil {
120120
return *c.Publish
121121
}
122122

123123
return true
124124
}
125125

126-
func (c *ConfigQueryMetricField) Validate() error {
126+
func (c *MetricField) Validate() error {
127127
if c.Name == "" {
128128
return errors.New("no field name set")
129129
}
@@ -149,7 +149,7 @@ func (c *ConfigQueryMetricField) Validate() error {
149149
return nil
150150
}
151151

152-
func (c *ConfigQueryMetricField) GetType() (ret string) {
152+
func (c *MetricField) GetType() (ret string) {
153153
ret = strings.ToLower(c.Type)
154154

155155
if ret == "" {
@@ -159,7 +159,7 @@ func (c *ConfigQueryMetricField) GetType() (ret string) {
159159
return
160160
}
161161

162-
func (c *ConfigQueryMetricFieldFilter) Validate() error {
162+
func (c *MetricFieldFilter) Validate() error {
163163
if c.Type == "" {
164164
return errors.New("no type name set")
165165
}
@@ -180,7 +180,7 @@ func (c *ConfigQueryMetricFieldFilter) Validate() error {
180180
return nil
181181
}
182182

183-
func (m *ConfigQueryMetric) IsExpand(field string) bool {
183+
func (m *Metric) IsExpand(field string) bool {
184184
for _, fieldConfig := range m.Fields {
185185
if fieldConfig.Name == field {
186186
if fieldConfig.IsExpand() {
@@ -193,48 +193,48 @@ func (m *ConfigQueryMetric) IsExpand(field string) bool {
193193
return false
194194
}
195195

196-
func (m *ConfigQueryMetric) GetFieldConfigMap() (list map[string][]ConfigQueryMetricField) {
197-
list = map[string][]ConfigQueryMetricField{}
196+
func (m *Metric) GetFieldConfigMap() (list map[string][]MetricField) {
197+
list = map[string][]MetricField{}
198198

199199
for _, field := range m.Fields {
200200
if _, ok := list[field.Name]; !ok {
201-
list[field.Name] = []ConfigQueryMetricField{}
201+
list[field.Name] = []MetricField{}
202202
}
203203
list[field.GetSourceField()] = append(list[field.GetSourceField()], field)
204204
}
205205

206206
return
207207
}
208208

209-
func (f *ConfigQueryMetricField) GetSourceField() (ret string) {
209+
func (f *MetricField) GetSourceField() (ret string) {
210210
ret = f.Source
211211
if ret == "" {
212212
ret = f.Name
213213
}
214214
return
215215
}
216216

217-
func (f *ConfigQueryMetricField) IsExpand() bool {
217+
func (f *MetricField) IsExpand() bool {
218218
return f.Type == MetricFieldTypeExpand || f.Expand != nil
219219
}
220220

221-
func (f *ConfigQueryMetricField) IsSourceField() bool {
221+
func (f *MetricField) IsSourceField() bool {
222222
return f.Source != ""
223223
}
224224

225-
func (f *ConfigQueryMetricField) IsTypeIgnore() bool {
225+
func (f *MetricField) IsTypeIgnore() bool {
226226
return f.GetType() == MetricFieldTypeIgnore
227227
}
228228

229-
func (f *ConfigQueryMetricField) IsTypeId() bool {
229+
func (f *MetricField) IsTypeId() bool {
230230
return f.GetType() == MetricFieldTypeId
231231
}
232232

233-
func (f *ConfigQueryMetricField) IsTypeValue() bool {
233+
func (f *MetricField) IsTypeValue() bool {
234234
return f.GetType() == MetricFieldTypeValue
235235
}
236236

237-
func (f *ConfigQueryMetricField) GetTargetFieldName(sourceName string) (ret string) {
237+
func (f *MetricField) GetTargetFieldName(sourceName string) (ret string) {
238238
ret = sourceName
239239
if f.Target != "" {
240240
ret = f.Target
@@ -244,7 +244,7 @@ func (f *ConfigQueryMetricField) GetTargetFieldName(sourceName string) (ret stri
244244
return
245245
}
246246

247-
func (f *ConfigQueryMetricField) TransformString(value string) (ret string) {
247+
func (f *MetricField) TransformString(value string) (ret string) {
248248
ret = value
249249

250250
switch f.Type {
@@ -282,13 +282,13 @@ func (f *ConfigQueryMetricField) TransformString(value string) (ret string) {
282282
return
283283
}
284284

285-
func (f *ConfigQueryMetricField) TransformFloat64(value float64) (ret string) {
285+
func (f *MetricField) TransformFloat64(value float64) (ret string) {
286286
ret = fmt.Sprintf("%v", value)
287287
ret = f.TransformString(ret)
288288
return
289289
}
290290

291-
func (f *ConfigQueryMetricField) TransformBool(value bool) (ret string) {
291+
func (f *MetricField) TransformBool(value bool) (ret string) {
292292
if value {
293293
ret = "true"
294294
} else {
@@ -298,8 +298,8 @@ func (f *ConfigQueryMetricField) TransformBool(value bool) (ret string) {
298298
return
299299
}
300300

301-
func (f *ConfigQueryMetricFieldFilter) UnmarshalJSON(c []byte) error {
302-
var multi ConfigQueryMetricFieldFilterParser
301+
func (f *MetricFieldFilter) UnmarshalJSON(c []byte) error {
302+
var multi MetricFieldFilterParser
303303
err := json.Unmarshal(c, &multi)
304304
if err != nil {
305305
var single string

prometheus/kusto/parse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
)
66

7-
func BuildPrometheusMetricList(name string, metricConfig ConfigQueryMetric, row map[string]interface{}) (list map[string][]MetricRow) {
7+
func BuildPrometheusMetricList(name string, metricConfig Metric, row map[string]interface{}) (list map[string][]MetricRow) {
88
list = map[string][]MetricRow{}
99
idFieldList := map[string]string{}
1010

@@ -104,7 +104,7 @@ func BuildPrometheusMetricList(name string, metricConfig ConfigQueryMetric, row
104104
fieldConfig.Metric = fmt.Sprintf("%s_%s", name, fieldName)
105105
}
106106

107-
subMetricConfig := ConfigQueryMetric{}
107+
subMetricConfig := Metric{}
108108
if fieldConfig.Expand != nil {
109109
subMetricConfig = *fieldConfig.Expand
110110
}

prometheus/kusto/parse_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ defaultField:
6565
type: ignore
6666
`)
6767

68-
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.ConfigQueryMetric, resultRow)
68+
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.Metric, resultRow)
6969

7070
metricTestSuite := testingMetricResult{t: t, list: metricList}
7171
metricTestSuite.assertMetricNames(2)
@@ -129,7 +129,7 @@ defaultField:
129129
type: ignore
130130
`)
131131

132-
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.ConfigQueryMetric, resultRow)
132+
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.Metric, resultRow)
133133

134134
metricTestSuite := testingMetricResult{t: t, list: metricList}
135135
metricTestSuite.assertMetricNames(1)
@@ -184,7 +184,7 @@ defaultField:
184184
type: ignore
185185
`)
186186

187-
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.ConfigQueryMetric, resultRow)
187+
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.Metric, resultRow)
188188

189189
metricTestSuite := testingMetricResult{t: t, list: metricList}
190190
metricTestSuite.assertMetricNames(2)
@@ -364,7 +364,7 @@ defaultField:
364364
foo, _ := json.Marshal(queryConfig)
365365
fmt.Println(string(foo))
366366

367-
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.ConfigQueryMetric, resultRow)
367+
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.Metric, resultRow)
368368

369369
metricTestSuite := testingMetricResult{t: t, list: metricList}
370370
metricTestSuite.assertMetricNames(8)
@@ -472,7 +472,7 @@ defaultField:
472472
type: ignore
473473
`)
474474

475-
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.ConfigQueryMetric, resultRow)
475+
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.Metric, resultRow)
476476

477477
metricTestSuite := testingMetricResult{t: t, list: metricList}
478478
metricTestSuite.assertMetricNames(1)
@@ -532,7 +532,7 @@ defaultField:
532532
type: ignore
533533
`)
534534

535-
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.ConfigQueryMetric, resultRow)
535+
metricList := BuildPrometheusMetricList(queryConfig.Metric, *queryConfig.Metric, resultRow)
536536

537537
metricTestSuite := testingMetricResult{t: t, list: metricList}
538538
metricTestSuite.assertMetricNames(2)
@@ -571,9 +571,9 @@ func parseResourceGraphJsonToResultRow(t *testing.T, data string) map[string]int
571571
return ret
572572
}
573573

574-
func parseMetricConfig(t *testing.T, data string) ConfigQuery {
574+
func parseMetricConfig(t *testing.T, data string) Query {
575575
t.Helper()
576-
ret := ConfigQuery{}
576+
ret := Query{}
577577
if err := yaml.UnmarshalStrict([]byte(data), &ret); err != nil {
578578
t.Fatalf(`unable to unmarshal query configuration yaml: %v`, err)
579579
}

prometheus/kusto/process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func convertSubMetricInterfaceToArray(val interface{}) []interface{} {
1717
return ret
1818
}
1919

20-
func processFieldAndAddToMetric(fieldName string, value interface{}, fieldConfig ConfigQueryMetricField, metric *MetricRow) {
20+
func processFieldAndAddToMetric(fieldName string, value interface{}, fieldConfig MetricField, metric *MetricRow) {
2121
labelName := fieldConfig.GetTargetFieldName(fieldName)
2222

2323
// upgrade to 64bit

0 commit comments

Comments
 (0)