github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/benchmark/cmd/command/queryprom.go (about)

     1  package command
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     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 newPromQuery(cfg *config.PromQuery) *cobra.Command {
    14  	vpr := newViper()
    15  	promQuery := &cobra.Command{
    16  		// TODO(eh-am): call it 'promquery instant' or something
    17  		Use:   "promquery [flags]",
    18  		Short: "queries prometheus",
    19  		Args: func(cmd *cobra.Command, args []string) error {
    20  			return nil
    21  		},
    22  		RunE: cli.CreateCmdRunFn(cfg, vpr, func(_ *cobra.Command, args []string) error {
    23  			query := args[0]
    24  			t := time.Now()
    25  
    26  			pq := promquery.New(cfg)
    27  
    28  			value, err := pq.Instant(query, t)
    29  			if err != nil {
    30  				return err
    31  			}
    32  
    33  			fmt.Println(value)
    34  			return nil
    35  		}),
    36  	}
    37  
    38  	cli.PopulateFlagSet(cfg, promQuery.Flags(), vpr)
    39  	return promQuery
    40  }