-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Update README - Update to go1.18 - Update to k8s v1.24.3 - Reworked vfstats collector - Implemented endpoint unit tests - Add netlink support detection - Add image building to Makefile - Remove deprecated references - Add Mellanox driver to drivers DB - Refactor code to enable testing - Support for NFD SR-IOV feature label - Changes to ensure more uniform Makefile - Implemented initial unit tests - Implemented vfstats package unit tests Co-Authored-By: Eoghan1232 <[email protected]> Co-Authored-By: eoghanlawless <[email protected]> Co-Authored-By: Ipawlikx <[email protected]> Co-Authored-By: nhennigan <[email protected]>
- Loading branch information
1 parent
18d24f7
commit 031d7f9
Showing
17 changed files
with
1,383 additions
and
174 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: "CodeQL" | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
schedule: | ||
- cron: "1 7 * * 5" | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ go ] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v2 | ||
with: | ||
languages: ${{ matrix.language }} | ||
queries: +security-and-quality | ||
|
||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v2 | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v2 | ||
with: | ||
category: "/language:${{ matrix.language }}" |
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 |
---|---|---|
|
@@ -11,17 +11,13 @@ ifdef HTTPS_PROXY | |
DOCKERARGS += --build-arg https_proxy=$(HTTPS_PROXY) | ||
endif | ||
|
||
all: build | ||
all: build docker-build test | ||
|
||
clean: | ||
rm -rf bin | ||
go clean --modcache | ||
|
||
go clean -modcache -testcache | ||
build: | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
go mod tidy | ||
go fmt ./... | ||
golangci-lint run | ||
GO111MODULE=on go build -ldflags "-s -w" -buildmode=pie -o bin/sriov-exporter cmd/sriov-network-metrics-exporter.go | ||
|
||
docker-build: | ||
|
@@ -30,3 +26,19 @@ docker-build: | |
|
||
docker-push: | ||
docker push $(IMAGE_NAME) | ||
|
||
test: | ||
go test ./... -coverprofile cover.out | ||
|
||
test-coverage: | ||
ginkgo -v -r -cover -coverprofile=cover.out --output-dir=. | ||
go tool cover -html=cover.out | ||
|
||
go-lint: | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
go mod tidy | ||
go fmt ./... | ||
golangci-lint run --color always -v ./... | ||
|
||
go-lint-report: | ||
golangci-lint run --color always -v ./... &> golangci-lint.txt |
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,101 @@ | ||
package collectors | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"log" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/gbytes" | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
"sriov-network-metrics-exporter/pkg/utils" | ||
) | ||
|
||
var buffer gbytes.Buffer | ||
|
||
func TestCollectors(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "collectors test suite") | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
utils.EvalSymlinks = evalSymlinks | ||
|
||
logFatal = func(msg string, args ...any) { | ||
log.Printf(msg, args...) | ||
} | ||
|
||
log.SetFlags(0) | ||
}) | ||
|
||
var _ = BeforeEach(func() { | ||
buffer = *gbytes.NewBuffer() | ||
log.SetOutput(&buffer) | ||
}) | ||
|
||
type metric struct { | ||
labels map[string]string | ||
counter float64 | ||
} | ||
|
||
type testCollector struct { | ||
name string | ||
} | ||
|
||
func createTestCollector() prometheus.Collector { | ||
return testCollector{ | ||
name: "collector.test", | ||
} | ||
} | ||
|
||
func (c testCollector) Collect(ch chan<- prometheus.Metric) {} | ||
func (c testCollector) Describe(chan<- *prometheus.Desc) {} | ||
|
||
var _ = DescribeTable("test registering collector", // register | ||
func(name string, enabled bool, collector func() prometheus.Collector) { | ||
register(name, enabled, collector) | ||
|
||
Expect(collectorState).To(HaveKey(name)) | ||
Expect(collectorState[name]).To(Equal(&enabled)) | ||
|
||
Expect(collectorFunctions).To(HaveKey(name)) | ||
// Expect(allCollectors[name]).To(Equal(collector)) // TODO: verify expected collector is returned | ||
|
||
}, | ||
Entry("the correct collector is enabled when default is true", | ||
"test_true", | ||
true, | ||
createTestCollector), | ||
Entry("the correct collector is not enabled when default is false", | ||
"test_false", | ||
false, | ||
createTestCollector), | ||
) | ||
|
||
// TODO: create Enabled unit test | ||
|
||
func assertLogs(logs []string) { | ||
for _, log := range logs { | ||
Eventually(&buffer).WithTimeout(time.Duration(2 * time.Second)).Should(gbytes.Say(log)) | ||
} | ||
} | ||
|
||
// Replaces filepath.EvalSymlinks with an emulated evaluation to work with the in-memory fs. | ||
var evalSymlinks = func(path string) (string, error) { | ||
path = filepath.Join(filepath.Base(filepath.Dir(path)), filepath.Base(path)) | ||
|
||
if stat, err := fs.Stat(devfs, path); err == nil && stat.Mode() == fs.ModeSymlink { | ||
if target, err := fs.ReadFile(devfs, path); err == nil { | ||
return string(target), nil | ||
} else { | ||
return "", fmt.Errorf("error") | ||
} | ||
} else { | ||
return "", fmt.Errorf("error") | ||
} | ||
} |
Oops, something went wrong.