Skip to content

Commit

Permalink
Organise files wrt Go native approach (parseablehq#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
nitisht authored Sep 30, 2023
1 parent 800a722 commit a3e8fd0
Show file tree
Hide file tree
Showing 27 changed files with 414 additions and 855 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/cla.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
uses: contributor-assistant/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# the below token should have repo scope and must be manually added by you in the repository's secret
# This token is required only if you have configured to store the signatures in a remote repository/organization
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
with:
remote-organization-name: 'parseablehq' # enter the remote organization name where the signatures should be stored (Default is storing the signatures in the same repository)
Expand All @@ -40,5 +42,4 @@ jobs:
#custom-pr-sign-comment: 'The signature to be committed in order to sign the CLA'
#custom-allsigned-prcomment: 'pull request comment when all contributors has signed, defaults to **CLA Assistant Lite bot** All Contributors have signed the CLA.'
#lock-pullrequest-aftermerge: false - if you don't want this bot to automatically lock the pull request after merging (default - true)
#use-dco-flag: true - If you are using DCO instead of CLA

#use-dco-flag: true - If you are using DCO instead of CLA
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ WORKDIR /tests

COPY . .

RUN apt install wget \
RUN go test -c \
&& apt install wget \
&& wget https://github.com/grafana/k6/releases/download/v0.46.0/k6-v0.46.0-linux-amd64.deb \
&& apt install -f ./k6-v0.46.0-linux-amd64.deb \
&& apt update \
Expand All @@ -13,5 +14,4 @@ RUN apt install wget \
&& tar -xvf flog_0.4.3_linux_amd64.tar.gz \
&& cp flog /usr/local/bin


ENTRYPOINT ["./main.sh"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ docker build . -t parseable/quest:v0.1
Use the below format to run tests against a Parseable server.

Positional arguments for the 'smoke' or 'load' mode:

```
1. Test name: `smoke` or `load`
2. Server URL
Expand Down
1 change: 0 additions & 1 deletion benchmarks/README.md

This file was deleted.

16 changes: 16 additions & 0 deletions testrunner/client.go → client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright (c) 2023 Cloudnatively Services Pvt Ltd
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package main

import (
Expand Down
4 changes: 2 additions & 2 deletions testrunner/go.mod → go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module smoketest
module quest

go 1.21.0
go 1.21.1

require github.com/stretchr/testify v1.8.4

Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions go.work

This file was deleted.

1 change: 0 additions & 1 deletion go.work.sum

This file was deleted.

Binary file removed images/grafana.png
Binary file not shown.
File renamed without changes.
74 changes: 74 additions & 0 deletions load_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) 2023 Cloudnatively Services Pvt Ltd
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package main

import (
"fmt"
"os/exec"
"testing"
)

const (
vus = "10"
duration = "5m"
schema_count = "20"
)

func TestStreamBatchLoadWithK6(t *testing.T) {
if NewGlob.Mode == "load" {
CreateStream(t, NewGlob.Client, NewGlob.Stream)
cmd := exec.Command("k6",
"run",
"-e", fmt.Sprintf("P_URL=%s", NewGlob.Url.String()),
"-e", fmt.Sprintf("P_USERNAME=%s", NewGlob.Username),
"-e", fmt.Sprintf("P_PASSWORD=%s", NewGlob.Password),
"-e", fmt.Sprintf("P_STREAM=%s", NewGlob.Stream),
"-e", fmt.Sprintf("P_SCHEMA_COUNT=%s", schema_count),
"./scripts/load_batch_events.js",
"--vus=", vus,
"--duration=", duration)

cmd.Run()
op, err := cmd.Output()
if err != nil {
t.Log(err)
}
t.Log(string(op))
}
}

func TestStreamLoadWithK6(t *testing.T) {
if NewGlob.Mode == "load" {
cmd := exec.Command("k6",
"run",
"-e", fmt.Sprintf("P_URL=%s", NewGlob.Url.String()),
"-e", fmt.Sprintf("P_USERNAME=%s", NewGlob.Username),
"-e", fmt.Sprintf("P_PASSWORD=%s", NewGlob.Password),
"-e", fmt.Sprintf("P_STREAM=%s", NewGlob.Stream),
"-e", fmt.Sprintf("P_SCHEMA_COUNT=%s", schema_count),
"./scripts/load_single_events.js",
"--vus=", vus,
"--duration=", duration)

cmd.Run()
op, err := cmd.Output()
if err != nil {
t.Log(err)
}
t.Log(string(op))
}
}
69 changes: 69 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) 2023 Cloudnatively Services Pvt Ltd
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package main

import (
"flag"
"net/url"
"testing"
)

func main() {
println("hello")
}

type Glob struct {
Url url.URL
Username string
Password string
Stream string
Client HTTPClient
Mode string
}

var NewGlob = func() Glob {
testing.Init()
var targetUrl string
var username string
var password string
var stream string
var mode string

flag.StringVar(&targetUrl, "url", "http://localhost:8000", "Specify url. Default is root")
flag.StringVar(&username, "user", "admin", "Specify username. Default is admin")
flag.StringVar(&password, "pass", "admin", "Specify pass. Default is admin")
flag.StringVar(&stream, "stream", "app", "Specify stream. Default is app")
flag.StringVar(&mode, "mode", "smoke", "Specify mode. Default is smoke")

flag.Parse()

parsedTargetUrl, err := url.Parse(targetUrl)
if err != nil {
panic("Could not parse url")
}

client := DefaultClient(*parsedTargetUrl, username, password)

return Glob{
Url: *parsedTargetUrl,
Username: username,
Password: password,
Stream: stream,
Client: client,
Mode: mode,
}
}()
23 changes: 3 additions & 20 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,9 @@ duration=$7

stream_name=$(head /dev/urandom | tr -dc a-z | head -c10)

run_smoke_test () {
go test smoketest -timeout=10m -args -url="$endpoint" -stream="$stream_name" -user="$username" -pass="$password"
run () {
./quest.test -test.v -mode="$mode" -url="$endpoint" -stream="$stream_name" -user="$username" -pass="$password"
return $?
}

run_load_test () {
./testcases/load_test.sh "$endpoint" "$stream_name" "$username" "$password" "$schema_count" "$vus" "$duration"
return $?
}

run_validation_test () {
./testcases/validate_test.sh "$endpoint" "$stream_name" "$username" "$password" "$schema_count" "$vus" "$duration"
return $?
}

case "$mode" in
"smoke") run_smoke_test
;;
"load") run_load_test
;;
"validate") run_validation_test
;;
esac
run
25 changes: 23 additions & 2 deletions testrunner/model.go → model.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Copyright (c) 2023 Cloudnatively Services Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package main

import "fmt"
Expand Down Expand Up @@ -338,8 +353,10 @@ const RetentionBody string = `[
}
]`

const TestUser string = "alice"
const dummyRole string = `[{"privilege": "editor"},{"privilege": "writer", "resource": {"stream": "app"}}]`
const (
TestUser string = "alice"
dummyRole string = `[{"privilege": "editor"},{"privilege": "writer", "resource": {"stream": "app"}}]`
)

const RoleEditor string = `[{"privilege": "editor"}]`

Expand All @@ -350,3 +367,7 @@ func RoleWriter(stream string) string {
func RoleReader(stream string) string {
return fmt.Sprintf(`[{"privilege": "reader", "resource": {"stream": "%s", "tag": null}}]`, stream)
}

func RoleIngestor(stream string) string {
return fmt.Sprintf(`[{"privilege": "ingest", "resource": {"stream": "%s"}}]`, stream)
}
Binary file added quest.test
Binary file not shown.
File renamed without changes.
File renamed without changes.
10 changes: 4 additions & 6 deletions testcases/load_test.sh → scripts/load_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ count=$5
vus=$6
duration=$7

curl_std_opts=( -sS --header 'Content-Type: application/json' -w '\n\n%{http_code}' -u "$username":"$password" )

# Create stream
create_stream () {
response=$(curl "${curl_std_opts[@]}" --request PUT "$parseable_url"/api/v1/logstream/"$stream_name")
response=$(curl -sS --header 'Content-Type: application/json' -w '\n\n%{http_code}' -u "$username":"$password" --request PUT "$parseable_url"/api/v1/logstream/"$stream_name")

if [ $? -ne 0 ]; then
printf "Failed to create log stream %s with exit code: %s\n" "$stream_name" "$?"
Expand Down Expand Up @@ -56,7 +54,7 @@ create_stream () {

# Delete stream
delete_stream () {
response=$(curl "${curl_std_opts[@]}" --request DELETE "$parseable_url"/api/v1/logstream/"$stream_name")
response=$(curl -sS --header 'Content-Type: application/json' -w '\n\n%{http_code}' -u "$username":"$password" --request DELETE "$parseable_url"/api/v1/logstream/"$stream_name")

if [ $? -ne 0 ]; then
printf "Failed to delete stream for %s with exit code: %s\n" "$stream_name" "$?"
Expand Down Expand Up @@ -84,10 +82,10 @@ delete_stream () {

run_k6() {
printf "K6 script with 100 batched log events per HTTP Call"
k6 run -e P_URL="$parseable_url" -e P_STREAM="$stream_name" -e P_USERNAME="$username" -e P_PASSWORD="$password" -e P_SCHEMA_COUNT="$count" "/tests/testcases/load_batch_events.js" --vus="$vus" --duration="$duration"
k6 run -e P_URL="$parseable_url" -e P_STREAM="$stream_name" -e P_USERNAME="$username" -e P_PASSWORD="$password" -e P_SCHEMA_COUNT="$count" "/tests/scripts/load_batch_events.js" --vus="$vus" --duration="$duration"

printf "K6 script with 1 event per HTTP Call"
k6 run -e P_URL="$parseable_url" -e P_STREAM="$stream_name" -e P_USERNAME="$username" -e P_PASSWORD="$password" -e P_SCHEMA_COUNT="$count" "/tests/testcases/load_single_event.js" --vus="$vus" --duration="$duration"
k6 run -e P_URL="$parseable_url" -e P_STREAM="$stream_name" -e P_USERNAME="$username" -e P_PASSWORD="$password" -e P_SCHEMA_COUNT="$count" "/tests/scripts/load_single_event.js" --vus="$vus" --duration="$duration"
}

printf "======= Starting load tests with k6 =======\n"
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions signatures/version1/cla.json

This file was deleted.

Loading

0 comments on commit a3e8fd0

Please sign in to comment.