1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-28 18:57:10 +00:00

refactor sources to source pkg

This commit is contained in:
Andy Xie 2017-09-06 10:48:10 +08:00 committed by Connor Doyle
parent b34ad30ad6
commit 0ea8ff631e
11 changed files with 481 additions and 153 deletions

238
glide.lock generated
View file

@ -1,31 +1,257 @@
hash: f43fa3ac02ea7f1a8669981c2244722bf001e9237002d659d0c0a508d9a067c9
updated: 2016-11-11T10:29:40.757214999-08:00
updated: 2017-08-25T19:17:17.781888283+08:00
imports:
- name: cloud.google.com/go
version: 3b1ae45394a234c385be014e9a488f2bb6eef821
subpackages:
- compute/metadata
- internal
- name: github.com/blang/semver
version: 31b736133b98f26d5e078ec9eb591666edfd091f
- name: github.com/coreos/go-oidc
version: 5644a2f50e2d2d5ba0b474bc5bc55fea1925936d
subpackages:
- http
- jose
- key
- oauth2
- oidc
- name: github.com/coreos/pkg
version: fa29b1d70f0beaddd4c7021607cc3c3be8ce94b8
subpackages:
- health
- httputil
- timeutil
- name: github.com/davecgh/go-spew
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
subpackages:
- spew
- name: github.com/docker/distribution
version: cd27f179f2c10c5d300e6d09025b538c475b0d51
subpackages:
- digest
- reference
- name: github.com/docopt/docopt-go
version: 784ddc588536785e7299f7272f39101f7faccc3f
- name: github.com/emicklei/go-restful
version: 89ef8af493ab468a45a42bb0d89a06fccdd2fb22
subpackages:
- log
- swagger
- name: github.com/ghodss/yaml
version: 73d445a93680fa1a78ae23a5839bad48f32ba1ee
- name: github.com/go-openapi/jsonpointer
version: 46af16f9f7b149af66e5d1bd010e3574dc06de98
- name: github.com/go-openapi/jsonreference
version: 13c6e3589ad90f49bd3e3bbe2c2cb3d7a4142272
- name: github.com/go-openapi/spec
version: 6aced65f8501fe1217321abf0749d354824ba2ff
- name: github.com/go-openapi/swag
version: 1d0bd113de87027671077d3c71eb3ac5d7dbba72
- name: github.com/gogo/protobuf
version: e18d7aa8f8c624c915db340349aad4c49b10d173
subpackages:
- proto
- sortkeys
- name: github.com/golang/glog
version: 44145f04b68cf362d9c4df2182967c2275eaefed
- name: github.com/golang/protobuf
version: 8616e8ee5e20a1704615e6c8d7afcdac06087a67
subpackages:
- proto
- name: github.com/google/gofuzz
version: bbcb9da2d746f8bdbd6a936686a0a6067ada0ec5
- name: github.com/jonboulle/clockwork
version: 72f9bd7c4e0c2a40055ab3d0f09654f730cce982
- name: github.com/juju/ratelimit
version: 77ed1c8a01217656d2080ad51981f6e99adaa177
- name: github.com/klauspost/cpuid
version: 09cded8978dc9e80714c4d85b0322337b0a1e5e0
version: ae7887de9fa5d2db4eaa8174a7eff2c1ac00f2da
- name: github.com/mailru/easyjson
version: d5b7844b561a7bc640052f1b935f7b800330d7e0
subpackages:
- buffer
- jlexer
- jwriter
- name: github.com/pborman/uuid
version: ca53cad383cad2479bbba7f7a1a05797ec1386e4
- name: github.com/pmezard/go-difflib
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
subpackages:
- difflib
- name: github.com/PuerkitoBio/purell
version: 8a290539e2e8629dbc4e6bad948158f790ec31f4
- name: github.com/PuerkitoBio/urlesc
version: 5bd2802263f21d8788851d5305584c82a5c75d7e
- name: github.com/spf13/pflag
version: 5ccb023bc27df288a957c5e994cd44fd19619465
- name: github.com/stretchr/objx
version: cbeaeb16a013161a98496fad62933b1d21786672
- name: github.com/stretchr/testify
version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0
subpackages:
- mock
- assert
- mock
- name: github.com/ugorji/go
version: f1f1a805ed361a0e078bb537e4ea78cd37dcf065
subpackages:
- codec
- name: golang.org/x/net
version: e90d6d0afc4c315a0d87a568ae68577cc15149a0
subpackages:
- context
- context/ctxhttp
- http2
- http2/hpack
- idna
- lex/httplex
- name: golang.org/x/oauth2
version: 3c3a985cb79f52a3190fbc056984415ca6763d01
subpackages:
- google
- internal
- jws
- jwt
- name: golang.org/x/text
version: 2910a502d2bf9e43193af9d68ca516529614eed3
subpackages:
- cases
- internal/tag
- language
- runes
- secure/bidirule
- secure/precis
- transform
- unicode/bidi
- unicode/norm
- width
- name: google.golang.org/appengine
version: 4f7eeb5305a4ba1966344836ba4af9996b7b4e05
subpackages:
- internal
- internal/app_identity
- internal/base
- internal/datastore
- internal/log
- internal/modules
- internal/remote_api
- internal/urlfetch
- urlfetch
- name: gopkg.in/inf.v0
version: 3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4
- name: gopkg.in/yaml.v2
version: 53feefa2559fb8dfa8d81baad31be332c97d6c77
- name: k8s.io/client-go
version: b22087a53becae45931ed72d5e0f12e0031d771a
version: e121606b0d09b2e1c467183ee46217fa85a6b672
subpackages:
- 1.4/kubernetes
- 1.4/pkg/api
- 1.4/rest
- discovery
- kubernetes
- kubernetes/typed/apps/v1beta1
- kubernetes/typed/authentication/v1beta1
- kubernetes/typed/authorization/v1beta1
- kubernetes/typed/autoscaling/v1
- kubernetes/typed/batch/v1
- kubernetes/typed/batch/v2alpha1
- kubernetes/typed/certificates/v1alpha1
- kubernetes/typed/core/v1
- kubernetes/typed/extensions/v1beta1
- kubernetes/typed/policy/v1beta1
- kubernetes/typed/rbac/v1alpha1
- kubernetes/typed/storage/v1beta1
- pkg/api
- pkg/api/errors
- pkg/api/install
- pkg/api/meta
- pkg/api/meta/metatypes
- pkg/api/resource
- pkg/api/unversioned
- pkg/api/v1
- pkg/api/validation/path
- pkg/apimachinery
- pkg/apimachinery/announced
- pkg/apimachinery/registered
- pkg/apis/apps
- pkg/apis/apps/install
- pkg/apis/apps/v1beta1
- pkg/apis/authentication
- pkg/apis/authentication/install
- pkg/apis/authentication/v1beta1
- pkg/apis/authorization
- pkg/apis/authorization/install
- pkg/apis/authorization/v1beta1
- pkg/apis/autoscaling
- pkg/apis/autoscaling/install
- pkg/apis/autoscaling/v1
- pkg/apis/batch
- pkg/apis/batch/install
- pkg/apis/batch/v1
- pkg/apis/batch/v2alpha1
- pkg/apis/certificates
- pkg/apis/certificates/install
- pkg/apis/certificates/v1alpha1
- pkg/apis/extensions
- pkg/apis/extensions/install
- pkg/apis/extensions/v1beta1
- pkg/apis/policy
- pkg/apis/policy/install
- pkg/apis/policy/v1beta1
- pkg/apis/rbac
- pkg/apis/rbac/install
- pkg/apis/rbac/v1alpha1
- pkg/apis/storage
- pkg/apis/storage/install
- pkg/apis/storage/v1beta1
- pkg/auth/user
- pkg/conversion
- pkg/conversion/queryparams
- pkg/fields
- pkg/genericapiserver/openapi/common
- pkg/labels
- pkg/runtime
- pkg/runtime/serializer
- pkg/runtime/serializer/json
- pkg/runtime/serializer/protobuf
- pkg/runtime/serializer/recognizer
- pkg/runtime/serializer/streaming
- pkg/runtime/serializer/versioning
- pkg/selection
- pkg/third_party/forked/golang/reflect
- pkg/third_party/forked/golang/template
- pkg/types
- pkg/util
- pkg/util/cert
- pkg/util/clock
- pkg/util/errors
- pkg/util/flowcontrol
- pkg/util/framer
- pkg/util/integer
- pkg/util/intstr
- pkg/util/json
- pkg/util/jsonpath
- pkg/util/labels
- pkg/util/net
- pkg/util/parsers
- pkg/util/rand
- pkg/util/runtime
- pkg/util/sets
- pkg/util/uuid
- pkg/util/validation
- pkg/util/validation/field
- pkg/util/wait
- pkg/util/yaml
- pkg/version
- pkg/watch
- pkg/watch/versioned
- plugin/pkg/client/auth
- plugin/pkg/client/auth/gcp
- plugin/pkg/client/auth/oidc
- rest
- tools/clientcmd/api
- tools/metrics
- transport
testImports:
- name: github.com/gopherjs/gopherjs
version: e34a5cd6a1bc7c4fde759f2d3039852fc68b5fcc
@ -39,10 +265,10 @@ testImports:
- internal/go-render/render
- internal/oglematchers
- name: github.com/smartystreets/goconvey
version: d4c757aa9afd1e2fc1832aaab209b5794eb336e1
version: 9e8dc3f972df6c8fcc0375ef492c24d0bb204857
subpackages:
- convey
- convey/reporting
- convey/gotest
- convey/reporting
- name: github.com/vektra/errors
version: c64d83aba85aa4392895aadeefabbd24e89f3580

