Skip to content

Commit

Permalink
logging: adds Honeycomb logging endpoint support
Browse files Browse the repository at this point in the history
Signed-off-by: Colton McCurdy <cmccurdy@fastly.com>
  • Loading branch information
mccurdyc committed May 20, 2020
1 parent 2501252 commit efbd4c6
Show file tree
Hide file tree
Showing 13 changed files with 1,153 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ type Interface interface {
UpdateLoggly(*fastly.UpdateLogglyInput) (*fastly.Loggly, error)
DeleteLoggly(*fastly.DeleteLogglyInput) error

CreateHoneycomb(*fastly.CreateHoneycombInput) (*fastly.Honeycomb, error)
ListHoneycombs(*fastly.ListHoneycombsInput) ([]*fastly.Honeycomb, error)
GetHoneycomb(*fastly.GetHoneycombInput) (*fastly.Honeycomb, error)
UpdateHoneycomb(*fastly.UpdateHoneycombInput) (*fastly.Honeycomb, error)
DeleteHoneycomb(*fastly.DeleteHoneycombInput) error

GetUser(*fastly.GetUserInput) (*fastly.User, error)

GetRegions() (*fastly.RegionsResponse, error)
Expand Down
15 changes: 15 additions & 0 deletions pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/fastly/cli/pkg/logging/bigquery"
"github.com/fastly/cli/pkg/logging/ftp"
"github.com/fastly/cli/pkg/logging/gcs"
"github.com/fastly/cli/pkg/logging/honeycomb"
"github.com/fastly/cli/pkg/logging/logentries"
"github.com/fastly/cli/pkg/logging/loggly"
"github.com/fastly/cli/pkg/logging/papertrail"
Expand Down Expand Up @@ -207,6 +208,13 @@ func Run(args []string, env config.Environment, file config.File, configFilePath
logglyUpdate := loggly.NewUpdateCommand(logglyRoot.CmdClause, &globals)
logglyDelete := loggly.NewDeleteCommand(logglyRoot.CmdClause, &globals)

honeycombRoot := honeycomb.NewRootCommand(loggingRoot.CmdClause, &globals)
honeycombCreate := honeycomb.NewCreateCommand(honeycombRoot.CmdClause, &globals)
honeycombList := honeycomb.NewListCommand(honeycombRoot.CmdClause, &globals)
honeycombDescribe := honeycomb.NewDescribeCommand(honeycombRoot.CmdClause, &globals)
honeycombUpdate := honeycomb.NewUpdateCommand(honeycombRoot.CmdClause, &globals)
honeycombDelete := honeycomb.NewDeleteCommand(honeycombRoot.CmdClause, &globals)

statsRoot := stats.NewRootCommand(app, &globals)
statsRegions := stats.NewRegionsCommand(statsRoot.CmdClause, &globals)
statsHistorical := stats.NewHistoricalCommand(statsRoot.CmdClause, &globals)
Expand Down Expand Up @@ -340,6 +348,13 @@ func Run(args []string, env config.Environment, file config.File, configFilePath
logglyUpdate,
logglyDelete,

honeycombRoot,
honeycombCreate,
honeycombList,
honeycombDescribe,
honeycombUpdate,
honeycombDelete,

statsRoot,
statsRegions,
statsHistorical,
Expand Down
70 changes: 70 additions & 0 deletions pkg/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,75 @@ COMMANDS
--version=VERSION Number of service version
-n, --name=NAME The name of the Loggly logging object
logging honeycomb create --name=NAME --version=VERSION --dataset=DATASET --auth-token=AUTH-TOKEN [<flags>]
Create a Honeycomb logging endpoint on a Fastly service version
-n, --name=NAME The name of the Honeycomb logging object. Used
as a primary key for API access
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
--dataset=DATASET The Honeycomb Dataset you want to log to
--auth-token=AUTH-TOKEN The Write Key from the Account page of your
Honeycomb account
--format=FORMAT Apache style log formatting. Your log must
produce valid JSON that Honeycomb can ingest
--format-version=FORMAT-VERSION
The version of the custom logging format used
for the configured endpoint. Can be either 2
(default) or 1
--response-condition=RESPONSE-CONDITION
The name of an existing condition in the
configured endpoint, or leave blank to always
execute
--placement=PLACEMENT Where in the generated VCL the logging call
should be placed, overriding any format_version
default. Can be none or waf_debug
logging honeycomb list --version=VERSION [<flags>]
List Honeycomb endpoints on a Fastly service version
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
logging honeycomb describe --version=VERSION --name=NAME [<flags>]
Show detailed information about a Honeycomb logging endpoint on a Fastly
service version
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
-d, --name=NAME The name of the Honeycomb logging object
logging honeycomb update --version=VERSION --name=NAME [<flags>]
Update a Honeycomb logging endpoint on a Fastly service version
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
-n, --name=NAME The name of the Honeycomb logging object
--new-name=NEW-NAME New name of the Honeycomb logging object
--format=FORMAT Apache style log formatting. Your log must
produce valid JSON that Honeycomb can ingest
--format-version=FORMAT-VERSION
The version of the custom logging format used
for the configured endpoint. Can be either 2
(default) or 1
--dataset=DATASET The Honeycomb Dataset you want to log to
--auth-token=AUTH-TOKEN The Write Key from the Account page of your
Honeycomb account
--response-condition=RESPONSE-CONDITION
The name of an existing condition in the
configured endpoint, or leave blank to always
execute
--placement=PLACEMENT Where in the generated VCL the logging call
should be placed, overriding any format_version
default. Can be none or waf_debug
logging honeycomb delete --version=VERSION --name=NAME [<flags>]
Delete a Honeycomb logging endpoint on a Fastly service version
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
-n, --name=NAME The name of the Honeycomb logging object
stats regions
List stats regions
Expand All @@ -1518,4 +1587,5 @@ For help on a specific command, try e.g.
fastly help configure
fastly configure --help
`) + "\n\n"
103 changes: 103 additions & 0 deletions pkg/logging/honeycomb/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package honeycomb

import (
"io"

"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/compute/manifest"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/fastly"
)

// CreateCommand calls the Fastly API to create Honeycomb logging endpoints.
type CreateCommand struct {
common.Base
manifest manifest.Data

// required
EndpointName string // Can't shaddow common.Base method Name().
Version int
Token string
Dataset string

// optional
Format common.OptionalString
FormatVersion common.OptionalUint
ResponseCondition common.OptionalString
Placement common.OptionalString
}

// NewCreateCommand returns a usable command registered under the parent.
func NewCreateCommand(parent common.Registerer, globals *config.Data) *CreateCommand {
var c CreateCommand

c.Globals = globals
c.manifest.File.Read(manifest.Filename)
c.CmdClause = parent.Command("create", "Create a Honeycomb logging endpoint on a Fastly service version").Alias("add")

c.CmdClause.Flag("name", "The name of the Honeycomb logging object. Used as a primary key for API access").Short('n').Required().StringVar(&c.EndpointName)
c.CmdClause.Flag("service-id", "Service ID").Short('s').StringVar(&c.manifest.Flag.ServiceID)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Version)

c.CmdClause.Flag("dataset", "The Honeycomb Dataset you want to log to").Required().StringVar(&c.Dataset)
c.CmdClause.Flag("auth-token", "The Write Key from the Account page of your Honeycomb account").Required().StringVar(&c.Token)

c.CmdClause.Flag("format", "Apache style log formatting. Your log must produce valid JSON that Honeycomb can ingest").Action(c.Format.Set).StringVar(&c.Format.Value)
c.CmdClause.Flag("format-version", "The version of the custom logging format used for the configured endpoint. Can be either 2 (default) or 1").Action(c.FormatVersion.Set).UintVar(&c.FormatVersion.Value)
c.CmdClause.Flag("response-condition", "The name of an existing condition in the configured endpoint, or leave blank to always execute").Action(c.ResponseCondition.Set).StringVar(&c.ResponseCondition.Value)
c.CmdClause.Flag("placement", "Where in the generated VCL the logging call should be placed, overriding any format_version default. Can be none or waf_debug").Action(c.Placement.Set).StringVar(&c.Placement.Value)

return &c
}

// createInput transforms values parsed from CLI flags into an object to be used by the API client library.
func (c *CreateCommand) createInput() (*fastly.CreateHoneycombInput, error) {
var input fastly.CreateHoneycombInput

serviceID, source := c.manifest.ServiceID()
if source == manifest.SourceUndefined {
return nil, errors.ErrNoServiceID
}

input.Service = serviceID
input.Version = c.Version
input.Name = fastly.String(c.EndpointName)
input.Token = fastly.String(c.Token)
input.Dataset = fastly.String(c.Dataset)

if c.Format.Valid {
input.Format = fastly.String(c.Format.Value)
}

if c.FormatVersion.Valid {
input.FormatVersion = fastly.Uint(c.FormatVersion.Value)
}

if c.ResponseCondition.Valid {
input.ResponseCondition = fastly.String(c.ResponseCondition.Value)
}

if c.Placement.Valid {
input.Placement = fastly.String(c.Placement.Value)
}

return &input, nil
}

// Exec invokes the application logic for the command.
func (c *CreateCommand) Exec(in io.Reader, out io.Writer) error {
input, err := c.createInput()
if err != nil {
return err
}

d, err := c.Globals.Client.CreateHoneycomb(input)
if err != nil {
return err
}

text.Success(out, "Created Honeycomb logging endpoint %s (service %s version %d)", d.Name, d.ServiceID, d.Version)
return nil
}
47 changes: 47 additions & 0 deletions pkg/logging/honeycomb/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package honeycomb

import (
"io"

"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/compute/manifest"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/fastly"
)

// DeleteCommand calls the Fastly API to delete Honeycomb logging endpoints.
type DeleteCommand struct {
common.Base
manifest manifest.Data
Input fastly.DeleteHoneycombInput
}

// NewDeleteCommand returns a usable command registered under the parent.
func NewDeleteCommand(parent common.Registerer, globals *config.Data) *DeleteCommand {
var c DeleteCommand
c.Globals = globals
c.manifest.File.Read(manifest.Filename)
c.CmdClause = parent.Command("delete", "Delete a Honeycomb logging endpoint on a Fastly service version").Alias("remove")
c.CmdClause.Flag("service-id", "Service ID").Short('s').StringVar(&c.manifest.Flag.ServiceID)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.Version)
c.CmdClause.Flag("name", "The name of the Honeycomb logging object").Short('n').Required().StringVar(&c.Input.Name)
return &c
}

// Exec invokes the application logic for the command.
func (c *DeleteCommand) Exec(in io.Reader, out io.Writer) error {
serviceID, source := c.manifest.ServiceID()
if source == manifest.SourceUndefined {
return errors.ErrNoServiceID
}
c.Input.Service = serviceID

if err := c.Globals.Client.DeleteHoneycomb(&c.Input); err != nil {
return err
}

text.Success(out, "Deleted Honeycomb logging endpoint %s (service %s version %d)", c.Input.Name, c.Input.Service, c.Input.Version)
return nil
}
57 changes: 57 additions & 0 deletions pkg/logging/honeycomb/describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package honeycomb

import (
"fmt"
"io"

"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/compute/manifest"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/go-fastly/fastly"
)

// DescribeCommand calls the Fastly API to describe a Honeycomb logging endpoint.
type DescribeCommand struct {
common.Base
manifest manifest.Data
Input fastly.GetHoneycombInput
}

// NewDescribeCommand returns a usable command registered under the parent.
func NewDescribeCommand(parent common.Registerer, globals *config.Data) *DescribeCommand {
var c DescribeCommand
c.Globals = globals
c.manifest.File.Read(manifest.Filename)
c.CmdClause = parent.Command("describe", "Show detailed information about a Honeycomb logging endpoint on a Fastly service version").Alias("get")
c.CmdClause.Flag("service-id", "Service ID").Short('s').StringVar(&c.manifest.Flag.ServiceID)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.Version)
c.CmdClause.Flag("name", "The name of the Honeycomb logging object").Short('d').Required().StringVar(&c.Input.Name)
return &c
}

// Exec invokes the application logic for the command.
func (c *DescribeCommand) Exec(in io.Reader, out io.Writer) error {
serviceID, source := c.manifest.ServiceID()
if source == manifest.SourceUndefined {
return errors.ErrNoServiceID
}
c.Input.Service = serviceID

honeycomb, err := c.Globals.Client.GetHoneycomb(&c.Input)
if err != nil {
return err
}

fmt.Fprintf(out, "Service ID: %s\n", honeycomb.ServiceID)
fmt.Fprintf(out, "Version: %d\n", honeycomb.Version)
fmt.Fprintf(out, "Name: %s\n", honeycomb.Name)
fmt.Fprintf(out, "Dataset: %s\n", honeycomb.Dataset)
fmt.Fprintf(out, "Token: %s\n", honeycomb.Token)
fmt.Fprintf(out, "Format: %s\n", honeycomb.Format)
fmt.Fprintf(out, "Format version: %d\n", honeycomb.FormatVersion)
fmt.Fprintf(out, "Response condition: %s\n", honeycomb.ResponseCondition)
fmt.Fprintf(out, "Placement: %s\n", honeycomb.Placement)

return nil
}
3 changes: 3 additions & 0 deletions pkg/logging/honeycomb/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package honeycomb contains commands to inspect and manipulate Fastly service Honeycomb
// logging endpoints.
package honeycomb
Loading

0 comments on commit efbd4c6

Please sign in to comment.