utils

package
v0.0.0-...-86a5277 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT-0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ERROR_CONFIGURATION_S3_BUCKET_NAME_PREFIX = "error-configuration-sample-s3-bucket-"
	SQ_DATABASE_NAME                          = "sq_result_database_multi"
	SQ_TABLE_NAME                             = "sq_result_table"
	DATABASE_NAME                             = "devops_multi_sample_application"
	TABLE_NAME                                = "host_metrics_sample_application"
	REGION                                    = "us-east-1"
	SAMPLE_DATA_CSV_FILE_PATH                 = "../data/sample-multi.csv"

	ROLE_NAME   = "ScheduledQuerySampleApplicationRole"
	POLICY_NAME = "SampleApplicationExecutionAccess"
	HOSTNAME    = "host-24Gju"
	SQ_NAME     = "daily-sample"

	// schedule running every minute
	SCHEDULE_EXPRESSION = "cron(0/1 * * * ? *)"
	VALID_QUERY         = "SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp, " +
		"ROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization, " +
		"ROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization, " +
		"ROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization, " +
		"ROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization " +
		"FROM %s.%s " +
		"WHERE measure_name = 'metrics' " +
		"AND hostname = '" + HOSTNAME + "' " +
		"AND time > ago(2h) " +
		"GROUP BY region, hostname, az, BIN(time, 15s) " +
		"ORDER BY binned_timestamp ASC " +
		"LIMIT 5"
	INVALID_QUERY = "SELECT cast('2030-12-16' as TIMESTAMP) as timestamp, 1.0 as random_measure_value, '1' as dim0"

	SCHEDULED_QUERY_CREATING = "SCHEDULED_QUERY_CREATING" // scheduled query is being created
	SCHEDULED_QUERY_CREATED  = "SCHEDULED_QUERY_CREATED"  // for successful scheduled query creation
	SCHEDULED_QUERY_UPDATED  = "SCHEDULED_QUERY_UPDATED"  // for successful scheduled query update
	SCHEDULED_QUERY_DELETED  = "SCHEDULED_QUERY_DELETED"  // for successful scheduled query deletion
	AUTO_TRIGGER_SUCCESS     = "AUTO_TRIGGER_SUCCESS"     // for successful completion of scheduled query
	AUTO_TRIGGER_FAILURE     = "AUTO_TRIGGER_FAILURE"     // for failures of scheduled query
	MANUAL_TRIGGER_SUCCESS   = "MANUAL_TRIGGER_SUCCESS"   // for successful completion of manual execution
	MANUAL_TRIGGER_FAILURE   = "MANUAL_TRIGGER_FAILURE"   // for failed manual execution

)
View Source
const (
	POLICY_DOCUMENT = "{" +
		"  \"Version\": \"2012-10-17\"," +
		"  \"Statement\": [" +
		"    {" +
		"        \"Action\": [" +
		"            \"kms:Decrypt\"," +
		"            \"sns:Publish\"," +
		"            \"timestream:describeEndpoints\"," +
		"            \"timestream:Select\"," +
		"            \"timestream:SelectValues\"," +
		"            \"timestream:WriteRecords\"," +
		"            \"s3:PutObject\"" +
		"       ]," +
		"       \"Resource\": \"*\"," +
		"       \"Effect\": \"Allow\"" +
		"    }" +
		"   ]" +
		"}"

	SQS_POLICY_FORMAT = "{" +
		"\"Version\":\"2012-10-17\"," +
		"\"Statement\": [" +
		"   {" +
		"       \"Sid\":\"topic-subscription-%s\", " +
		"       \"Effect\": \"Allow\", " +
		"       \"Principal\":{\"AWS\":\"*\"}, " +
		"       \"Action\": \"sqs:SendMessage\", " +
		"       \"Resource\": \"%s\", " +
		"       \"Condition\":{" +
		"           \"ArnEquals\":{" +
		"               \"aws:SourceArn\":\"%s\"" +
		"           }" +
		"       }" +
		"   }" +
		"  ]" +
		"}"

	ROLE_POLICY_FORMAT = "{" +
		"\"Version\":\"2012-10-17\"," +
		"\"Statement\":[" +
		"   {" +
		"       \"Effect\":\"Allow\"," +
		"       \"Principal\":{" +
		"            \"Service\": \"timestream.amazonaws.com\"" +
		"       }," +
		"       \"Action\":\"sts:AssumeRole\"" +
		"   }" +
		"  ]" +
		"}"
)