27
main.go
View file

@ -7,10 +7,16 @@ import (
"regexp"
"strings"
"github.com/docopt/docopt-go"
"github.com/kubernetes-incubator/node-feature-discovery/source"
"github.com/kubernetes-incubator/node-feature-discovery/source/cpuid"
"github.com/kubernetes-incubator/node-feature-discovery/source/fake"
"github.com/kubernetes-incubator/node-feature-discovery/source/panic_fake"
"github.com/kubernetes-incubator/node-feature-discovery/source/pstate"
"github.com/kubernetes-incubator/node-feature-discovery/source/rdt"
k8sclient "k8s.io/client-go/kubernetes"
api "k8s.io/client-go/pkg/api/v1"
restclient "k8s.io/client-go/rest"
"github.com/docopt/docopt-go"
)
const (
@ -128,21 +134,22 @@ func argsParse(argv []string) (noPublish bool, sourcesArg []string, whiteListArg
// configureParameters returns all the variables required to perform feature
// discovery based on command line arguments.
func configureParameters(sourcesArg []string, whiteListArg string) (sources []FeatureSource, labelWhiteList *regexp.Regexp, err error) {
func configureParameters(sourcesArg []string, whiteListArg string) (sources []source.FeatureSource, labelWhiteList *regexp.Regexp, err error) {
enabledSources := map[string]struct{}{}
for _, s := range sourcesArg {
enabledSources[strings.TrimSpace(s)] = struct{}{}
}
// Configure feature sources.
allSources := []FeatureSource{
cpuidSource{},
rdtSource{},
pstateSource{},
fakeSource{},
allSources := []source.FeatureSource{
cpuid.Source{},
rdt.Source{},
pstate.Source{},
fake.Source{},
panic_fake.Source{},
}
sources = []FeatureSource{}
sources = []source.FeatureSource{}
for _, s := range allSources {
if _, enabled := enabledSources[s.Name()]; enabled {
sources = append(sources, s)
@ -161,7 +168,7 @@ func configureParameters(sourcesArg []string, whiteListArg string) (sources []Fe
// createFeatureLabels returns the set of feature labels from the enabled
// sources and the whitelist argument.
func createFeatureLabels(sources []FeatureSource, labelWhiteList *regexp.Regexp) (labels Labels) {
func createFeatureLabels(sources []source.FeatureSource, labelWhiteList *regexp.Regexp) (labels Labels) {
labels = Labels{}
// Add the version of this discovery code as a node label
versionLabel := fmt.Sprintf("%s/%s.version", Namespace, ProgramName)
@ -208,7 +215,7 @@ func updateNodeWithFeatureLabels(helper APIHelpers, noPublish bool, labels Label
// getFeatureLabels returns node labels for features discovered by the
// supplied source.
func getFeatureLabels(source FeatureSource) (labels Labels, err error) {
func getFeatureLabels(source source.FeatureSource) (labels Labels, err error) {
defer func() {
if r := recover(); r != nil {
stderrLogger.Printf("panic occurred during discovery of source [%s]: %v", source.Name(), r)

View file

@ -5,6 +5,9 @@ import (
"regexp"
"testing"
"github.com/kubernetes-incubator/node-feature-discovery/source"
"github.com/kubernetes-incubator/node-feature-discovery/source/fake"
"github.com/kubernetes-incubator/node-feature-discovery/source/panic_fake"
. "github.com/smartystreets/goconvey/convey"
"github.com/vektra/errors"
k8sclient "k8s.io/client-go/kubernetes"
@ -20,7 +23,7 @@ func TestDiscoveryWithMockSources(t *testing.T) {
for _, f := range fakeFeatures {
fakeFeatureLabels[fmt.Sprintf("%s-testSource-%s", prefix, f)] = "true"
}
fakeFeatureSource := FeatureSource(mockFeatureSource)
fakeFeatureSource := source.FeatureSource(mockFeatureSource)
Convey("When I successfully get the labels from the mock source", func() {
mockFeatureSource.On("Name").Return(fakeFeatureSourceName)
@ -194,7 +197,7 @@ func TestConfigureParameters(t *testing.T) {
})
Convey("Proper sources are returned", func() {
So(len(sources), ShouldEqual, 1)
So(sources[0], ShouldHaveSameTypeAs, fakeSource{})
So(sources[0], ShouldHaveSameTypeAs, fake.Source{})
So(labelWhiteList, ShouldResemble, emptyRegexp)
})
})
@ -232,8 +235,8 @@ func TestCreateFeatureLabels(t *testing.T) {
Convey("When creating feature labels from the configured sources", t, func() {
Convey("When fake feature source is configured", func() {
emptyLabelWL, _ := regexp.Compile("")
fakeFeatureSource := FeatureSource(new(fakeSource))
sources := []FeatureSource{}
fakeFeatureSource := source.FeatureSource(new(fake.Source))
sources := []source.FeatureSource{}
sources = append(sources, fakeFeatureSource)
labels := createFeatureLabels(sources, emptyLabelWL)
@ -246,8 +249,8 @@ func TestCreateFeatureLabels(t *testing.T) {
})
Convey("When fake feature source is configured with a whitelist that doesn't match", func() {
emptyLabelWL, _ := regexp.Compile(".*rdt.*")
fakeFeatureSource := FeatureSource(new(fakeSource))
sources := []FeatureSource{}
fakeFeatureSource := source.FeatureSource(new(fake.Source))
sources := []source.FeatureSource{}
sources = append(sources, fakeFeatureSource)
labels := createFeatureLabels(sources, emptyLabelWL)
@ -326,7 +329,7 @@ func TestRemoveLabels(t *testing.T) {
func TestGetFeatureLabels(t *testing.T) {
Convey("When I get feature labels and panic occurs during discovery of a feature source", t, func() {
fakePanicFeatureSource := FeatureSource(new(fakePanicSource))
fakePanicFeatureSource := source.FeatureSource(new(panic_fake.Source))
returnedLabels, err := getFeatureLabels(fakePanicFeatureSource)
Convey("No label is returned", func() {

30
source/cpuid/cpuid.go Normal file
View file

@ -0,0 +1,30 @@
/*
Copyright 2017 The Kubernetes Authors.
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 cpuid
import "github.com/klauspost/cpuid"
// Source implements FeatureSource.
type Source struct{}
func (s Source) Name() string { return "cpuid" }
// Discover returns feature names for all the supported CPU features.
func (s Source) Discover() ([]string, error) {
// Get the cpu features as strings
return cpuid.CPU.Features.Strings(), nil
}

31
source/fake/fake.go Normal file
View file

@ -0,0 +1,31 @@
/*
Copyright 2017 The Kubernetes Authors.
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 fake
// Source implements FeatureSource.
type Source struct{}
func (s Source) Name() string { return "fake" }
func (s Source) Discover() ([]string, error) {
features := []string{}
// Adding three fake features.
features = append(features, "fakefeature1", "fakefeature2", "fakefeature3")
return features, nil
}

View file

@ -0,0 +1,26 @@
/*
Copyright 2017 The Kubernetes Authors.
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 panic_fake
// Source implements FeatureSource.
type Source struct{}
func (s Source) Name() string { return "panic_fake" }
func (s Source) Discover() ([]string, error) {
panic("panic fake error")
}

44
source/pstate/pstate.go Normal file
View file

@ -0,0 +1,44 @@
/*
Copyright 2017 The Kubernetes Authors.
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 pstate
import (
"fmt"
"io/ioutil"
)
// Source implements FeatureSource.
type Source struct{}
func (s Source) Name() string { return "pstate" }
// Discover returns feature names for p-state related features such as turbo boost.
func (s Source) Discover() ([]string, error) {
features := []string{}
// Only looking for turbo boost for now...
bytes, err := ioutil.ReadFile("/sys/devices/system/cpu/intel_pstate/no_turbo")
if err != nil {
return nil, fmt.Errorf("can't detect whether turbo boost is enabled: %s", err.Error())
}
if bytes[0] == byte('0') {
// Turbo boost is enabled.
features = append(features, "turbo")
}
return features, nil
}

65
source/rdt/rdt.go Normal file
View file

@ -0,0 +1,65 @@
/*
Copyright 2017 The Kubernetes Authors.
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 rdt
import (
"os/exec"
"path"
"github.com/golang/glog"
)
const (
// RDTBin is the path to RDT detection helpers.
RDTBin = "/go/src/github.com/kubernetes-incubator/node-feature-discovery/rdt-discovery"
)
// Source implements FeatureSource.
type Source struct{}
func (s Source) Name() string { return "rdt" }
// Returns feature names for CMT and CAT if suppported.
func (s Source) Discover() ([]string, error) {
features := []string{}
cmd := exec.Command("bash", "-c", path.Join(RDTBin, "mon-discovery"))
if err := cmd.Run(); err != nil {
glog.Errorf("support for RDT monitoring was not detected: %v", err)
} else {
// RDT monitoring detected.
features = append(features, "RDTMON")
}
cmd = exec.Command("bash", "-c", path.Join(RDTBin, "l3-alloc-discovery"))
if err := cmd.Run(); err != nil {
glog.Errorf("support for RDT L3 allocation was not detected: %v", err)
} else {
// RDT L3 cache allocation detected.
features = append(features, "RDTL3CA")
}
cmd = exec.Command("bash", "-c", path.Join(RDTBin, "l2-alloc-discovery"))
if err := cmd.Run(); err != nil {
glog.Errorf("support for RDT L2 allocation was not detected: %v", err)
} else {
// RDT L2 cache allocation detected.
features = append(features, "RDTL2CA")
}
return features, nil
}

26
source/source.go Normal file
View file

@ -0,0 +1,26 @@
/*
Copyright 2017 The Kubernetes Authors.
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 source
// FeatureSource represents a source of a discovered node feature.
type FeatureSource interface {
// Name returns a friendly name for this source of node feature.
Name() string
// Discover returns discovered features for this node.
Discover() ([]string, error)
}

View file

@ -1,102 +0,0 @@
package main
import (
"fmt"
"io/ioutil"
"os/exec"
"path"
"github.com/klauspost/cpuid"
)
// FeatureSource represents a source of discovered node features.
type FeatureSource interface {
// Returns a friendly name for this source of node features.
Name() string
// Returns discovered features for this node.
Discover() ([]string, error)
}
const (
// RDTBin is the path to RDT detection helpers.
RDTBin = "/go/src/github.com/kubernetes-incubator/node-feature-discovery/rdt-discovery"
)
////////////////////////////////////////////////////////////////////////////////
// CPUID Source
// Implements main.FeatureSource.
type cpuidSource struct{}
func (s cpuidSource) Name() string { return "cpuid" }
// Returns feature names for all the supported CPU features.
func (s cpuidSource) Discover() ([]string, error) {
// Get the cpu features as strings
return cpuid.CPU.Features.Strings(), nil
}
////////////////////////////////////////////////////////////////////////////////
// RDT (Intel Resource Director Technology) Source
// Implements main.FeatureSource.
type rdtSource struct{}
func (s rdtSource) Name() string { return "rdt" }
// Returns feature names for CMT and CAT if suppported.
func (s rdtSource) Discover() ([]string, error) {
features := []string{}
cmd := exec.Command("bash", "-c", path.Join(RDTBin, "mon-discovery"))
if err := cmd.Run(); err != nil {
stderrLogger.Printf("support for RDT monitoring was not detected: %s", err.Error())
} else {
// RDT monitoring detected.
features = append(features, "RDTMON")
}
cmd = exec.Command("bash", "-c", path.Join(RDTBin, "l3-alloc-discovery"))
if err := cmd.Run(); err != nil {
stderrLogger.Printf("support for RDT L3 allocation was not detected: %s", err.Error())
} else {
// RDT L3 cache allocation detected.
features = append(features, "RDTL3CA")
}
cmd = exec.Command("bash", "-c", path.Join(RDTBin, "l2-alloc-discovery"))
if err := cmd.Run(); err != nil {
stderrLogger.Printf("support for RDT L2 allocation was not detected: %s", err.Error())
} else {
// RDT L2 cache allocation detected.
features = append(features, "RDTL2CA")
}
return features, nil
}
////////////////////////////////////////////////////////////////////////////////
// PState Source
// Implements main.FeatureSource.
type pstateSource struct{}
func (s pstateSource) Name() string { return "pstate" }
// Returns feature names for p-state related features such as turbo boost.
func (s pstateSource) Discover() ([]string, error) {
features := []string{}
// Only looking for turbo boost for now...
bytes, err := ioutil.ReadFile("/sys/devices/system/cpu/intel_pstate/no_turbo")
if err != nil {
return nil, fmt.Errorf("can't detect whether turbo boost is enabled: %s", err.Error())
}
if bytes[0] == byte('0') {
// Turbo boost is enabled.
features = append(features, "turbo")
}
return features, nil
}

View file

@ -1,28 +0,0 @@
package main
////////////////////////////////////////////////////////////////////////////////
// Fake Source (used only for testing)
// Implements main.FeatureSource.
type fakeSource struct{}
func (s fakeSource) Name() string { return "fake" }
func (s fakeSource) Discover() ([]string, error) {
features := []string{}
// Adding three fake features.
features = append(features, "fakefeature1", "fakefeature2", "fakefeature3")
return features, nil
}
////////////////////////////////////////////////////////////////////////////////
// Fake Panic Source (used only for testing)
// Implements main.FeatureSource.
type fakePanicSource struct{}
func (s fakePanicSource) Name() string { return "fakepanic" }
func (s fakePanicSource) Discover() ([]string, error) {
panic("fake panic error")
}