// Package `logs` contains the billman CLI for calculating // log billing data. package logs import ( "context" "flag" "github.com/peterbourgon/ff/v3/ffcli" "edge-infra.dev/pkg/edge/monitoring/billman/cmd" "edge-infra.dev/pkg/edge/monitoring/billman/costs" "edge-infra.dev/pkg/edge/monitoring/billman/gcp" ) const ( name = "logs" container = "k8s_container" node = "k8s_node" ) // config for the logs subcommand type config struct { RootConfig *cmd.Config DisplayType string } // New returns a usable ffcli.Command for the logs subcommand. func New(rootConfig *cmd.Config) *ffcli.Command { cfg := config{ RootConfig: rootConfig, DisplayType: name, } fs := flag.NewFlagSet("billman"+name, flag.ExitOnError) return &ffcli.Command{ Name: name, ShortUsage: "billman " + name + " [flags]", ShortHelp: "Print the estimated billing costs for logs", FlagSet: cmd.WithGlobalFlags(fs), Exec: cfg.Exec, } } // Exec runs the `billman logs` command. Only log // data will be calculated. func (c *config) Exec(_ context.Context, _ []string) error { err := cmd.CheckRequiredFlags(cmd.GlobalFlags) if err != nil { return err } err = cmd.CheckPeriod(c.RootConfig.Period) if err != nil { return err } bytesContainer, err := gcp.GetLogBytes(c.RootConfig.TopLevelProjectID, c.RootConfig.ClusterID, c.RootConfig.Period, container) if err != nil { return err } bytesNode, err := gcp.GetLogBytes(c.RootConfig.TopLevelProjectID, c.RootConfig.ClusterID, c.RootConfig.Period, node) if err != nil { return err } lcd := costs.LogContainerData{ Bytes: bytesContainer, Cost: costs.LogCosts(bytesContainer, c.RootConfig.LoggingRate), } lnd := costs.LogNodeData{ Bytes: bytesNode, Cost: costs.LogCosts(bytesNode, c.RootConfig.LoggingRate), } ld := costs.LogData{ Bytes: lcd.Bytes + lnd.Bytes, Cost: lcd.Cost + lnd.Cost, } b := costs.Billing{ Cluster: c.RootConfig.Cluster, LogContainerData: lcd, LogNodeData: lnd, LogData: ld, MetricData: costs.MetricData{}, Options: c.RootConfig.Options, DisplayType: c.DisplayType, } costs.PrintClusterCosts(b) return nil }