Skip to content

Commit

Permalink
Add -config custom config file options. Fixes #6. (#12)
Browse files Browse the repository at this point in the history
* Add -config custom config file options. Fixes #6.

* [skip ci] Improve usage
  • Loading branch information
bojand committed Apr 16, 2018
1 parent 716c0b2 commit 6e5b8f1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Options:
-protoset The compiled protoset file. Alternative to proto. -proto takes precedence.
-call A fully-qualified method name in 'service/method' or 'service.method' format.
-cert The file containing the CA root cert file.
-cname an override of the expect Server Cname presented by the server.
-cname An override of the expect Server Cname presented by the server.
-config Path to the config JSON file.
-c Number of requests to run concurrently. Total number of requests cannot
be smaller than the concurrency level. Default is 50.
Expand Down Expand Up @@ -59,7 +60,7 @@ Options:
-v Print the version.
```

Alternatively all settings can be set via `grpcannon.json` file if present in the same path as the `grpcannon` executable.
Alternatively all settings can be set via `grpcannon.json` file if present in the same path as the `grpcannon` executable. A custom configuration file can be specified using `-config` option.

## Examples

Expand Down Expand Up @@ -99,6 +100,12 @@ And then use it as input to `grpcannon` with `-protoset` option:

Note that only one of `-proto` or `-protoset` options will be used. `-proto` takes precedence.

Using a custom config file:

```sh
grpcannon -config ./config.json
```

Example `grpcannon.json`

```json
Expand All @@ -112,7 +119,10 @@ Example `grpcannon.json`
},
"i": [
"/path/to/protos"
]
],
"n": 4000,
"c": 40,
"host": "0.0.0.0:50051"
}
```

Expand Down
28 changes: 19 additions & 9 deletions cmd/grpcannon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var (
protoset = flag.String("protoset", "", `The .protoset file.`)
call = flag.String("call", "", `A fully-qualified symbol name.`)
cert = flag.String("cert", "", "Client certificate file. If Omitted insecure is used.")
cname = flag.String("cname", "", "Server Cert CName Override - useful for self signed certs")
cname = flag.String("cname", "", "Server Cert CName Override - useful for self signed certs.")
cPath = flag.String("config", "", "Path to the config JSON file.")

c = flag.Int("c", 50, "Number of requests to run concurrently.")
n = flag.Int("n", 200, "Number of requests to run. Default is 200.")
Expand Down Expand Up @@ -58,7 +59,8 @@ Options:
-protoset The compiled protoset file. Alternative to proto. -proto takes precedence.
-call A fully-qualified method name in 'service/method' or 'service.method' format.
-cert The file containing the CA root cert file.
-cname an override of the expect Server Cname presented by the server.
-cname An override of the expect Server Cname presented by the server.
-config Path to the config JSON file.
-c Number of requests to run concurrently. Total number of requests cannot
be smaller than the concurrency level. Default is 50.
Expand Down Expand Up @@ -102,20 +104,28 @@ func main() {
os.Exit(0)
}

if flag.NArg() < 1 {
usageAndExit("")
}

host := flag.Args()[0]

var cfg *config.Config

if _, err := os.Stat(localConfigName); err == nil {
cfgPath := strings.TrimSpace(*cPath)

if cfgPath != "" {
var err error
cfg, err = config.ReadConfig(cfgPath)
if err != nil {
errAndExit(err.Error())
}
} else if _, err := os.Stat(localConfigName); err == nil {
cfg, err = config.ReadConfig(localConfigName)
if err != nil {
errAndExit(err.Error())
}
} else {
if flag.NArg() < 1 {
usageAndExit("")
}

host := flag.Args()[0]

iPaths := []string{}
pathsTrimmed := strings.TrimSpace(*paths)
if pathsTrimmed != "" {
Expand Down
4 changes: 2 additions & 2 deletions data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ func TestData_createPayloads(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, mtdClientStreaming)

mtdTestUnary, err := protodesc.GetMethodDesc(
mtdTestUnary, err := protodesc.GetMethodDescFromProto(
"data.DataTestService.TestCall",
"./testdata/data.proto",
nil)

assert.NoError(t, err)
assert.NotNil(t, mtdTestUnary)

mtdTestUnaryTwo, err := protodesc.GetMethodDesc(
mtdTestUnaryTwo, err := protodesc.GetMethodDescFromProto(
"data.DataTestService.TestCallTwo",
"./testdata/data.proto",
nil)
Expand Down

0 comments on commit 6e5b8f1

Please sign in to comment.