Variables

This section is empty.

Functions

func Check

func Check(e error)

func CleanUp

func CleanUp(timestreamBuilder TimestreamBuilder, timestreamDependencyHelper TimestreamDependencyHelper,
	databaseName string, tableName string, s3BucketName string)

func FileExists

func FileExists(name string) (bool, error)

func GenerateRandomStringWithSize

func GenerateRandomStringWithSize(size int) string

func GetRecordsWithMultiMeasures

func GetRecordsWithMultiMeasures(dimensions []types.Dimension) []types.Record

func GetRecordsWithMultiMeasuresMultipleRecords

func GetRecordsWithMultiMeasuresMultipleRecords(dimensions []types.Dimension) []types.Record

func HandleError

func HandleError(err error, errorMessage string, exitFlag bool)

func IngestToTimestream

func IngestToTimestream(writeSvc *timestreamwrite.Client,
	writeRecordsInputMulti *timestreamwrite.WriteRecordsInput,
	message string)

func JsonMarshalIgnoreError

func JsonMarshalIgnoreError(input interface{}) string

func LoadHttpSettings

func LoadHttpSettings() *http.Transport

func ParseQueryResult

func ParseQueryResult(queryResponse *timestreamquery.QueryOutput, f *os.File)

func RunQuery

func RunQuery(queryPtr *string, querySvc *timestreamquery.Client, f *os.File, maxRows int32) error

func Write

func Write(f *os.File, s string)

Types

type NotificationMessage

type NotificationMessage struct {
	ParseFlag         bool
	TopicArn          string `json:"TopicArn"`
	ReceiptHandle     string
	MessageAttributes struct {
		QueryArn struct {
			Type  string `json:"type"`
			Value string `json:"value"`
		} `json:"queryArn"`
		NotificationType struct {
			Type  string `json:"type"`
			Value string `json:"value"`
		} `json:"notificationType"`
	} `json:"MessageAttributes"`
	Type          string `json:"Type"`
	MessageString string `json:"Message"`
	Message       struct {
		Type                      string `json:"type"`
		Arn                       string `json:"arn"`
		NextInvocationEpochSecond int64  `json:"NextInvocationEpochSecond"`
		ScheduledQueryRunSummary  struct {
			FailureReason         string `json:"failureReason"`
			RunStatus             string `json:"runStatus"`
			InvocationEpochSecond int64  `json:"invocationEpochSecond"`
			TriggerTimeMillis     int64  `json:"triggerTimeMillis"`
			ErrorReportLocation   struct {
				S3ReportLocation struct {
					BucketName string `json:"bucketName"`
					ObjectKey  string `json:"objectKey"`
				} `json:"s3ReportLocation"`
				ExecutionStats map[string]interface{} `json:"executionStats"`
			} `json:"errorReportLocation"`
		} `json:"scheduledQueryRunSummary"`
	}
}

type Resource

type Resource struct {
	Type              string
	Identifier        string
	AdditionalDetails string
}

type TimestreamBuilder

type TimestreamBuilder struct {
	WriteSvc *timestreamwrite.Client
	QuerySvc *timestreamquery.Client
}

func (TimestreamBuilder) CreateDatabase

func (timestreamBuilder TimestreamBuilder) CreateDatabase(databaseName string) error

func (TimestreamBuilder) CreateInvalidScheduledQuery

