Skip to content

Commit

Permalink
Merge pull request #179 from scylladb/schema_in_output_file
Browse files Browse the repository at this point in the history
gemini: schema in result file
  • Loading branch information
Henrik Johansson authored Jul 16, 2019
2 parents 29c6df3 + 713bb39 commit 5d78a64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/gemini/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func run(cmd *cobra.Command, args []string) {
}
pump.Start(duration+warmup, createPumpCallback(result, sp))
res := sampleStatus(pump, result, sp, logger)
res.PrintResult(outFile)
res.PrintResult(outFile, schema)
for _, g := range generators {
g.Stop()
}
Expand Down
12 changes: 8 additions & 4 deletions cmd/gemini/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/briandowns/spinner"
"github.com/pkg/errors"
"github.com/scylladb/gemini"
"go.uber.org/zap"
)

Expand All @@ -28,8 +29,8 @@ func (r *Status) Merge(sum *Status) Status {
return *sum
}

func (r *Status) PrintResult(w io.Writer) {
if err := r.PrintResultAsJSON(w); err != nil {
func (r *Status) PrintResult(w io.Writer, schema *gemini.Schema) {
if err := r.PrintResultAsJSON(w, schema); err != nil {
// In case there has been it has been a long run we want to display it anyway...
fmt.Printf("Unable to print result as json, using plain text to stdout, error=%s\n", err)
fmt.Printf("Gemini version: %s\n", version)
Expand All @@ -41,17 +42,20 @@ func (r *Status) PrintResult(w io.Writer) {
for i, err := range r.Errors {
fmt.Printf("Error %d: %s\n", i, err)
}
jsonSchema, _ := json.MarshalIndent(schema, "", " ")
fmt.Printf("Schema: %v\n", string(jsonSchema))
}
}

func (r *Status) PrintResultAsJSON(w io.Writer) error {
func (r *Status) PrintResultAsJSON(w io.Writer, schema *gemini.Schema) error {
result := map[string]interface{}{
"result": r,
"gemini_version": version,
"schema": schema,
}
encoder := json.NewEncoder(w)
encoder.SetEscapeHTML(false)
encoder.SetIndent(" ", " ")
encoder.SetIndent(" ", " ")
if err := encoder.Encode(result); err != nil {
return errors.Wrap(err, "unable to create json from result")
}
Expand Down

0 comments on commit 5d78a64

Please sign in to comment.