-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add new <= 0.1m tier. - Fix tier selection and add tests. Remove tier duplicate. - Update deps, run rekres. Signed-off-by: Dmitriy Matrenichev <[email protected]>
- Loading branch information
Showing
10 changed files
with
103 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,15 @@ | |
|
||
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. | ||
# | ||
# Generated on 2023-05-17T09:08:38Z by kres latest. | ||
# Generated on 2023-06-14T00:34:22Z by kres latest. | ||
|
||
ARG TOOLCHAIN | ||
|
||
# cleaned up specs and compiled versions | ||
FROM scratch AS generate | ||
|
||
# runs markdownlint | ||
FROM docker.io/node:20.2.0-alpine3.17 AS lint-markdown | ||
FROM docker.io/node:20.3.0-alpine3.18 AS lint-markdown | ||
WORKDIR /src | ||
RUN npm i -g [email protected] | ||
RUN npm i [email protected] | ||
|
@@ -28,26 +28,27 @@ ENV GO111MODULE on | |
ARG CGO_ENABLED | ||
ENV CGO_ENABLED ${CGO_ENABLED} | ||
ENV GOPATH /go | ||
ARG DEEPCOPY_VERSION | ||
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install github.com/siderolabs/deep-copy@${DEEPCOPY_VERSION} \ | ||
&& mv /go/bin/deep-copy /bin/deep-copy | ||
ARG GOLANGCILINT_VERSION | ||
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCILINT_VERSION} \ | ||
&& mv /go/bin/golangci-lint /bin/golangci-lint | ||
ARG GOFUMPT_VERSION | ||
RUN go install mvdan.cc/gofumpt@${GOFUMPT_VERSION} \ | ||
&& mv /go/bin/gofumpt /bin/gofumpt | ||
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install golang.org/x/vuln/cmd/govulncheck@latest \ | ||
&& mv /go/bin/govulncheck /bin/govulncheck | ||
ARG GOIMPORTS_VERSION | ||
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install golang.org/x/tools/cmd/goimports@${GOIMPORTS_VERSION} \ | ||
&& mv /go/bin/goimports /bin/goimports | ||
ARG DEEPCOPY_VERSION | ||
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install github.com/siderolabs/deep-copy@${DEEPCOPY_VERSION} \ | ||
&& mv /go/bin/deep-copy /bin/deep-copy | ||
ARG GOFUMPT_VERSION | ||
RUN go install mvdan.cc/gofumpt@${GOFUMPT_VERSION} \ | ||
&& mv /go/bin/gofumpt /bin/gofumpt | ||
|
||
# tools and sources | ||
FROM tools AS base | ||
WORKDIR /src | ||
COPY ./go.mod . | ||
COPY ./go.sum . | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
RUN cd . | ||
RUN --mount=type=cache,target=/go/pkg go mod download | ||
RUN --mount=type=cache,target=/go/pkg go mod verify | ||
COPY ./controlplane ./controlplane | ||
|
@@ -61,28 +62,32 @@ RUN FILES="$(gofumpt -l .)" && test -z "${FILES}" || (echo -e "Source code is no | |
|
||
# runs goimports | ||
FROM base AS lint-goimports | ||
RUN FILES="$(goimports -l -local github.com/siderolabs/go-loadbalancer .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'goimports -w -local github.com/siderolabs/go-loadbalancer .':\n${FILES}"; exit 1) | ||
RUN FILES="$(goimports -l -local github.com/siderolabs/go-loadbalancer/ .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'goimports -w -local github.com/siderolabs/go-loadbalancer/ .':\n${FILES}"; exit 1) | ||
|
||
# runs golangci-lint | ||
FROM base AS lint-golangci-lint | ||
WORKDIR /src | ||
COPY .golangci.yml . | ||
ENV GOGC 50 | ||
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.cache/golangci-lint --mount=type=cache,target=/go/pkg golangci-lint run --config .golangci.yml | ||
|
||
# runs govulncheck | ||
FROM base AS lint-govulncheck | ||
WORKDIR /src | ||
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg govulncheck ./... | ||
|
||
# runs unit-tests with race detector | ||
FROM base AS unit-tests-race | ||
WORKDIR /src | ||
ARG TESTPKGS | ||
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg --mount=type=cache,target=/tmp CGO_ENABLED=1 go test -v -race -count 1 ${TESTPKGS} | ||
|
||
# runs unit-tests | ||
FROM base AS unit-tests-run | ||
WORKDIR /src | ||
ARG TESTPKGS | ||
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg --mount=type=cache,target=/tmp go test -v -covermode=atomic -coverprofile=coverage.txt -coverpkg=${TESTPKGS} -count 1 ${TESTPKGS} | ||
|
||
FROM scratch AS unit-tests | ||
COPY --from=unit-tests-run /src/coverage.txt /coverage.txt | ||
COPY --from=unit-tests-run /src/coverage.txt /coverage-unit-tests.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
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,13 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package loadbalancer | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/siderolabs/go-loadbalancer/upstream" | ||
) | ||
|
||
func CalcTier(err error, elapsed time.Duration) (upstream.Tier, error) { return calcTier(err, elapsed) } |
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,46 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package loadbalancer_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/siderolabs/go-loadbalancer/loadbalancer" | ||
"github.com/siderolabs/go-loadbalancer/upstream" | ||
) | ||
|
||
func Test_calcTier(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := map[string]struct { | ||
want upstream.Tier | ||
elapsed time.Duration | ||
}{ | ||
"Microsecond": {want: upstream.Tier(0), elapsed: time.Microsecond}, | ||
"100 Microseconds": {want: upstream.Tier(1), elapsed: 100 * time.Microsecond}, | ||
"Millisecond": {want: upstream.Tier(2), elapsed: time.Millisecond}, | ||
"10 Milliseconds": {want: upstream.Tier(3), elapsed: 10 * time.Millisecond}, | ||
"100 Milliseconds": {want: upstream.Tier(4), elapsed: 100 * time.Millisecond}, | ||
"1 Second": {want: upstream.Tier(5), elapsed: time.Second}, | ||
} | ||
for name, tt := range tests { | ||
tt := tt | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
got, err := loadbalancer.CalcTier(nil, tt.elapsed) | ||
if err != nil { | ||
t.Errorf("calcTier() error = %v", err) | ||
|
||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("calcTier() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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