@@ -34,29 +34,29 @@ var replaceVariableRegexp = regexp.MustCompile(`\$\{[a-zA-Z0-9_:]+}`)
34
34
type Database interface {
35
35
GetMetric (name string ) * v1.Metric
36
36
ListMetrics () (map [string ]* v1.Metric , error )
37
- ListInvalidMetrics () (map [string ]* v1.InvalidMetric , error )
37
+ ListPartialMetrics () (map [string ]* v1.PartialMetric , error )
38
38
ListPendingUsage () map [string ]* v1.MetricUsage
39
39
EnqueueMetricList (metrics []string )
40
- EnqueueInvalidMetricsUsage (usages map [string ]* v1.MetricUsage )
40
+ EnqueuePartialMetricsUsage (usages map [string ]* v1.MetricUsage )
41
41
EnqueueUsage (usages map [string ]* v1.MetricUsage )
42
42
EnqueueLabels (labels map [string ][]string )
43
43
}
44
44
45
45
func New (cfg config.Database ) Database {
46
46
d := & db {
47
47
metrics : make (map [string ]* v1.Metric ),
48
- invalidMetrics : make (map [string ]* v1.InvalidMetric ),
48
+ partialMetrics : make (map [string ]* v1.PartialMetric ),
49
49
usage : make (map [string ]* v1.MetricUsage ),
50
50
usageQueue : make (chan map [string ]* v1.MetricUsage , 250 ),
51
- invalidMetricsUsageQueue : make (chan map [string ]* v1.MetricUsage , 250 ),
51
+ partialMetricsUsageQueue : make (chan map [string ]* v1.MetricUsage , 250 ),
52
52
labelsQueue : make (chan map [string ][]string , 250 ),
53
53
metricsQueue : make (chan []string , 10 ),
54
54
path : cfg .Path ,
55
55
}
56
56
57
57
go d .watchUsageQueue ()
58
58
go d .watchMetricsQueue ()
59
- go d .watchInvalidMetricsUsageQueue ()
59
+ go d .watchPartialMetricsUsageQueue ()
60
60
go d .watchLabelsQueue ()
61
61
if ! * cfg .InMemory {
62
62
if err := d .readMetricsInJSONFile (); err != nil {
@@ -72,8 +72,8 @@ type db struct {
72
72
// metrics is the list of metric name (as a key) associated to their usage based on the different collector activated.
73
73
// This struct is our "database".
74
74
metrics map [string ]* v1.Metric
75
- // invalidMetrics is the list of metric name that likely contains a variable or a regexp and as such cannot be a valid metric name.
76
- invalidMetrics map [string ]* v1.InvalidMetric
75
+ // partialMetrics is the list of metric name that likely contains a variable or a regexp and as such cannot be a valid metric name.
76
+ partialMetrics map [string ]* v1.PartialMetric
77
77
// usage is a buffer in case the metric name has not yet been collected
78
78
usage map [string ]* v1.MetricUsage
79
79
// metricsQueue is the channel that should be used to send and receive the list of metric name to keep in memory.
@@ -87,10 +87,10 @@ type db struct {
87
87
// There will be no other way to write in it.
88
88
// Doing that allows us to accept more HTTP requests to write data and to delay the actual writing.
89
89
usageQueue chan map [string ]* v1.MetricUsage
90
- // invalidMetricsUsageQueue is the way to send the usage per metric that is not valid to write in the database.
90
+ // partialMetricsUsageQueue is the way to send the usage per metric that is not valid to write in the database.
91
91
// There will be no other way to write in it.
92
92
// Doing that allows us to accept more HTTP requests to write data and to delay the actual writing.
93
- invalidMetricsUsageQueue chan map [string ]* v1.MetricUsage
93
+ partialMetricsUsageQueue chan map [string ]* v1.MetricUsage
94
94
// path is the path to the JSON file where metrics is flushed periodically
95
95
// It is empty if the database is purely in memory.
96
96
path string
@@ -102,7 +102,7 @@ type db struct {
102
102
// 2. Read the file directly when a read query is coming
103
103
// Like that we have two different ways to read and write the data.
104
104
metricsMutex sync.Mutex
105
- invalidMetricsUsageMutex sync.Mutex
105
+ partialMetricsUsageMutex sync.Mutex
106
106
}
107
107
108
108
func (d * db ) GetMetric (name string ) * v1.Metric {
@@ -117,10 +117,10 @@ func (d *db) ListMetrics() (map[string]*v1.Metric, error) {
117
117
return deep .Copy (d .metrics )
118
118
}
119
119
120
- func (d * db ) ListInvalidMetrics () (map [string ]* v1.InvalidMetric , error ) {
121
- d .invalidMetricsUsageMutex .Lock ()
122
- defer d .invalidMetricsUsageMutex .Unlock ()
123
- return deep .Copy (d .invalidMetrics )
120
+ func (d * db ) ListPartialMetrics () (map [string ]* v1.PartialMetric , error ) {
121
+ d .partialMetricsUsageMutex .Lock ()
122
+ defer d .partialMetricsUsageMutex .Unlock ()
123
+ return deep .Copy (d .partialMetrics )
124
124
}
125
125
126
126
func (d * db ) EnqueueMetricList (metrics []string ) {
@@ -137,8 +137,8 @@ func (d *db) EnqueueUsage(usages map[string]*v1.MetricUsage) {
137
137
d .usageQueue <- usages
138
138
}
139
139
140
- func (d * db ) EnqueueInvalidMetricsUsage (usages map [string ]* v1.MetricUsage ) {
141
- d .invalidMetricsUsageQueue <- usages
140
+ func (d * db ) EnqueuePartialMetricsUsage (usages map [string ]* v1.MetricUsage ) {
141
+ d .partialMetricsUsageQueue <- usages
142
142
}
143
143
144
144
func (d * db ) EnqueueLabels (labels map [string ][]string ) {
@@ -167,22 +167,22 @@ func (d *db) watchMetricsQueue() {
167
167
}
168
168
}
169
169
170
- func (d * db ) watchInvalidMetricsUsageQueue () {
171
- for data := range d .invalidMetricsUsageQueue {
172
- d .invalidMetricsUsageMutex .Lock ()
170
+ func (d * db ) watchPartialMetricsUsageQueue () {
171
+ for data := range d .partialMetricsUsageQueue {
172
+ d .partialMetricsUsageMutex .Lock ()
173
173
for metricName , usage := range data {
174
- if _ , ok := d .invalidMetrics [metricName ]; ! ok {
175
- re , matchingMetrics := d .matchInvalidMetric (metricName )
176
- d .invalidMetrics [metricName ] = & v1.InvalidMetric {
174
+ if _ , ok := d .partialMetrics [metricName ]; ! ok {
175
+ re , matchingMetrics := d .matchPartialMetric (metricName )
176
+ d .partialMetrics [metricName ] = & v1.PartialMetric {
177
177
Usage : usage ,
178
178
MatchingMetrics : matchingMetrics ,
179
179
MatchingRegexp : re ,
180
180
}
181
181
} else {
182
- d .invalidMetrics [metricName ].Usage = v1 .MergeUsage (d .invalidMetrics [metricName ].Usage , usage )
182
+ d .partialMetrics [metricName ].Usage = v1 .MergeUsage (d .partialMetrics [metricName ].Usage , usage )
183
183
}
184
184
}
185
- d .invalidMetricsUsageMutex .Unlock ()
185
+ d .partialMetricsUsageMutex .Unlock ()
186
186
}
187
187
}
188
188
@@ -253,10 +253,10 @@ func (d *db) readMetricsInJSONFile() error {
253
253
return json .Unmarshal (data , & d .metrics )
254
254
}
255
255
256
- func (d * db ) matchInvalidMetric ( invalidMetric string ) (* common.Regexp , v1.Set [string ]) {
257
- re , err := generateRegexp (invalidMetric )
256
+ func (d * db ) matchPartialMetric ( partialMetric string ) (* common.Regexp , v1.Set [string ]) {
257
+ re , err := generateRegexp (partialMetric )
258
258
if err != nil {
259
- logrus .WithError (err ).Errorf ("unable to compile the invalid metric name %q into a regexp" , invalidMetric )
259
+ logrus .WithError (err ).Errorf ("unable to compile the partial metric name %q into a regexp" , partialMetric )
260
260
return nil , nil
261
261
}
262
262
if re == nil {
@@ -274,45 +274,45 @@ func (d *db) matchInvalidMetric(invalidMetric string) (*common.Regexp, v1.Set[st
274
274
}
275
275
276
276
func (d * db ) matchValidMetric (validMetric string ) {
277
- d .invalidMetricsUsageMutex .Lock ()
278
- defer d .invalidMetricsUsageMutex .Unlock ()
279
- for metricName , invalidMetric := range d .invalidMetrics {
280
- re := invalidMetric .MatchingRegexp
277
+ d .partialMetricsUsageMutex .Lock ()
278
+ defer d .partialMetricsUsageMutex .Unlock ()
279
+ for metricName , partialMetric := range d .partialMetrics {
280
+ re := partialMetric .MatchingRegexp
281
281
if re == nil {
282
282
var err error
283
283
re , err = generateRegexp (metricName )
284
284
if err != nil {
285
- logrus .WithError (err ).Errorf ("unable to compile the invalid metric name %q into a regexp" , metricName )
285
+ logrus .WithError (err ).Errorf ("unable to compile the partial metric name %q into a regexp" , metricName )
286
286
continue
287
287
}
288
- invalidMetric .MatchingRegexp = re
288
+ partialMetric .MatchingRegexp = re
289
289
if re == nil {
290
290
continue
291
291
}
292
292
}
293
293
if re .MatchString (validMetric ) {
294
- matchingMetrics := invalidMetric .MatchingMetrics
294
+ matchingMetrics := partialMetric .MatchingMetrics
295
295
if matchingMetrics == nil {
296
296
matchingMetrics = v1 .NewSet [string ]()
297
- invalidMetric .MatchingMetrics = matchingMetrics
297
+ partialMetric .MatchingMetrics = matchingMetrics
298
298
}
299
299
matchingMetrics .Add (validMetric )
300
300
}
301
301
}
302
302
}
303
303
304
- // GenerateRegexp is taking an invalid metric name,
304
+ // GenerateRegexp is taking an partial metric name,
305
305
// will replace every variable by a pattern and then returning a regepx if the final string is not just equal to .*.
306
- func generateRegexp (invalidMetricName string ) (* common.Regexp , error ) {
306
+ func generateRegexp (partialMetricName string ) (* common.Regexp , error ) {
307
307
// The first step is to replace every variable by a single special char.
308
308
// We are using a special single char because it will be easier to find if these chars are continuous
309
309
// or if there are other characters in between.
310
- s := replaceVariableRegexp .ReplaceAllString (invalidMetricName , "#" )
310
+ s := replaceVariableRegexp .ReplaceAllString (partialMetricName , "#" )
311
311
s = strings .ReplaceAll (s , ".+" , "#" )
312
312
s = strings .ReplaceAll (s , ".*" , "#" )
313
313
if s == "#" || len (s ) == 0 {
314
314
// This means the metric name is just a variable and as such can match all metric.
315
- // So it's basically impossible to know what this invalid metric name is covering/matching.
315
+ // So it's basically impossible to know what this partial metric name is covering/matching.
316
316
return nil , nil
317
317
}
318
318
// The next step is to contact every continuous special char '#' to a single one.
0 commit comments