feat: add file-server tools (#72)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2024-09-25 22:38:08 +08:00 committed by GitHub
parent 2108989c74
commit c1381ba0e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 78 additions and 6 deletions

View File

@ -1,10 +1,10 @@
all: help all: help
# Run markdown lint # Build file-server image.
markdownlint: docker-build-file-server:
@echo "Begin to markdownlint." @echo "Begin to use docker build file-server image."
@./hack/markdownlint.sh docker build -t file-server:latest -f ./tools/file-server/Dockerfile .
.PHONY: markdownlint .PHONY: docker-build-file-server
# Run code lint # Run code lint
lint: markdownlint lint: markdownlint
@ -12,6 +12,12 @@ lint: markdownlint
@golangci-lint run @golangci-lint run
.PHONY: lint .PHONY: lint
# Run markdown lint
markdownlint:
@echo "Begin to markdownlint."
@./hack/markdownlint.sh
.PHONY: markdownlint
# Clear compiled files # Clear compiled files
clean: clean:
@go clean @go clean
@ -19,6 +25,7 @@ clean:
.PHONY: clean .PHONY: clean
help: help:
@echo "make docker-build-file-server build file-server image"
@echo "make lint run code lint" @echo "make lint run code lint"
@echo "make markdownlint run markdown lint" @echo "make markdownlint run markdown lint"
@echo "make clean clean" @echo "make clean clean"

View File

@ -3,6 +3,7 @@ module github.com/dragonflyoss/perf-tests/benchmark
go 1.22.4 go 1.22.4
require ( require (
github.com/google/uuid v1.4.0
github.com/sirupsen/logrus v1.9.3 github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1 github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0 github.com/spf13/viper v1.19.0

View File

@ -9,6 +9,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=

View File

@ -20,6 +20,8 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"path" "path"
"github.com/google/uuid"
) )
type FileSizeLevel string type FileSizeLevel string
@ -58,6 +60,7 @@ func (f *fileServer) GetFileURL(fileSizeLevel FileSizeLevel, tag string) (*url.U
// Add tag query parameter. // Add tag query parameter.
query := u.Query() query := u.Query()
query.Set("tag", tag) query.Set("tag", tag)
query.Set("uuid", uuid.New().String())
u.RawQuery = query.Encode() u.RawQuery = query.Encode()
return u, nil return u, nil
} }

View File

@ -255,7 +255,7 @@ func (d *dragonfly) downloadFileByProxy(ctx context.Context, podExec *util.PodEx
// getClientPods returns the client pods. // getClientPods returns the client pods.
func (d *dragonfly) getClientPods(ctx context.Context) ([]string, error) { func (d *dragonfly) getClientPods(ctx context.Context) ([]string, error) {
pods, err := util.GetPods(ctx, d.namespace, "app=client") pods, err := util.GetPods(ctx, d.namespace, "component=client")
if err != nil { if err != nil {
logrus.Errorf("failed to get pods: %v", err) logrus.Errorf("failed to get pods: %v", err)
return nil, err return nil, err

View File

@ -0,0 +1,19 @@
FROM nginx:alpine
RUN dd if=/dev/zero of=/usr/share/nginx/html/nano bs=1 count=1
RUN dd if=/dev/zero of=/usr/share/nginx/html/micro bs=1K count=10
RUN dd if=/dev/zero of=/usr/share/nginx/html/small bs=1M count=1
RUN dd if=/dev/zero of=/usr/share/nginx/html/medium bs=1M count=10
RUN dd if=/dev/zero of=/usr/share/nginx/html/large bs=1G count=1
RUN dd if=/dev/zero of=/usr/share/nginx/html/xlarge bs=1G count=10
RUN dd if=/dev/zero of=/usr/share/nginx/html/xxlarge bs=1G count=30
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@ -0,0 +1,40 @@
---
apiVersion: v1
kind: Service
metadata:
name: file-server
spec:
selector:
app: dragonfly
component: file-server
type: ClusterIP
ports:
- name: nginx
port: 80
protocol: TCP
targetPort: 80
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: file-server
spec:
serviceName: file-server
selector:
matchLabels:
app: dragonfly
component: file-server
replicas: 1
template:
metadata:
labels:
app: dragonfly
component: file-server
spec:
containers:
- name: file-server
image: dragonflyoss/file-server:latest
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 80