-
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
165b761
commit 0dfe4e3
Showing
25 changed files
with
2,495 additions
and
1,075 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
IMAGE_REGISTRY?=localhost:5000/ | ||
IMAGE_VERSION?=latest | ||
|
||
IMAGE_NAME?=$(IMAGE_REGISTRY)sriov-metrics-exporter:$(IMAGE_VERSION) | ||
|
||
DOCKERARGS?= | ||
ifdef HTTP_PROXY | ||
DOCKERARGS += --build-arg http_proxy=$(HTTP_PROXY) | ||
endif | ||
ifdef HTTPS_PROXY | ||
DOCKERARGS += --build-arg https_proxy=$(HTTPS_PROXY) | ||
endif | ||
|
||
all: build docker-build test | ||
|
||
clean: | ||
rm -rf bin | ||
go clean --modcache | ||
|
||
go clean -modcache -testcache | ||
build: | ||
GO111MODULE=on go build -ldflags "-s -w" -buildmode=pie -o bin/sriov-exporter cmd/sriov-network-metrics-exporter.go | ||
|
||
docker-build: | ||
@echo "Bulding Docker image $(IMAGE_NAME)" | ||
docker build -f Dockerfile -t $(IMAGE_NAME) $(DOCKERARGS) . | ||
|
||
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 | ||
GO111MODULE=on go build -ldflags "-s -w" -buildmode=pie -o bin/sriov-exporter cmd/sriov-network-metrics-exporter.go | ||
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,80 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"golang.org/x/time/rate" | ||
) | ||
|
||
func TestMain(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "main test suite") | ||
} | ||
|
||
var _ = DescribeTable("test endpointOnly handler", // endpointOnly | ||
func(endpoint string, expectedResponse int) { | ||
recorder := httptest.NewRecorder() | ||
request := httptest.NewRequest(http.MethodGet, endpoint, nil) | ||
handler := endpointOnly(promhttp.Handler(), metricsEndpoint) | ||
|
||
handler.ServeHTTP(recorder, request) | ||
|
||
Expect(recorder.Code).To(Equal(expectedResponse)) | ||
}, | ||
Entry("returns status 'OK' when request endpoint is '/metrics'", "/metrics", http.StatusOK), | ||
Entry("returns status 'Not Found' when request endpoint is not '/metrics'", "/invalidendpoint", http.StatusNotFound), | ||
) | ||
|
||
var _ = DescribeTable("test getOnly handler", // getOnly | ||
func(method string, expectedResponse int) { | ||
recorder := httptest.NewRecorder() | ||
request := httptest.NewRequest(method, metricsEndpoint, nil) | ||
handler := getOnly(promhttp.Handler()) | ||
|
||
handler.ServeHTTP(recorder, request) | ||
|
||
Expect(recorder.Code).To(Equal(expectedResponse)) | ||
}, | ||
Entry("returns status 'OK' when request method is 'GET'", http.MethodGet, http.StatusOK), | ||
Entry("returns status 'MethodNotAllowed' when request method is not 'GET'", http.MethodPost, http.StatusMethodNotAllowed), | ||
) | ||
|
||
var _ = DescribeTable("test noBody handler", // noBody | ||
func(body io.Reader, expectedResponse int) { | ||
recorder := httptest.NewRecorder() | ||
request := httptest.NewRequest(http.MethodGet, metricsEndpoint, body) | ||
handler := noBody(promhttp.Handler()) | ||
|
||
handler.ServeHTTP(recorder, request) | ||
|
||
Expect(recorder.Code).To(Equal(expectedResponse)) | ||
}, | ||
Entry("returns status 'OK' when request body is empty", nil, http.StatusOK), | ||
Entry("returns status 'Bad Request' when request body is not empty", bytes.NewReader([]byte("body")), http.StatusBadRequest), | ||
) | ||
|
||
var _ = DescribeTable("test limitRequests handler", // limitRequests | ||
func(limit int, requests int, expectedResponse int) { | ||
handler := limitRequests(promhttp.Handler(), rate.Limit(limit), limit) | ||
|
||
code := http.StatusOK | ||
for i := 0; i < requests; i++ { | ||
recorder := httptest.NewRecorder() | ||
request := httptest.NewRequest(http.MethodGet, metricsEndpoint, nil) | ||
handler.ServeHTTP(recorder, request) | ||
|
||
code = recorder.Code | ||
} | ||
|
||
Expect(code).To(Equal(expectedResponse)) | ||
}, | ||
Entry("returns status 'OK' when the number of requests does not exceed the request limit", 10, 10, http.StatusOK), | ||
Entry("returns status 'Too Many Requests' when number of requests exceeds the request limit", 10, 11, http.StatusTooManyRequests), | ||
) |
Oops, something went wrong.