Skip to content

Commit

Permalink
feat: Initial changes for distributed jmeter
Browse files Browse the repository at this point in the history
Signed-off-by: hiteshwani <[email protected]>
  • Loading branch information
hiteshwani committed Aug 23, 2023
1 parent c794a9c commit 07c0884
Show file tree
Hide file tree
Showing 54 changed files with 2,222 additions and 26 deletions.
9 changes: 8 additions & 1 deletion api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4901,7 +4901,14 @@ components:
$ref: "#/components/schemas/TestSuiteExecution"
clusterName:
type: string
description: cluster name of event
description: cluster name of event
envs:
type: object
description: "environment variables"
additionalProperties:
type: string
example:
WEBHOOK_PARAMETER: "any value"

EventResource:
type: string
Expand Down
20 changes: 16 additions & 4 deletions cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"

"google.golang.org/grpc"
Expand Down Expand Up @@ -284,13 +285,23 @@ func main() {

apiVersion := version.Version

envs := make(map[string]string)
for _, env := range os.Environ() {
pair := strings.SplitN(env, "=", 2)
if len(pair) != 2 {
continue
}

envs[pair[0]] += pair[1]
}

// configure NATS event bus
nc, err := bus.NewNATSConnection(cfg.NatsURI)
if err != nil {
log.DefaultLogger.Errorw("error creating NATS connection", "error", err)
}
eventBus := bus.NewNATSBus(nc)
eventsEmitter := event.NewEmitter(eventBus, cfg.TestkubeClusterName)
eventsEmitter := event.NewEmitter(eventBus, cfg.TestkubeClusterName, envs)

metrics := metrics.NewMetrics()

Expand Down Expand Up @@ -372,7 +383,7 @@ func main() {
testsuiteExecutionsClient,
)

slackLoader, err := newSlackLoader(cfg)
slackLoader, err := newSlackLoader(cfg, envs)
if err != nil {
ui.ExitOnError("Creating slack loader", err)
}
Expand Down Expand Up @@ -419,6 +430,7 @@ func main() {
api.GetLogsStream,
clusterId,
cfg.TestkubeClusterName,
envs,
)
if err != nil {
ui.ExitOnError("Starting agent", err)
Expand Down Expand Up @@ -566,7 +578,7 @@ func parseDefaultExecutors(cfg *config.Config) (executors []testkube.ExecutorDet
return executors, nil
}

func newSlackLoader(cfg *config.Config) (*slack.SlackLoader, error) {
func newSlackLoader(cfg *config.Config, envs map[string]string) (*slack.SlackLoader, error) {
slackTemplate, err := loadConfigFromStringOrFile(
cfg.SlackTemplate,
cfg.TestkubeConfigDir,
Expand All @@ -582,7 +594,7 @@ func newSlackLoader(cfg *config.Config) (*slack.SlackLoader, error) {
return nil, err
}

return slack.NewSlackLoader(slackTemplate, slackConfig, cfg.TestkubeClusterName, testkube.AllEventTypes), nil
return slack.NewSlackLoader(slackTemplate, slackConfig, cfg.TestkubeClusterName, testkube.AllEventTypes, envs), nil
}

func loadConfigFromStringOrFile(inputString, configDir, filename, configType string) (raw string, err error) {
Expand Down
10 changes: 10 additions & 0 deletions contrib/executor/jmeterd/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.git
.gitignore
.golangci.yml
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
Makefile
README.md
temp
data
6 changes: 6 additions & 0 deletions contrib/executor/jmeterd/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# used if storage backend is behind HTTPS, should be set to false for local development
RUNNER_SSL=false
# used to enable/disable scrapper, should be set to false for local development
RUNNER_SCRAPPERENABLED=false
# path to the data/ directory where JMeter will run and store results
RUNNER_DATADIR=./data
35 changes: 35 additions & 0 deletions contrib/executor/jmeterd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
### Go template
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

### JetBrains
.idea
*.iml

# Helm
Chart.lock

.DS_Store
bin/
site
dist/
data/
temp/

.vscode

### Environment
.env
29 changes: 29 additions & 0 deletions contrib/executor/jmeterd/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
run:
timeout: 5m

linters:
disable-all: true
enable:
- errcheck
- goimports
- govet
- staticcheck
- revive
- unused
- errname
- errorlint
- gocyclo
- gofmt
- goimports
- misspell
- predeclared

linters-settings:
govet:
check-shadowing: true
lll:
line-length: 150
misspell:
locale: US
goimports:
local-prefixes: github.com/kubeshop/testkube,github.com/kubeshop/testkube-executor-jmeter
30 changes: 30 additions & 0 deletions contrib/executor/jmeterd/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# testkube (by Kubeshop) Community Code of Conduct

Testkube follows the CNCF Code of Conduct. The text of the CNCF CoC is replicated below. If you notice that this is out of date, please file an issue.

If you notice a violation of the Code of Conduct at an event or meeting, in Slack, or in another communication mechanism, reach out to the Testkube Code of Conduct Committee. You can reach us by email at [email protected] Your anonymity will be protected.

# CNCF Community Code of Conduct v1.0

## Contributor Code of Conduct

As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.

## Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery
- Personal attacks
- Trolling or insulting/derogatory comments
- Public or private harassment
- Publishing other's private information, such as physical or electronic addresses, without explicit permission
- Other unethical or unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.

This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.

Instances of abusive, harassing, or otherwise unacceptable behavior in Testkube may be reported by contacting the Testkube Code of Conduct Committee via [email protected].

This Code of Conduct is adapted from the Contributor Covenant (https://contributor-covenant.org), version 1.2.0, available at https://contributor-covenant.org/version/1/2/0/
44 changes: 44 additions & 0 deletions contrib/executor/jmeterd/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Contribution to Testkube

Thanks for reaching out contribution 🎉

If you're new in Open-source community there is nice guide how to start contributing to projects:
https://github.com/firstcontributions/first-contributions

## Code of Conduct

This project and everyone participating in it is governed by the Testkube [code of conduct](CODE_OF_CONDUCT.md)

## Have questions or idea?

We're using github discussions for managing pre-development ideas and clarifications, feel free to add one at our [Q&A discussion page](https://github.com/kubeshop/testkube/discussions/categories/q-a)

New ideas should be placed in [Ideas discussion page](https://github.com/kubeshop/testkube/discussions/categories/ideas)



## General guidance for contributing to Testkube project

You're very welcome to help in testkube development, there is a lot of incoming work to do :).

We're trying hard to limit technical debt from the beginning so we defined simple rules into Testkube repo to help with it.

### For golang based components

- Always use gofmt (there is only one true way of doing code formatting ;) ).
- Follow golang good practices (proverbs) in your code.
- Tests are your friend (we will target 80% CC in our code).
- Use clean names, don't brake basic design patterns and rules.

### For infrastructure / Kubernetes based components

- We're using helm charts to build and share Testkube
- Comment non-obvious decisions
- Use current Helm/Kubernetes versions


## How can I help?

- By fixing [one of many Issues](https://github.com/kubeshop/testkube/issues) - simply fork our repo and create new Pull Request with new code changes.
- By helping to reach out valid results [from discussions](https://github.com/kubeshop/testkube/discussions)

21 changes: 21 additions & 0 deletions contrib/executor/jmeterd/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Kubeshop

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
60 changes: 60 additions & 0 deletions contrib/executor/jmeterd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
REPOSITORY ?= kubeshop
NAME ?= testkube-jmeterd-executor
LOCAL_TAG ?= 999.0.0
BIN_DIR ?= $(HOME)/bin

.PHONY: build
build:
go build -o $(BIN_DIR)/$(NAME) cmd/agent/main.go

.PHONY: build-local-linux
build-local-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o dist/runner cmd/agent/main.go

.PHONY: run
run:
EXECUTOR_PORT=8082 go run cmd/agent/main.go ${run_args}

.PHONY: docker-build
docker-build:
docker build -t $(REPOSITORY)/$(NAME) -f build/agent/Dockerfile .

.PHONY: docker-build-local
docker-build-local: build-local-linux
docker build -t $(REPOSITORY)/$(NAME):$(LOCAL_TAG) -f build/agent/local.Dockerfile .

.PHONY: kind-load-local
kind-load-local: build-local-linux
kind load docker-image kubeshop/testkube-jmeterd-executor:999.0.0

.PHONY: test
test:
go test ./... -cover

.PHONY: integration-test
integration-test:
INTEGRATION=y gotestsum --format short-verbose -- -run _Integration -cover ./...

.PHONY: cover
cover:
@go test -failfast -count=1 -v -tags test -coverprofile=./testCoverage.txt ./... && go tool cover -html=./testCoverage.txt -o testCoverage.html && rm ./testCoverage.txt
open testCoverage.html

.PHONY: version-bump
version-bump: version-bump-patch

.PHONY: version-bump-patch
version-bump-patch:
go run cmd/tools/main.go bump -k patch

.PHONY: version-bump-minor
version-bump-minor:
go run cmd/tools/main.go bump -k minor

.PHONY: version-bump-major
version-bump-major:
go run cmd/tools/main.go bump -k major

.PHONY: version-bump-dev
version-bump-dev:
go run cmd/tools/main.go bump --dev
Loading

0 comments on commit 07c0884

Please sign in to comment.