-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from ondat/ctrl-216
Ctrl-216 - Allow to disable metrics collectors
- Loading branch information
Showing
14 changed files
with
237 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ | |
!go.mod | ||
!go.sum | ||
!index.html | ||
# ignore local GOPATH=$(pwd)/.go/ | ||
.go/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Copyright 2022 Ondat. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package v1 | ||
|
||
const ( | ||
// MetricsExporterConfigFileName is a mandatory key in the data field of the | ||
// ConfigMap/storage-metrics-exporter. The associated value must be a valid MetricsExporterConfig | ||
// serialized as YAML. | ||
MetricsExporterConfigFileName = "config.yaml" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright 2022 Ondat. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package v1 | ||
|
||
func (c *MetricsExporterConfig) Default() *MetricsExporterConfig { | ||
if c.LogLevel == "" { | ||
c.LogLevel = "info" | ||
} | ||
if c.Timeout == 0 { | ||
c.Timeout = 10 | ||
} | ||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
|
||
configondatv1 "github.com/ondat/metrics-exporter/api/config.storageos.com/v1" | ||
) | ||
|
||
func TestGetEnabledMetricsCollectors(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
disable []configondatv1.MetricsExporterCollector | ||
expectedEnabled []string | ||
}{ | ||
{ | ||
name: "all enabled", | ||
disable: nil, | ||
expectedEnabled: []string{ | ||
"diskstats", | ||
"filesystem", | ||
}, | ||
}, | ||
|
||
{ | ||
name: "disable filesystem", | ||
disable: []configondatv1.MetricsExporterCollector{configondatv1.MetricsExporterCollectorFileSystem}, | ||
expectedEnabled: []string{ | ||
"diskstats", | ||
}, | ||
}, | ||
|
||
{ | ||
name: "disable diskstats", | ||
disable: []configondatv1.MetricsExporterCollector{configondatv1.MetricsExporterCollectorDiskStats}, | ||
expectedEnabled: []string{ | ||
"filesystem", | ||
}, | ||
}, | ||
|
||
{ | ||
name: "disable both", | ||
disable: []configondatv1.MetricsExporterCollector{ | ||
configondatv1.MetricsExporterCollectorFileSystem, | ||
configondatv1.MetricsExporterCollectorDiskStats, | ||
}, | ||
expectedEnabled: []string{}, | ||
}, | ||
|
||
{ | ||
name: "disable both - reversed", | ||
disable: []configondatv1.MetricsExporterCollector{ | ||
configondatv1.MetricsExporterCollectorDiskStats, | ||
configondatv1.MetricsExporterCollectorFileSystem, | ||
}, | ||
expectedEnabled: []string{}, | ||
}, | ||
|
||
{ | ||
name: "ignore bad value", | ||
disable: []configondatv1.MetricsExporterCollector{ | ||
configondatv1.MetricsExporterCollector("bad"), | ||
configondatv1.MetricsExporterCollectorFileSystem, | ||
}, | ||
expectedEnabled: []string{ | ||
"diskstats", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
var tt = tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
loggerConfig := zap.NewProductionConfig() | ||
logger, _ := loggerConfig.Build() | ||
log := logger.Sugar() | ||
|
||
collectors := GetEnabledMetricsCollectors(log, tt.disable) | ||
names := make([]string, 0, len(collectors)) | ||
for _, c := range collectors { | ||
names = append(names, c.Name()) | ||
} | ||
require.ElementsMatch(t, tt.expectedEnabled, names) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.