func (timestreamBuilder TimestreamBuilder) CreateInvalidScheduledQuery(topicArn string, roleArn string,
	s3ErrorReportBucketName string, sqDatabaseName string, sqTableName string) (string, error)

func (TimestreamBuilder) CreateScheduledQuery

func (timestreamBuilder TimestreamBuilder) CreateScheduledQuery(topicArn string, roleArn string, s3ErrorReportBucketName string,
	query string, targetConfiguration qtypes.TargetConfiguration) (string, error)

func (TimestreamBuilder) CreateTable

func (timestreamBuilder TimestreamBuilder) CreateTable(databaseName string, tableName string, s3BucketName string) error

func (TimestreamBuilder) CreateValidScheduledQuery

func (timestreamBuilder TimestreamBuilder) CreateValidScheduledQuery(topicArn string, roleArn string, s3ErrorReportBucketName string,
	sqDatabaseName string, sqTableName string, databaseName string, tableName string) (string, error)

func (TimestreamBuilder) DeleteDatabase

func (timestreamBuilder TimestreamBuilder) DeleteDatabase(databaseName string) error

func (TimestreamBuilder) DeleteScheduledQuery

func (timestreamBuilder TimestreamBuilder) DeleteScheduledQuery(scheduledQueryArn string) error

func (TimestreamBuilder) DeleteTable

func (timestreamBuilder TimestreamBuilder) DeleteTable(databaseName string, tableName string) error

func (TimestreamBuilder) DescribeDatabase

func (timestreamBuilder TimestreamBuilder) DescribeDatabase(databaseName string) error

func (TimestreamBuilder) DescribeScheduledQuery

func (timestreamBuilder TimestreamBuilder) DescribeScheduledQuery(scheduledQueryArn string) error

func (TimestreamBuilder) DescribeTable

func (timestreamBuilder TimestreamBuilder) DescribeTable(databaseName string, tableName string) (*timestreamwrite.DescribeTableOutput, error)

func (TimestreamBuilder) ExecuteScheduledQuery

func (timestreamBuilder TimestreamBuilder) ExecuteScheduledQuery(scheduledQueryArn string, invocationTime time.Time) error

func (TimestreamBuilder) IngestRecordsFromCsv

func (timestreamBuilder TimestreamBuilder) IngestRecordsFromCsv(testFileName string, databaseName string,
	tableName string) error

func (TimestreamBuilder) ListDatabases

func (timestreamBuilder TimestreamBuilder) ListDatabases(maxResultCount int32) error

func (TimestreamBuilder) ListScheduledQueries

func (timestreamBuilder TimestreamBuilder) ListScheduledQueries() ([]qtypes.ScheduledQuery, error)

func (TimestreamBuilder) ListTables

func (timestreamBuilder TimestreamBuilder) ListTables(databaseName string, maxResultCount int32) error

func (TimestreamBuilder) QueryWithQueryString

func (timestreamBuilder TimestreamBuilder) QueryWithQueryString(queryString string) (*timestreamquery.QueryOutput, error)

func (TimestreamBuilder) UpdateDatabase

func (timestreamBuilder TimestreamBuilder) UpdateDatabase(databaseName *string, kmsKeyId *string) error

func (TimestreamBuilder) UpdateScheduledQuery

func (timestreamBuilder TimestreamBuilder) UpdateScheduledQuery(scheduledQueryArn string) error

func (TimestreamBuilder) UpdateTable

func (timestreamBuilder TimestreamBuilder) UpdateTable(databaseName string, tableName string) error

type TimestreamDependencyHelper

type TimestreamDependencyHelper struct {
	SnsSvc *sns.Client
	SqsSvc *sqs.Client
	S3Svc  *s3.Client
	IamSvc *iam.Client
	StsSvc *sts.Client
}

func (TimestreamDependencyHelper) AttachIamPolicy

