-
Notifications
You must be signed in to change notification settings - Fork 523
/
glue_job.go
91 lines (78 loc) 路 2.64 KB
/
glue_job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package aws
import (
"fmt"
"github.com/shopspring/decimal"
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
)
// GlueJob struct represents a serverless AWS Glue job. A Glue job is designed to clean, transform and merge data
// into a data lake so that it is easy to analyze.
//
// GlueJob is just one resource of the wider AWS Glue service, which provides a number of different serverless services
// to build a robust data analytics pipeline.
//
// Resource information: https://aws.amazon.com/glue/
// Pricing information: https://aws.amazon.com/glue/pricing/
type GlueJob struct {
Address string
Region string
DPUs float64
MonthlyHours *float64 `infracost_usage:"monthly_hours"`
}
func (r *GlueJob) CoreType() string {
return "GlueJob"
}
func (r *GlueJob) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{
{Key: "monthly_hours", DefaultValue: 0, ValueType: schema.Float64},
}
}
// PopulateUsage parses the u schema.UsageData into the GlueJob.
// It uses the `infracost_usage` struct tags to populate data into the GlueJob.
func (r *GlueJob) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
// BuildResource builds a schema.Resource from a valid GlueJob struct. GlueJob has just one schema.CostComponent
// associated with it:
//
// 1. DPU hours - GlueJob is charged per hour that the job is run. Users are charged based on the number of DPU
// units they use in that time.
//
// This method is called after the resource is initialised by an IaC provider. See providers folder for more information.
func (r *GlueJob) BuildResource() *schema.Resource {
var quantity *decimal.Decimal
if r.MonthlyHours != nil {
quantity = decimalPtr(decimal.NewFromFloat(*r.MonthlyHours * r.DPUs))
}
suffix := "DPUs"
if r.DPUs == 1 {
suffix = "DPU"
}
unit := fmt.Sprintf("hours (%d %s)", int(r.DPUs), suffix)
if r.DPUs > 0 && r.DPUs < 1 {
unit = fmt.Sprintf("hours (%.4f %s)", r.DPUs, suffix)
}
return &schema.Resource{
Name: r.Address,
UsageSchema: r.UsageSchema(),
CostComponents: []*schema.CostComponent{
{
Name: "Duration",
Unit: unit,
UnitMultiplier: decimal.NewFromFloat(r.DPUs),
MonthlyQuantity: quantity,
ProductFilter: &schema.ProductFilter{
VendorName: vendorName,
Region: strPtr(r.Region),
Service: strPtr("AWSGlue"),
ProductFamily: strPtr("AWS Glue"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "group", Value: strPtr("ETL Job run")},
{Key: "operation", ValueRegex: strPtr("/^jobrun$/i")},
},
},
UsageBased: true,
},
},
}
}