Skip to content

Commit

Permalink
feat:remove metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamadch91 committed Nov 18, 2024
1 parent 7097b68 commit 22efdc8
Show file tree
Hide file tree
Showing 45 changed files with 3 additions and 1,863 deletions.
159 changes: 1 addition & 158 deletions pkg/sdk/es/resources_clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -30704,36 +30704,10 @@ func GetEC2LaunchTemplateVersion(ctx context.Context, d *plugin.QueryData, _ *pl

// ========================== START: EC2InstanceMetricCpuUtilizationHourly =============================

type EC2InstanceMetricCpuUtilizationHourly struct {
ResourceID string `json:"resource_id"`
PlatformID string `json:"platform_id"`
Description aws.EC2InstanceMetricCpuUtilizationHourlyDescription `json:"description"`
Metadata aws.Metadata `json:"metadata"`
DescribedBy string `json:"described_by"`
ResourceType string `json:"resource_type"`
IntegrationType string `json:"integration_type"`
IntegrationID string `json:"integration_id"`
}

type EC2InstanceMetricCpuUtilizationHourlyHit struct {
ID string `json:"_id"`
Score float64 `json:"_score"`
Index string `json:"_index"`
Type string `json:"_type"`
Version int64 `json:"_version,omitempty"`
Source EC2InstanceMetricCpuUtilizationHourly `json:"_source"`
Sort []interface{} `json:"sort"`
}

type EC2InstanceMetricCpuUtilizationHourlyHits struct {
Total essdk.SearchTotal `json:"total"`
Hits []EC2InstanceMetricCpuUtilizationHourlyHit `json:"hits"`
}

type EC2InstanceMetricCpuUtilizationHourlySearchResponse struct {
PitID string `json:"pit_id"`
Hits EC2InstanceMetricCpuUtilizationHourlyHits `json:"hits"`
}


type EC2InstanceMetricCpuUtilizationHourlyPaginator struct {
paginator *essdk.BaseESPaginator
Expand All @@ -30760,27 +30734,6 @@ func (p EC2InstanceMetricCpuUtilizationHourlyPaginator) Close(ctx context.Contex
return p.paginator.Deallocate(ctx)
}

func (p EC2InstanceMetricCpuUtilizationHourlyPaginator) NextPage(ctx context.Context) ([]EC2InstanceMetricCpuUtilizationHourly, error) {
var response EC2InstanceMetricCpuUtilizationHourlySearchResponse
err := p.paginator.Search(ctx, &response)
if err != nil {
return nil, err
}

var values []EC2InstanceMetricCpuUtilizationHourly
for _, hit := range response.Hits.Hits {
values = append(values, hit.Source)
}

hits := int64(len(response.Hits.Hits))
if hits > 0 {
p.paginator.UpdateState(hits, response.Hits.Hits[hits-1].Sort, response.PitID)
} else {
p.paginator.UpdateState(hits, nil, "")
}

return values, nil
}

var listEC2InstanceMetricCpuUtilizationHourlyFilters = map[string]string{
"account_id": "Account",
Expand All @@ -30793,65 +30746,7 @@ var listEC2InstanceMetricCpuUtilizationHourlyFilters = map[string]string{
"timestamp": "Description.Timestamp",
}

func ListEC2InstanceMetricCpuUtilizationHourly(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("ListEC2InstanceMetricCpuUtilizationHourly")
runtime.GC()

// create service
cfg := essdk.GetConfig(d.Connection)
ke, err := essdk.NewClientCached(cfg, d.ConnectionCache, ctx)
if err != nil {
plugin.Logger(ctx).Error("ListEC2InstanceMetricCpuUtilizationHourly NewClientCached", "error", err)
return nil, err
}
k := Client{Client: ke}

sc, err := steampipesdk.NewSelfClientCached(ctx, d.ConnectionCache)
if err != nil {
plugin.Logger(ctx).Error("ListEC2InstanceMetricCpuUtilizationHourly NewSelfClientCached", "error", err)
return nil, err
}
accountId, err := sc.GetConfigTableValueOrNil(ctx, steampipesdk.OpenGovernanceConfigKeyAccountID)
if err != nil {
plugin.Logger(ctx).Error("ListEC2InstanceMetricCpuUtilizationHourly GetConfigTableValueOrNil for OpenGovernanceConfigKeyAccountID", "error", err)
return nil, err
}
encodedResourceCollectionFilters, err := sc.GetConfigTableValueOrNil(ctx, steampipesdk.OpenGovernanceConfigKeyResourceCollectionFilters)
if err != nil {
plugin.Logger(ctx).Error("ListEC2InstanceMetricCpuUtilizationHourly GetConfigTableValueOrNil for OpenGovernanceConfigKeyResourceCollectionFilters", "error", err)
return nil, err
}
clientType, err := sc.GetConfigTableValueOrNil(ctx, steampipesdk.OpenGovernanceConfigKeyClientType)
if err != nil {
plugin.Logger(ctx).Error("ListEC2InstanceMetricCpuUtilizationHourly GetConfigTableValueOrNil for OpenGovernanceConfigKeyClientType", "error", err)
return nil, err
}

paginator, err := k.NewEC2InstanceMetricCpuUtilizationHourlyPaginator(essdk.BuildFilter(ctx, d.QueryContext, listEC2InstanceMetricCpuUtilizationHourlyFilters, "aws", accountId, encodedResourceCollectionFilters, clientType), d.QueryContext.Limit)
if err != nil {
plugin.Logger(ctx).Error("ListEC2InstanceMetricCpuUtilizationHourly NewEC2InstanceMetricCpuUtilizationHourlyPaginator", "error", err)
return nil, err
}

for paginator.HasNext() {
page, err := paginator.NextPage(ctx)
if err != nil {
plugin.Logger(ctx).Error("ListEC2InstanceMetricCpuUtilizationHourly paginator.NextPage", "error", err)
return nil, err
}

for _, v := range page {
d.StreamListItem(ctx, v)
}
}

err = paginator.Close(ctx)
if err != nil {
return nil, err
}

return nil, nil
}

var getEC2InstanceMetricCpuUtilizationHourlyFilters = map[string]string{
"account_id": "Account",
Expand All @@ -30864,58 +30759,6 @@ var getEC2InstanceMetricCpuUtilizationHourlyFilters = map[string]string{
"timestamp": "Description.Timestamp",
}

func GetEC2InstanceMetricCpuUtilizationHourly(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("GetEC2InstanceMetricCpuUtilizationHourly")
runtime.GC()
// create service
cfg := essdk.GetConfig(d.Connection)
ke, err := essdk.NewClientCached(cfg, d.ConnectionCache, ctx)
if err != nil {
return nil, err
}
k := Client{Client: ke}

sc, err := steampipesdk.NewSelfClientCached(ctx, d.ConnectionCache)
if err != nil {
return nil, err
}
accountId, err := sc.GetConfigTableValueOrNil(ctx, steampipesdk.OpenGovernanceConfigKeyAccountID)
if err != nil {
return nil, err
}
encodedResourceCollectionFilters, err := sc.GetConfigTableValueOrNil(ctx, steampipesdk.OpenGovernanceConfigKeyResourceCollectionFilters)
if err != nil {
return nil, err
}
clientType, err := sc.GetConfigTableValueOrNil(ctx, steampipesdk.OpenGovernanceConfigKeyClientType)
if err != nil {
return nil, err
}

limit := int64(1)
paginator, err := k.NewEC2InstanceMetricCpuUtilizationHourlyPaginator(essdk.BuildFilter(ctx, d.QueryContext, getEC2InstanceMetricCpuUtilizationHourlyFilters, "aws", accountId, encodedResourceCollectionFilters, clientType), &limit)
if err != nil {
return nil, err
}

for paginator.HasNext() {
page, err := paginator.NextPage(ctx)
if err != nil {
return nil, err
}

for _, v := range page {
return v, nil
}
}

err = paginator.Close(ctx)
if err != nil {
return nil, err
}

return nil, nil
}

// ========================== END: EC2InstanceMetricCpuUtilizationHourly =============================

Expand Down
58 changes: 0 additions & 58 deletions provider/describer/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4596,61 +4596,3 @@ func eC2ManagedPrefixListEntryHandle(ctx context.Context, prefixListId string, v
return values
}

func Ec2InstanceMetricCpuUtilizationHourly(ctx context.Context, cfg aws.Config, stream *models.StreamSender) ([]models.Resource, error) {
client := ec2.NewFromConfig(cfg)
paginator := ec2.NewDescribeInstancesPaginator(client, &ec2.DescribeInstancesInput{})

var values []models.Resource
for paginator.HasMorePages() {
page, err := paginator.NextPage(ctx)
if err != nil {
return nil, err
}

for _, r := range page.Reservations {
for _, v := range r.Instances {
statistics, err := getEc2InstanceMetricCpuUtilizationHourly(ctx, cfg, v.InstanceId)
if err != nil {
return nil, err
}
for _, resource := range statistics {
if stream != nil {
if err := (*stream)(resource); err != nil {
return nil, err
}
} else {
values = append(values, resource)
}
}
}
}
}
return values, nil
}

func getEc2InstanceMetricCpuUtilizationHourly(ctx context.Context, cfg aws.Config, instanceId *string) ([]models.Resource, error) {
describeCtx := GetDescribeContext(ctx)
statistics, err := listCloudWatchMetricStatistics(ctx, cfg, "HOURLY", "AWS/EC2", "CPUUtilization", "InstanceId", *instanceId)
if err != nil {
return nil, err
}
var values []models.Resource

for _, s := range statistics {
values = append(values, models.Resource{
Account: describeCtx.AccountID,
Region: describeCtx.OGRegion,
Description: model.EC2InstanceMetricCpuUtilizationHourlyDescription{
InstanceId: instanceId,
Timestamp: s.Timestamp,
Sum: s.Sum,
Average: s.Average,
Maximum: s.Maximum,
Minimum: s.Minimum,
SampleCount: s.SampleCount,
},
})
}

return values, nil
}
10 changes: 1 addition & 9 deletions provider/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1306,15 +1306,7 @@ type EC2EIPAddressTransferDescription struct {
AddressTransfer ec2.AddressTransfer
}

type EC2InstanceMetricCpuUtilizationHourlyDescription struct {
InstanceId *string
Timestamp *time.Time
Average *float64
Sum *float64
Maximum *float64
Minimum *float64
SampleCount *float64
}


// =================== STS Caller =================

Expand Down
12 changes: 0 additions & 12 deletions provider/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2415,18 +2415,6 @@ var ResourceTypes = map[string]model.ResourceType{
GetDescriber: nil,
},

"AWS::EC2::InstanceMetricCpuUtilizationHourly": {
IntegrationType: configs.IntegrationName,
ResourceName: "AWS::EC2::InstanceMetricCpuUtilizationHourly",
Tags: map[string][]string{
"category": {"Compute"},
"logo_uri": {"https://raw.githubusercontent.com/opengovernance/awsicons/master/svg-export/icons/Ec2Instance.svg"},
},
Labels: map[string]string{},
Annotations: map[string]string{},
ListDescriber: ParallelDescribeRegional(describer.Ec2InstanceMetricCpuUtilizationHourly),
GetDescriber: nil,
},

"AWS::EC2::InstanceAvailability": {
IntegrationType: configs.IntegrationName,
Expand Down
14 changes: 1 addition & 13 deletions provider/resource_types/resource-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1742,19 +1742,7 @@
"SteampipeTable": "aws_ec2_instance",
"Model": "EC2Instance"
},
{
"ResourceName": "AWS::EC2::InstanceMetricCpuUtilizationHourly",
"Tags": {
"category": ["Compute"],
"logo_uri": [
"https://raw.githubusercontent.com/opengovernance/awsicons/master/svg-export/icons/Ec2Instance.svg"
]
},
"ListDescriber": "ParallelDescribeRegional(describer.Ec2InstanceMetricCpuUtilizationHourly)",
"GetDescriber": "nil",
"SteampipeTable": "aws_ec2_instance_metric_cpu_utilization_hourly",
"Model": "EC2InstanceMetricCpuUtilizationHourly"
},

{
"ResourceName": "AWS::EC2::InstanceAvailability",
"ListDescriber": "ParallelDescribeRegional(describer.EC2InstanceAvailability)",
Expand Down
Loading

0 comments on commit 22efdc8

Please sign in to comment.