func (timestreamDependencyHelper TimestreamDependencyHelper) AttachIamPolicy(roleName string, policyArn string) error

func (TimestreamDependencyHelper) CreateIamPolicy

func (timestreamDependencyHelper TimestreamDependencyHelper) CreateIamPolicy(policyName string) (string, error)

func (TimestreamDependencyHelper) CreateIamRole

func (timestreamDependencyHelper TimestreamDependencyHelper) CreateIamRole(roleName string) (string, error)

func (TimestreamDependencyHelper) CreateS3Bucket

func (timestreamDependencyHelper TimestreamDependencyHelper) CreateS3Bucket(bucketName string, region string) error

func (TimestreamDependencyHelper) CreateSnsTopic

func (timestreamDependencyHelper TimestreamDependencyHelper) CreateSnsTopic(topicName string) (string, error)

func (TimestreamDependencyHelper) CreateSqsQueue

func (timestreamDependencyHelper TimestreamDependencyHelper) CreateSqsQueue(queueName string) (string, error)

func (TimestreamDependencyHelper) DeleteIamPolicy

func (timestreamDependencyHelper TimestreamDependencyHelper) DeleteIamPolicy(policyArn string) error

func (TimestreamDependencyHelper) DeleteIamRole

func (timestreamDependencyHelper TimestreamDependencyHelper) DeleteIamRole(roleName string) error

func (TimestreamDependencyHelper) DeleteMessage

func (timestreamDependencyHelper TimestreamDependencyHelper) DeleteMessage(queueUrl string, receiptHandle string) error

func (TimestreamDependencyHelper) DeleteS3Bucket

func (timestreamDependencyHelper TimestreamDependencyHelper) DeleteS3Bucket(bucketName string) error

func (TimestreamDependencyHelper) DeleteSnsTopic

func (timestreamDependencyHelper TimestreamDependencyHelper) DeleteSnsTopic(topicArn string) error

func (TimestreamDependencyHelper) DeleteSqsQueue

func (timestreamDependencyHelper TimestreamDependencyHelper) DeleteSqsQueue(queueUrl string) error

func (TimestreamDependencyHelper) DetachIamPolicy

func (timestreamDependencyHelper TimestreamDependencyHelper) DetachIamPolicy(roleName string, policyArn string) error

func (TimestreamDependencyHelper) GetSqsQueryUrl

func (timestreamDependencyHelper TimestreamDependencyHelper) GetSqsQueryUrl(queueName string) (string, error)

func (TimestreamDependencyHelper) GetSqsQueueArn

func (timestreamDependencyHelper TimestreamDependencyHelper) GetSqsQueueArn(queueUrl string) (string, error)

func (TimestreamDependencyHelper) ParseS3ErrorReport

func (timestreamDependencyHelper TimestreamDependencyHelper) ParseS3ErrorReport(s3ErrorReportBucketName string,
	errorReportPrefix string) error

func (TimestreamDependencyHelper) ReceiveMessage

func (timestreamDependencyHelper TimestreamDependencyHelper) ReceiveMessage(queueUrl string) (NotificationMessage, error)

func (TimestreamDependencyHelper) S3BucketExists

func (timestreamDependencyHelper TimestreamDependencyHelper) S3BucketExists(bucketName string) (bool, error)

func (TimestreamDependencyHelper) SetSqsAccessPolicy

func (timestreamDependencyHelper TimestreamDependencyHelper) SetSqsAccessPolicy(queueUrl string, topicArn string, queueArn string) error

func (TimestreamDependencyHelper) SubscribeToSnsTopic

func (timestreamDependencyHelper TimestreamDependencyHelper) SubscribeToSnsTopic(topicArn string, queueArn string) (string, error)

func (TimestreamDependencyHelper) UnsubscribeToSnsTopic

func (timestreamDependencyHelper TimestreamDependencyHelper) UnsubscribeToSnsTopic(subscriptionArn string) error

Jump to

Keyboard shortcuts

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