Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Application Signals Service Level Objective Table #2291

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c30e534
Add application signals package
johnlayton Sep 2, 2024
10c3f80
Add application signals service level objective table
johnlayton Sep 2, 2024
a5a8c32
Add basic table documentation
johnlayton Sep 2, 2024
06b8364
Update basic table documentation
johnlayton Sep 2, 2024
01153d9
Update aws/table_aws_application_signals_service_level_objective.go
johnlayton Sep 4, 2024
71fa7a0
Update code based on PR comments;
johnlayton Sep 4, 2024
42cb587
Revert "Add application signals package"
johnlayton Sep 4, 2024
95d856a
Revert change to project dependencies
johnlayton Sep 4, 2024
8bcc5ca
Update aws/table_aws_application_signals_service_level_objective.go
johnlayton Sep 4, 2024
8b20b90
Update aws/table_aws_application_signals_service_level_objective.go
johnlayton Sep 4, 2024
1dc7bcd
Update aws/table_aws_application_signals_service_level_objective.go
johnlayton Sep 4, 2024
4241701
Update aws/table_aws_application_signals_service_level_objective.go
johnlayton Sep 4, 2024
5f4baac
Update aws/table_aws_application_signals_service_level_objective.go
johnlayton Sep 4, 2024
1061f1e
Merge branch 'turbot:main' into application_signals
johnlayton Sep 4, 2024
2aa9a5c
Update project dependencies
johnlayton Sep 4, 2024
1d1a7b9
Update table documentation to add sqlite
johnlayton Sep 4, 2024
b9ef639
Run go mod tidy
johnlayton Sep 5, 2024
f685380
Merge branch 'turbot:main' into application_signals
johnlayton Sep 17, 2024
508d4b9
Update dependencies
johnlayton Sep 17, 2024
b629224
Update dependencies
johnlayton Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion aws/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"aws_appautoscaling_policy": tableAwsAppAutoScalingPolicy(ctx),
"aws_appautoscaling_target": tableAwsAppAutoScalingTarget(ctx),
"aws_appconfig_application": tableAwsAppConfigApplication(ctx),
"aws_application_signals_service_level_objective": tableAwsApplicationSignalsServiceLevelObjective(ctx),
"aws_appstream_fleet": tableAwsAppStreamFleet(ctx),
"aws_appstream_image": tableAwsAppStreamImage(ctx),
"aws_appsync_graphql_api": tableAwsAppsyncGraphQLApi(ctx),
Expand Down Expand Up @@ -467,7 +468,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"aws_securityhub_hub": tableAwsSecurityHub(ctx),
"aws_securityhub_insight": tableAwsSecurityHubInsight(ctx),
"aws_securityhub_member": tableAwsSecurityHubMember(ctx),
"aws_securityhub_enabled_product_subscription": tableAwsSecurityhubEnabledProductSubscription(ctx),
"aws_securityhub_enabled_product_subscription": tableAwsSecurityhubEnabledProductSubscription(ctx),
"aws_securityhub_product": tableAwsSecurityhubProduct(ctx),
"aws_securityhub_standards_control": tableAwsSecurityHubStandardsControl(ctx),
"aws_securityhub_standards_subscription": tableAwsSecurityHubStandardsSubscription(ctx),
Expand Down
9 changes: 9 additions & 0 deletions aws/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/apigatewayv2"
"github.com/aws/aws-sdk-go-v2/service/appconfig"
"github.com/aws/aws-sdk-go-v2/service/applicationautoscaling"
"github.com/aws/aws-sdk-go-v2/service/applicationsignals"
"github.com/aws/aws-sdk-go-v2/service/apprunner"
"github.com/aws/aws-sdk-go-v2/service/appstream"
"github.com/aws/aws-sdk-go-v2/service/appsync"
Expand Down Expand Up @@ -315,6 +316,14 @@ func ApplicationAutoScalingClient(ctx context.Context, d *plugin.QueryData) (*ap
return applicationautoscaling.NewFromConfig(*cfg), nil
}

func ApplicationSignalsClient(ctx context.Context, d *plugin.QueryData) (*applicationsignals.Client, error) {
cfg, err := getClientForQueryRegion(ctx, d)
johnlayton marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
return applicationsignals.NewFromConfig(*cfg), nil
}

func AppRunnerClient(ctx context.Context, d *plugin.QueryData) (*apprunner.Client, error) {
cfg, err := getClientForQuerySupportedRegion(ctx, d, appRunnerEndpoint.EndpointsID)
if err != nil {
Expand Down
174 changes: 174 additions & 0 deletions aws/table_aws_application_signals_service_level_objective.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package aws

import (
"context"
"github.com/aws/aws-sdk-go-v2/service/applicationsignals"
cloudwatchlogsv1 "github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/applicationsignals/types"

"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)

func tableAwsApplicationSignalsServiceLevelObjective(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "aws_application_signals_service_level_objective",
Description: "AWS Application Signals Service Level Objective",
Get: &plugin.GetConfig{
Hydrate: getApplicationSignalsServiceLevelObjective,
Tags: map[string]string{"service": "application_signals", "action": "GetApplicationSignalsServiceLevelObjective"},
johnlayton marked this conversation as resolved.
Show resolved Hide resolved
KeyColumns: plugin.AllColumns([]string{"arn", "name"}),
},
List: &plugin.ListConfig{
Hydrate: listApplicationSignalsServiceLevelObjectives,
Tags: map[string]string{"service": "application_signals", "action": "ListApplicationSignalsServiceLevelObjectives"},
johnlayton marked this conversation as resolved.
Show resolved Hide resolved
},
HydrateConfig: []plugin.HydrateConfig{
{
Func: getApplicationSignalsServiceLevelObjective,
Tags: map[string]string{"service": "application_signals", "action": "GetApplicationSignalsServiceLevelObjective"},
johnlayton marked this conversation as resolved.
Show resolved Hide resolved
},
},
GetMatrixItemFunc: SupportedRegionMatrix(cloudwatchlogsv1.EndpointsID),
Copy link
Author

@johnlayton johnlayton Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query, how do I identify regions supported by this application_signals service?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @johnlayton,

Thank you for your contribution! 🎉

In this plugin, we are currently using AWS Go SDK v1, specifically version v1.51.19. Unfortunately, in this version, the AWS Application Signals service is not yet available. After reviewing the AWS Go SDK v1 repository, I found that support for this service was added in version v1.53.20.

To use the EndpointID of the Application Signals service, we would need to update the AWS Go SDK v1 to v1.53.20. This would enable us to leverage the EndpointID reference.

Alternatively, if we prefer not to update the AWS SDK v1, we could potentially use a hardcoded value (application-signals) to retrieve the supported regions for the Application Signals service. However, I’m not entirely certain if using a hardcoded value would fully resolve the issue in listing supported regions for the service.

Please let us know what works best for you.

Thanks again!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feedback. Just to confirm (I am new to Go) the go.mod and go.sum changes need to be reverted except for adding github.com/aws/aws-sdk-go-v2/service/applicationsignals v1.3.1?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @johnlayton,

I noticed that the current package version we are using in the AWS plugin (v1.27.0) already supports the applicationsignals service. Therefore, there’s no need to update AWS SDK V2 to support this table.

However, for the service endpoint reference, we may need to update AWS SDK V1 to version v1.53.20.

To resolve this, you can follow the steps outlined below:

  1. Revert the AWS SDK V2 to v1.27.0 by running the command: go get github.com/aws/[email protected].
  2. Update AWS SDK V1 to v1.53.20 to obtain the endpoint ID reference by running the command: go get github.com/aws/[email protected].
  3. Replace the hardcoded endpoint ID value here.
  4. Make any necessary adjustments to the aws_application_signals_service_level_objective table, depending on the API behavior, if required.

Please let me know if you need any further clarification.

Thanks!

Copy link
Author

@johnlayton johnlayton Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. I updated the dependencies as suggested. I still see changes to configsources and endpoints, and the linting fails. Is this expected or am I still missing something?

Is it related to this comment -> #2291 (review)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @johnlayton, thank you so much for your efforts and contribution! I’ve merged the PR into a branch.

The lint failure was caused by the use of the deprecated function EndpointResolverWithOptionsFunc with AWS SDK V2 version 1.30.5.

I'll look into resolving it.

Columns: awsRegionalColumns([]*plugin.Column{
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) of the service level objective.",
Type: proto.ColumnType_STRING,
},
{
Name: "name",
Description: "The name of the service level objective.",
Type: proto.ColumnType_STRING,
},
{
Name: "attainment_goal",
Description: "The attainment goal of the service level objective.",
Type: proto.ColumnType_DOUBLE,
Hydrate: getApplicationSignalsServiceLevelObjective,
Transform: transform.FromField("Goal.AttainmentGoal"),
},
{
Name: "goal",
Description: "The goal of the service level objective.",
Type: proto.ColumnType_JSON,
Hydrate: getApplicationSignalsServiceLevelObjective,
},
{
Name: "sli",
Description: "The sli of the service level objective.",
Type: proto.ColumnType_JSON,
Hydrate: getApplicationSignalsServiceLevelObjective,
},
//// Steampipe Standard Columns
//{
// Name: "tags",
// Description: resourceInterfaceDescription("tags"),
// Type: proto.ColumnType_JSON,
// Hydrate: getLogGroupTagging,
//},
{
Name: "akas",
Description: resourceInterfaceDescription("akas"),
Type: proto.ColumnType_JSON,
Transform: transform.FromField("Arn").Transform(arnToAkas),
},
}),
}
}

//// LIST FUNCTION

func listApplicationSignalsServiceLevelObjectives(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
svc, err := ApplicationSignalsClient(ctx, d)
johnlayton marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
plugin.Logger(ctx).Error("aws_application_signals_service_level_objective.listApplicationSignalsServiceLevelObjectives", "client_error", err)
return nil, err
}

maxItems := int32(50)

// Reduce the basic request limit down if the user has only requested a small number
if d.QueryContext.Limit != nil {
limit := int32(*d.QueryContext.Limit)
if limit < maxItems {
if limit < 1 {
maxItems = int32(1)
} else {
maxItems = int32(limit)
}
}
johnlayton marked this conversation as resolved.
Show resolved Hide resolved
}

input := &applicationsignals.ListServiceLevelObjectivesInput{
MaxResults: &maxItems,
}

paginator := applicationsignals.NewListServiceLevelObjectivesPaginator(svc, input, func(o *applicationsignals.ListServiceLevelObjectivesPaginatorOptions) {
o.Limit = maxItems
o.StopOnDuplicateToken = true
})

for paginator.HasMorePages() {
// apply rate limiting
d.WaitForListRateLimit(ctx)

output, err := paginator.NextPage(ctx)
if err != nil {
plugin.Logger(ctx).Error("aws_application_signals_service_level_objective.listApplicationSignalsServiceLevelObjectives", "api_error", err)
johnlayton marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}

for _, sloSummary := range output.SloSummaries {
d.StreamListItem(ctx, sloSummary)

// Context may get cancelled due to manual cancellation or if the limit has been reached
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
}

return nil, nil
}

//// HYDRATE FUNCTIONS

func getApplicationSignalsServiceLevelObjective(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
arn := ""

if h.Item != nil {
data := h.Item.(types.ServiceLevelObjectiveSummary)
arn = *data.Arn
} else {
arn = d.EqualsQualString("arn")
}

// check if name is empty
if strings.TrimSpace(arn) == "" {
return nil, nil
}

// Get client
svc, err := ApplicationSignalsClient(ctx, d)
johnlayton marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
plugin.Logger(ctx).Error("aws_application_signals_service_level_objective.getApplicationSignalsServiceLevelObjective", "client_error", err)
johnlayton marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}

params := &applicationsignals.GetServiceLevelObjectiveInput{
Id: aws.String(arn),
}

item, err := svc.GetServiceLevelObjective(ctx, params)
if err != nil {
plugin.Logger(ctx).Error("aws_application_signals_service_level_objective.getApplicationSignalsServiceLevelObjective", "api_error", err)
johnlayton marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}

return item.Slo, nil
}
33 changes: 33 additions & 0 deletions docs/tables/aws_application_signals_service_level_objective.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: "Steampipe Table: aws_application_signals_service_level_objective - Query AWS Application Signals using SQL"
description: "Allows users to query AWS Application Signals to retrieve detailed information about each SLO, including its name, ARN, attainment_goal, goal and sli."
---

# Table: aws_application_signals_service_level_objective - Query AWS Application Signals Service Level Objective using SQL

## Table Usage Guide

The `aws_application_signals_service_level_objective` table in Steampipe provides you with information about SLOs within AWS Application Signals. This table allows you to query SLO details, including the name, ARN, attainment_goal, goal and sli, and associated metadata.

## Examples

```sql+postgres
select
arn,
name,
attainment_goal,
goal,
from
aws_application_signals_service_level_objective
```
johnlayton marked this conversation as resolved.
Show resolved Hide resolved

```sql+postgres
select
arn,
name,
sli::json -> 'ComparisonOperator' as "Must Be",
sli::json -> 'MetricThreshold' as "Threshold"
region
from
aws_application_signals_service_level_objective
```
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.6

require (
github.com/aws/aws-sdk-go v1.51.19
github.com/aws/aws-sdk-go-v2 v1.27.0
github.com/aws/aws-sdk-go-v2 v1.30.4
github.com/aws/aws-sdk-go-v2/config v1.27.16
github.com/aws/aws-sdk-go-v2/credentials v1.17.16
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.21
Expand All @@ -19,6 +19,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/apigatewayv2 v1.20.4
github.com/aws/aws-sdk-go-v2/service/appconfig v1.29.2
github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.27.4
github.com/aws/aws-sdk-go-v2/service/applicationsignals v1.3.1
github.com/aws/aws-sdk-go-v2/service/apprunner v1.28.8
github.com/aws/aws-sdk-go-v2/service/appstream v1.34.4
github.com/aws/aws-sdk-go-v2/service/appsync v1.31.4
Expand Down Expand Up @@ -166,8 +167,8 @@ require (
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.7 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.7 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ github.com/aws/aws-sdk-go v1.51.19 h1:jp/Vx/mUpXttthvvo/4/Nn/3+zumirIlAFkp1Irf1k
github.com/aws/aws-sdk-go v1.51.19/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go-v2 v1.27.0 h1:7bZWKoXhzI+mMR/HjdMx8ZCC5+6fY0lS5tr0bbgiLlo=
github.com/aws/aws-sdk-go-v2 v1.27.0/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
github.com/aws/aws-sdk-go-v2 v1.30.4 h1:frhcagrVNrzmT95RJImMHgabt99vkXGslubDaDagTk8=
github.com/aws/aws-sdk-go-v2 v1.30.4/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2/go.mod h1:lPprDr1e6cJdyYeGXnRaJoP4Md+cDBvi2eOj00BlGmg=
github.com/aws/aws-sdk-go-v2/config v1.27.16 h1:knpCuH7laFVGYTNd99Ns5t+8PuRjDn4HnnZK48csipM=
Expand All @@ -219,8 +221,12 @@ github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.21 h1:1v8Ii0MRVGYB/sdhkbxr
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.21/go.mod h1:cxdd1rc8yxCjKz28hi30XN1jDXr2DxZvD44vLxTz/bg=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.7 h1:lf/8VTF2cM+N4SLzaYJERKEWAXq8MOMpZfU6wEPWsPk=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.7/go.mod h1:4SjkU7QiqK2M9oozyMzfZ/23LmUY+h3oFqhdeP5OMiI=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16 h1:TNyt/+X43KJ9IJJMjKfa3bNTiZbUP7DeCxfbTROESwY=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16/go.mod h1:2DwJF39FlNAUiX5pAc0UNeiz16lK2t7IaFcm0LFHEgc=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.7 h1:4OYVp0705xu8yjdyoWix0r9wPIRXnIzzOoUpQVHIJ/g=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.7/go.mod h1:vd7ESTEvI76T2Na050gODNmNU7+OyKrIKroYTu4ABiI=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16 h1:jYfy8UPmd+6kJW5YhY0L1/KftReOGxI/4NtVSTh9O/I=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16/go.mod h1:7ZfEPZxkW42Afq4uQB8H2E2e6ebh6mXTueEpYzjCzcs=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.7 h1:/FUtT3xsoHO3cfh+I/kCbcMCN98QZRsiFet/V8QkWSs=
Expand All @@ -243,6 +249,8 @@ github.com/aws/aws-sdk-go-v2/service/appconfig v1.29.2 h1:Nm1Pqug23c/Ib+/FgwYpFZ
github.com/aws/aws-sdk-go-v2/service/appconfig v1.29.2/go.mod h1:Z4uxjsQCQYIZQYOf5js8AN9B5ZCFfwRkEHuiihgjHWs=
github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.27.4 h1:QGG9y+wEdP5KpTbcvpi8ETAoMq0zB6UJdqJ3JmVu/Wc=
github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.27.4/go.mod h1:g7O+8ghAn49ysZShSpeOxIRiI0/BgPoqHwZFNKnykco=
github.com/aws/aws-sdk-go-v2/service/applicationsignals v1.3.1 h1:DWuMp2+NdUD2BE55Cc8Bs2rjWM3svAzkiQZUu1+2fTw=
github.com/aws/aws-sdk-go-v2/service/applicationsignals v1.3.1/go.mod h1:8n7q1kFJBVY2AMJTyyGdJg3aF/zygTeYkwjMZ+V/mBk=
github.com/aws/aws-sdk-go-v2/service/apprunner v1.28.8 h1:vTSRA431Gi6tQcUDfCTF1PwnLvw7M+7SoMWb0FRvKAY=
github.com/aws/aws-sdk-go-v2/service/apprunner v1.28.8/go.mod h1:0ClIRoMxROYgDXb/kSvAsZSO41p4j9p4xkquAFzNEjM=
github.com/aws/aws-sdk-go-v2/service/appstream v1.34.4 h1:chEtg7jpLbd+wzNEZR5Y7if5S3+zCL4HO892dk4JRHI=
Expand Down