-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #3
Merged
Develop #3
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9da5576
Fixed an issue with empty configuration files.
ViaoV d9f1649
Script refactor
ViaoV 5d982dc
Changed explorer commands
ViaoV 47e3122
Update README.md
ViaoV ab4910a
Update README.md
ViaoV b5251bd
Fake data expansion
ViaoV c581373
Added hammer command
ViaoV 8145f0d
v0.1.2
ViaoV a1fb38f
Fixed an issue with empty configuration files.
ViaoV 9588dcf
Update README.md
ViaoV 316b021
v0.1.2
ViaoV ea622d6
Fixed an issue with empty configuration files.
ViaoV 2f4ce31
v0.1.2
ViaoV 1f18549
Fixed an issue with empty configuration files.
ViaoV 7166fa6
v0.1.2
ViaoV 6ded659
Endpoint test fixes
ViaoV f7f4c6a
Linting fixes
ViaoV File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
vendor/ | ||
dist/ | ||
testdata/ |
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,77 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/5sigma/spyder/config" | ||
"github.com/5sigma/spyder/endpoint" | ||
"github.com/5sigma/spyder/output" | ||
"github.com/5sigma/spyder/request" | ||
"github.com/dustin/go-humanize" | ||
"github.com/spf13/cobra" | ||
"path" | ||
"time" | ||
) | ||
|
||
// hammerCmd represents the hammer command | ||
var hammerCmd = &cobra.Command{ | ||
Use: "hammer", | ||
Short: "Makes an endpoint request a number of times rapidly.", | ||
Long: `Make a number of request to an endpoint very rapidly and record the request timing. The hammer command expects an endpoint to be passed in the same manner as the 'request' command: | ||
|
||
spyder hammer --count 100 myEndpoint`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var ( | ||
count int | ||
totalTime time.Duration | ||
maxTime time.Duration | ||
minTime time.Duration | ||
totalBytes int64 | ||
) | ||
|
||
count, _ = cmd.Flags().GetInt("count") | ||
if len(args) == 0 { | ||
output.PrintFatal(errors.New("No endpoint specified")) | ||
} | ||
|
||
configPath := path.Join(config.ProjectPath, "endpoints", args[0]+".json") | ||
config, err := endpoint.Load(configPath) | ||
if err != nil { | ||
output.PrintFatal(err) | ||
} | ||
|
||
bar := output.NewProgress(count) | ||
for i := 0; i <= count; i++ { | ||
res, err := request.Do(config) | ||
if err != nil { | ||
output.PrintFatal(err) | ||
} | ||
totalTime += res.RequestTime | ||
bar.Inc() | ||
if minTime == 0 { | ||
minTime = res.RequestTime | ||
} | ||
if res.RequestTime > maxTime { | ||
maxTime = res.RequestTime | ||
} | ||
if res.RequestTime < minTime { | ||
minTime = res.RequestTime | ||
} | ||
totalBytes += res.Response.ContentLength | ||
} | ||
|
||
avgTime := totalTime / time.Duration(count) | ||
|
||
output.PrintProperty("Number of requests", fmt.Sprintf("%d", count)) | ||
output.PrintProperty("Average time", fmt.Sprintf("%s", avgTime)) | ||
output.PrintProperty("Fastest", fmt.Sprintf("%s", minTime)) | ||
output.PrintProperty("Slowest", fmt.Sprintf("%s", maxTime)) | ||
output.PrintProperty("Total data transfer", | ||
humanize.Bytes(uint64(totalBytes))) | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(hammerCmd) | ||
hammerCmd.PersistentFlags().Int("count", 100, "Request count") | ||
} |
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,7 @@ | ||
{ | ||
"variables": { | ||
"host": "127.0.0.1", | ||
"method": "POST", | ||
"var": "123" | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function New should have comment or be unexported