-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Application Signals Service Level Objective Table (#2291)
Co-authored-by: ParthaI <[email protected]>
- Loading branch information
1 parent
84b9d84
commit 391ecaa
Showing
6 changed files
with
272 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
185 changes: 185 additions & 0 deletions
185
aws/table_aws_application_signals_service_level_objective.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
"github.com/aws/aws-sdk-go-v2/service/applicationsignals" | ||
applicationsignalsv1 "github.com/aws/aws-sdk-go/service/applicationsignals" | ||
"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"}, | ||
KeyColumns: plugin.AllColumns([]string{"arn", "name"}), | ||
}, | ||
List: &plugin.ListConfig{ | ||
Hydrate: listApplicationSignalsServiceLevelObjectives, | ||
Tags: map[string]string{"service": "application-signals", "action": "ListApplicationSignalsServiceLevelObjectives"}, | ||
}, | ||
HydrateConfig: []plugin.HydrateConfig{ | ||
{ | ||
Func: getApplicationSignalsServiceLevelObjective, | ||
Tags: map[string]string{"service": "application-signals", "action": "GetApplicationSignalsServiceLevelObjective"}, | ||
}, | ||
}, | ||
GetMatrixItemFunc: SupportedRegionMatrix(applicationsignalsv1.EndpointsID), | ||
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) | ||
|
||
// Unsupported region check | ||
if svc == nil { | ||
return nil, nil | ||
} | ||
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 { | ||
maxItems = int32(limit) | ||
} | ||
} | ||
|
||
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) | ||
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) | ||
|
||
// Unsupported region check | ||
if svc == nil { | ||
return nil, nil | ||
} | ||
|
||
// Unsupported region check | ||
if svc == nil { | ||
return nil, nil | ||
} | ||
if err != nil { | ||
plugin.Logger(ctx).Error("aws_application_signals_service_level_objective.getApplicationSignalsServiceLevelObjective", "client_error", err) | ||
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) | ||
return nil, err | ||
} | ||
|
||
return item.Slo, nil | ||
} |
58 changes: 58 additions & 0 deletions
58
docs/tables/aws_application_signals_service_level_objective.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
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 | ||
|
||
### Basic info | ||
|
||
```sql+postgres | ||
select | ||
arn, | ||
name, | ||
attainment_goal, | ||
goal, | ||
from | ||
aws_application_signals_service_level_objective; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
arn, | ||
name, | ||
attainment_goal, | ||
goal, | ||
from | ||
aws_application_signals_service_level_objective; | ||
``` | ||
|
||
### List service level objectives with select service level indicator details | ||
|
||
```sql+postgres | ||
select | ||
arn, | ||
name, | ||
sli::json -> 'ComparisonOperator' as "Must Be", | ||
sli::json -> 'MetricThreshold' as "Threshold" | ||
region | ||
from | ||
aws_application_signals_service_level_objective; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
arn, | ||
name, | ||
json_extract(sli, '$.ComparisonOperator') as "Must Be", | ||
json_extract(sli, '$.MetricThreshold') as "Threshold" | ||
region | ||
from | ||
aws_application_signals_service_level_objective | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters