cloudlogging

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogEntryMessage

func GetLogEntryMessage(entry *loggingpb.LogEntry) (string, error)

GetLogEntryMessage gets the message body of a LogEntry based on what kind of payload it is If it's JSON, we look for the `message` field since the other fields will be added as labels

func GetLogLabels

func GetLogLabels(entry *loggingpb.LogEntry) data.Labels

GetLogLabels flattens a log entry's labels + resource labels into a map

func GetLogLevel

func GetLogLevel(severity ltype.LogSeverity) string

GetLogLevel maps the string value of a LogSeverity to one supported by Grafana

Types

type API

type API interface {
	// ListLogs retrieves all logs matching some query filter up to the given limit
	ListLogs(context.Context, *Query) ([]*loggingpb.LogEntry, error)
	// TestConnection queries for any log from the given project
	TestConnection(ctx context.Context, projectID string) error
	// ListProjects returns the project IDs of all visible projects
	ListProjects(context.Context) ([]string, error)
	// ListProjectBuckets returns all log buckets of a project
	ListProjectBuckets(ctx context.Context, projectId string) ([]string, error)
	// ListProjectBucketViews returns all views of a log bucket
	ListProjectBucketViews(ctx context.Context, projectId string, bucketId string) ([]string, error)
	// Close closes the underlying connection to the GCP API
	Close() error
}

API implements the methods we need to query logs and list projects from GCP

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps a GCP logging client to fetch logs, a resourcemanager client to list projects, and a config client to get log bucket configurations

func NewClient

func NewClient(ctx context.Context, jsonCreds []byte) (*Client, error)

NewClient creates a new Client using jsonCreds for authentication

func NewClientWithGCE added in v1.2.0

func NewClientWithGCE(ctx context.Context) (*Client, error)

NewClient creates a new Clients using GCE metadata for authentication

func NewClientWithImpersonation added in v1.4.0

func NewClientWithImpersonation(ctx context.Context, jsonCreds []byte, impersonateSA string) (*Client, error)

NewClient creates a new Clients using service account impersonation

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying connection to the GCP API

func (*Client) ListLogs

func (c *Client) ListLogs(ctx context.Context, q *Query) ([]*loggingpb.LogEntry, error)

ListLogs retrieves all logs matching some query filter up to the given limit

func (*Client) ListProjectBucketViews added in v1.2.1

func (c *Client) ListProjectBucketViews(ctx context.Context, projectId string, bucketId string) ([]string, error)

ListProjectBucketsViews returns all views of a log bucket

func (*Client) ListProjectBuckets added in v1.2.1

func (c *Client) ListProjectBuckets(ctx context.Context, projectId string) ([]string, error)

ListProjectBuckets returns all log buckets of a project

func (*Client) ListProjects

func (c *Client) ListProjects(ctx context.Context) ([]string, error)

ListProjects returns the project IDs of all visible projects

func (*Client) TestConnection

func (c *Client) TestConnection(ctx context.Context, projectID string) error

TestConnection queries for any log from the given project

type Query

type Query struct {
	ProjectID string
	BucketId  string
	ViewId    string
	Filter    string
	Limit     int64
	TimeRange struct {
		From string
		To   string
	}
}

Query is the information from a Grafana query needed to query GCP for logs

func (*Query) String

func (q *Query) String() string

String is the query formatted for querying GCP It is the query text, with the time range constraints appended

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL