github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/benchmark/cmd/command/ci-report.go (about) 1 package command 2 3 import ( 4 "fmt" 5 6 "github.com/pyroscope-io/pyroscope/benchmark/internal/cireport" 7 "github.com/pyroscope-io/pyroscope/benchmark/internal/config" 8 "github.com/pyroscope-io/pyroscope/benchmark/internal/promquery" 9 "github.com/pyroscope-io/pyroscope/pkg/cli" 10 "github.com/spf13/cobra" 11 ) 12 13 func newReport(cfg *config.Report) *cobra.Command { 14 report := &cobra.Command{ 15 Use: "report [subcommand]", 16 Hidden: true, 17 } 18 19 vpr := newViper() 20 tableReport := &cobra.Command{ 21 Use: "table [flags]", 22 Short: "generates a markdown report to be used by ci", 23 RunE: cli.CreateCmdRunFn(&cfg.TableReport, vpr, func(_ *cobra.Command, args []string) error { 24 setLogLevel(cfg.TableReport.LogLevel) 25 pq := promquery.New(&config.PromQuery{ 26 PrometheusAddress: cfg.PrometheusAddress, 27 }) 28 29 report, err := cireport.TableReportCli(pq, cfg.TableReport.QueriesFile) 30 if err != nil { 31 return err 32 } 33 34 fmt.Println(report) 35 return nil 36 }), 37 } 38 39 imageReport := &cobra.Command{ 40 Use: "image [flags]", 41 Short: "generates a markdown report to be used by ci", 42 RunE: cli.CreateCmdRunFn(&cfg.ImageReport, vpr, func(_ *cobra.Command, args []string) error { 43 setLogLevel(cfg.ImageReport.LogLevel) 44 45 report, err := cireport.ImageReportCLI(cfg.ImageReport) 46 if err != nil { 47 return err 48 } 49 50 fmt.Println(report) 51 return nil 52 }), 53 } 54 55 metaReport := &cobra.Command{ 56 Use: "meta [flags]", 57 Short: "generates a markdown report to be used by ci", 58 RunE: cli.CreateCmdRunFn(&cfg.MetaReport, vpr, func(_ *cobra.Command, args []string) error { 59 setLogLevel(cfg.MetaReport.LogLevel) 60 61 mr, err := cireport.NewMetaReport([]string{ 62 "BENCH_RUN_FOR", 63 "PYROBENCH_RAND_SEED", 64 "PYROBENCH_PROFILE_WIDTH", 65 "PYROBENCH_PROFILE_DEPTH", 66 "PYROBENCH_PROFILE_SYMBOL_LENGTH", 67 "PYROBENCH_APPS", 68 "PYROBENCH_CLIENTS", 69 "PYROBENCH_REQUESTS", 70 }) 71 if err != nil { 72 return err 73 } 74 75 report, err := mr.Report(cfg.MetaReport.Title, cfg.MetaReport.Params) 76 if err != nil { 77 return err 78 } 79 80 fmt.Println(report) 81 return nil 82 }), 83 } 84 85 report.AddCommand(tableReport) 86 report.AddCommand(imageReport) 87 report.AddCommand(metaReport) 88 89 cli.PopulateFlagSet(&cfg.TableReport, tableReport.Flags(), vpr) 90 cli.PopulateFlagSet(&cfg.ImageReport, imageReport.Flags(), vpr) 91 cli.PopulateFlagSet(&cfg.MetaReport, metaReport.Flags(), vpr) 92 return report 93 }