cloudwatchlogsinsightsdriver

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2023 License: MIT Imports: 16 Imported by: 1

README

cloudwatch-logs-insights-driver

Documentation Latest GitHub tag Github Actions test Go Report Card License

Cloudwatch Logs Insights Driver for Go's database/sql package

Usage

for example:

package main

import(
	"context"
	"database/sql"
	"log"
    "time"

	_ "github.com/mashiike/cloudwatch-logs-insights-driver"
)

func main() {
	db, err := sql.Open("cloudwatch-logs-insights", "cloudwatch://?timeout=1m")
	if err != nil {
		log.Fatalln(err)
	}
	defer db.Close()
	rows, err := db.QueryContext(
		context.Background(),
		`fields @timestamp, @message | limit 10`,
		sql.Named("log_group_name", "test-log-group"),
		sql.Named("log_group_name", "test-log-group-2"),
		sql.Named("start_time", "2020-01-01T00:00:00+09:00"),
		sql.Named("end_time", "2020-01-01T23:59:59+09:00"),
	)
	if err != nil {
		log.Fatalln(err)
	}
    defer rows.Close()
	for rows.Next() {
        var timestamp time.Time
		var message string
		err := rows.Scan(&timestamp, &message)
		if err != nil {
			log.Println(err)
			return
		}
		log.Printf("%s\t%s", teimstamp, message)
	}
}

log_group_name can also be specified as cloudwatch://?log_group_name=test-log-group&timeout=1m. This is the default log group if it is not specified as a parameter at the time of query execution. If start_time and end_time are not specified, the last 15 minutes will be queried.

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSupported  = errors.New("not supported")
	ErrDSNEmpty      = errors.New("dsn is empty")
	ErrConnClosed    = errors.New("connection closed")
	ErrInvalidScheme = errors.New("invalid scheme")
)
View Source
var CloudwatchLogsClientConstructor func(ctx context.Context, cfg *CloudwatchLogsInsightsConfig) (CloudwatchLogsClient, error)

 CloudwatchLogsClientConstructor is the constructor for the Cloudwatch Logs Insights client.

Functions

func SetDebugLogger

func SetDebugLogger(l Logger) error

func SetLogger

func SetLogger(l Logger) error

Types

type CloudwatchLogsClient

type CloudwatchLogsClient interface {
	StartQuery(ctx context.Context, params *cloudwatchlogs.StartQueryInput, optFns ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.StartQueryOutput, error)
	GetQueryResults(ctx context.Context, params *cloudwatchlogs.GetQueryResultsInput, optFns ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.GetQueryResultsOutput, error)
	StopQuery(ctx context.Context, params *cloudwatchlogs.StopQueryInput, optFns ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.StopQueryOutput, error)
}

CloudwatchLogsClient is the interface for the Cloudwatch Logs Insights client.

func DefaultCloudwatchLogsClientConstructor

func DefaultCloudwatchLogsClientConstructor(ctx context.Context, cfg *CloudwatchLogsInsightsConfig) (CloudwatchLogsClient, error)

DefaultCloudwatchLogsClientConstructor is the default constructor for the Cloudwatch Logs Insights client.

type CloudwatchLogsInsightsConfig

type CloudwatchLogsInsightsConfig struct {
	OptFns        []func(*cloudwatchlogs.Options)
	Timeout       time.Duration // Default: 10s
	Polling       time.Duration // Default: 100ms
	LogGroupNames []string
	Region        string
	Limit         *int32

	Params url.Values
}

CloudwatchLogsConfig is the configuration for the Cloudwatch Logs Insights.

func ParseDSN

func ParseDSN(dsn string) (*CloudwatchLogsInsightsConfig, error)

ParseDSN is the function that constructs Config from the given DSN. For example, there is the following example. cloudwatch://?log_group_names=/aws/lambda/hoge,/aws/lambda/bar&limit=100&polling=1s&timeout=10s&region=ap-northeast-1 In this case, the following Config is constructed.

CloudwatchLogsInsightsConfig{
	OptFns:        []func(*cloudwatchlogs.Options){},
	Timeout:       10s,
	Polling:       1s,
	LogGroupNames: []string{"/aws/lambda/hoge", "/aws/lambda/bar"},
	Region:        "ap-northeast-1",
	Limit:         100,
}

Also, you can specify log_group_name instead of log_group_names. However, you can not specify log_group_name and log_group_names at the same time.

func (*CloudwatchLogsInsightsConfig) String

func (cfg *CloudwatchLogsInsightsConfig) String() string

type Logger

type Logger interface {
	Printf(format string, v ...any)
	SetOutput(w io.Writer)
	Writer() io.Writer
}

func GetDebugLogger

func GetDebugLogger() Logger

func GetLogger

func GetLogger() Logger

Jump to

Keyboard shortcuts

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