-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Xuewei Zhang
committed
Sep 12, 2019
1 parent
9e789b5
commit 7f590c0
Showing
17 changed files
with
705 additions
and
23 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors All rights reserved. | ||
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 exporterplugins | ||
|
||
// This file is necessary to make sure the exporterplugins package non-empty | ||
// under any build tags. |
25 changes: 25 additions & 0 deletions
25
cmd/nodeproblemdetector/exporterplugins/stackdriver_exporter_plugin.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// +build !disable_stackdriver_exporter | ||
|
||
/* | ||
Copyright 2019 The Kubernetes Authors All rights reserved. | ||
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 exporterplugins | ||
|
||
import ( | ||
_ "k8s.io/node-problem-detector/pkg/exporters/stackdriver" | ||
) | ||
|
||
// The stackdriver plugin takes about 6MB in the NPD binary. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"apiEndpoint": "monitoring.googleapis.com:443", | ||
"exportPeriod": "60s", | ||
"metadataFetchTimeout": "600s", | ||
"metadataFetchInterval": "10s", | ||
"panicOnMetadataFetchFailure": false, | ||
"customMetricPrefix": "" | ||
} |
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,63 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors All rights reserved. | ||
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 exporters | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/node-problem-detector/pkg/types" | ||
) | ||
|
||
var ( | ||
handlers = make(map[types.ExporterType]types.ExporterHandler) | ||
) | ||
|
||
// Register registers a exporter factory method, which will be used to create the exporter. | ||
func Register(exporterType types.ExporterType, handler types.ExporterHandler) { | ||
handlers[exporterType] = handler | ||
} | ||
|
||
// GetExporterNames retrieves all available exporter types. | ||
func GetExporterNames() []types.ExporterType { | ||
exporterTypes := []types.ExporterType{} | ||
for exporterType := range handlers { | ||
exporterTypes = append(exporterTypes, exporterType) | ||
} | ||
return exporterTypes | ||
} | ||
|
||
// GetExporterHandlerOrDie retrieves the ExporterHandler for a specific type of exporter, panic if error occurs.. | ||
func GetExporterHandlerOrDie(exporterType types.ExporterType) types.ExporterHandler { | ||
handler, ok := handlers[exporterType] | ||
if !ok { | ||
panic(fmt.Sprintf("Exporter handler for %v does not exist", exporterType)) | ||
} | ||
return handler | ||
} | ||
|
||
// NewExporters creates all exporters based on the configurations initialized. | ||
func NewExporters() []types.Exporter { | ||
exporters := []types.Exporter{} | ||
for _, handler := range handlers { | ||
exporter := handler.CreateExporterOrDie(handler.Options) | ||
if exporter == nil { | ||
continue | ||
} | ||
exporters = append(exporters, exporter) | ||
} | ||
return exporters | ||
} |
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,69 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors All rights reserved. | ||
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 exporters | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"k8s.io/node-problem-detector/pkg/types" | ||
) | ||
|
||
func TestRegistration(t *testing.T) { | ||
fooExporterFactory := func(types.CommandLineOptions) types.Exporter { | ||
return nil | ||
} | ||
fooExporterHandler := types.ExporterHandler{ | ||
CreateExporterOrDie: fooExporterFactory, | ||
Options: nil, | ||
} | ||
|
||
barExporterFactory := func(types.CommandLineOptions) types.Exporter { | ||
return nil | ||
} | ||
barExporterHandler := types.ExporterHandler{ | ||
CreateExporterOrDie: barExporterFactory, | ||
Options: nil, | ||
} | ||
|
||
Register("foo", fooExporterHandler) | ||
Register("bar", barExporterHandler) | ||
|
||
expectedExporterNames := []types.ExporterType{"foo", "bar"} | ||
exporterNames := GetExporterNames() | ||
assert.ElementsMatch(t, expectedExporterNames, exporterNames) | ||
|
||
handlers = make(map[types.ExporterType]types.ExporterHandler) | ||
} | ||
|
||
func TestGetExporterHandlerOrDie(t *testing.T) { | ||
fooExporterFactory := func(types.CommandLineOptions) types.Exporter { | ||
return nil | ||
} | ||
fooExporterHandler := types.ExporterHandler{ | ||
CreateExporterOrDie: fooExporterFactory, | ||
Options: nil, | ||
} | ||
|
||
Register("foo", fooExporterHandler) | ||
|
||
assert.NotPanics(t, func() { GetExporterHandlerOrDie("foo") }) | ||
assert.Panics(t, func() { GetExporterHandlerOrDie("bar") }) | ||
|
||
handlers = make(map[types.ExporterType]types.ExporterHandler) | ||
} |
Oops, something went wrong.