@@ -58,7 +58,7 @@ func NewEC2Metadata(awsSession *session.Session) {
58
58
59
59
// DescribeSGByPermissionGroup Finds an SG that the passed SG has permission to.
60
60
func (e * EC2 ) DescribeSGByPermissionGroup (sg * string ) (* string , error ) {
61
- cache := "sg-permission-group "
61
+ cache := "EC2-DescribeSGByPermissionGroup "
62
62
key := cache + "." + * sg
63
63
item := e .cache .Get (key )
64
64
@@ -68,6 +68,8 @@ func (e *EC2) DescribeSGByPermissionGroup(sg *string) (*string, error) {
68
68
return groupid , nil
69
69
}
70
70
71
+ albprom .AWSCache .With (prometheus.Labels {"cache" : cache , "action" : "miss" }).Add (float64 (1 ))
72
+
71
73
in := & ec2.DescribeSecurityGroupsInput {
72
74
Filters : []* ec2.Filter {
73
75
{
@@ -86,13 +88,12 @@ func (e *EC2) DescribeSGByPermissionGroup(sg *string) (*string, error) {
86
88
}
87
89
88
90
e .cache .Set (key , o .SecurityGroups [0 ].GroupId , time .Minute * 5 )
89
- albprom .AWSCache .With (prometheus.Labels {"cache" : cache , "action" : "miss" }).Add (float64 (1 ))
90
91
return o .SecurityGroups [0 ].GroupId , nil
91
92
}
92
93
93
94
// DescribeSGPorts returns the ports associated with a SG.
94
95
func (e * EC2 ) DescribeSGPorts (sgID * string ) ([]int64 , error ) {
95
- cache := "sg-ports "
96
+ cache := "EC2-DescribeSGPorts "
96
97
key := cache + "." + * sgID
97
98
item := e .cache .Get (key )
98
99
@@ -102,6 +103,8 @@ func (e *EC2) DescribeSGPorts(sgID *string) ([]int64, error) {
102
103
return ports , nil
103
104
}
104
105
106
+ albprom .AWSCache .With (prometheus.Labels {"cache" : cache , "action" : "miss" }).Add (float64 (1 ))
107
+
105
108
in := & ec2.DescribeSecurityGroupsInput {
106
109
GroupIds : []* string {sgID },
107
110
}
@@ -117,12 +120,23 @@ func (e *EC2) DescribeSGPorts(sgID *string) ([]int64, error) {
117
120
}
118
121
119
122
e .cache .Set (key , ports , time .Minute * 5 )
120
- albprom .AWSCache .With (prometheus.Labels {"cache" : cache , "action" : "miss" }).Add (float64 (1 ))
121
123
return ports , nil
122
124
}
123
125
124
126
// DescribeSGInboundCidrs returns the inbound cidrs associated with a SG.
125
127
func (e * EC2 ) DescribeSGInboundCidrs (sgID * string ) ([]* string , error ) {
128
+ cache := "EC2-DescribeSGInboundCidrs"
129
+ key := cache + "." + * sgID
130
+ item := e .cache .Get (key )
131
+
132
+ if item != nil {
133
+ tags := item .Value ().([]* string )
134
+ albprom .AWSCache .With (prometheus.Labels {"cache" : cache , "action" : "hit" }).Add (float64 (1 ))
135
+ return tags , nil
136
+ }
137
+
138
+ albprom .AWSCache .With (prometheus.Labels {"cache" : cache , "action" : "miss" }).Add (float64 (1 ))
139
+
126
140
in := & ec2.DescribeSecurityGroupsInput {
127
141
GroupIds : []* string {sgID },
128
142
}
@@ -139,12 +153,13 @@ func (e *EC2) DescribeSGInboundCidrs(sgID *string) ([]*string, error) {
139
153
}
140
154
}
141
155
156
+ e .cache .Set (key , inboundCidrs , time .Minute * 5 )
142
157
return inboundCidrs , nil
143
158
}
144
159
145
160
// DescribeSGTags returns tags for an sg when the sg-id is provided.
146
161
func (e * EC2 ) DescribeSGTags (sgID * string ) ([]* ec2.TagDescription , error ) {
147
- cache := "sg-tags "
162
+ cache := "EC2-DescribeSGTags "
148
163
key := cache + "." + * sgID
149
164
item := e .cache .Get (key )
150
165
@@ -154,6 +169,8 @@ func (e *EC2) DescribeSGTags(sgID *string) ([]*ec2.TagDescription, error) {
154
169
return tags , nil
155
170
}
156
171
172
+ albprom .AWSCache .With (prometheus.Labels {"cache" : cache , "action" : "miss" }).Add (float64 (1 ))
173
+
157
174
in := & ec2.DescribeTagsInput {
158
175
Filters : []* ec2.Filter {
159
176
{
@@ -169,7 +186,6 @@ func (e *EC2) DescribeSGTags(sgID *string) ([]*ec2.TagDescription, error) {
169
186
}
170
187
171
188
e .cache .Set (key , o .Tags , time .Minute * 5 )
172
- albprom .AWSCache .With (prometheus.Labels {"cache" : cache , "action" : "miss" }).Add (float64 (1 ))
173
189
return o .Tags , nil
174
190
}
175
191
@@ -189,7 +205,7 @@ func (e *EC2) DeleteSecurityGroupByID(sgID *string) error {
189
205
// exists. If it does, it attempts to remove the managedSG from the list.
190
206
func (e * EC2 ) DisassociateSGFromInstanceIfNeeded (instances []* string , managedSG * string ) error {
191
207
if managedSG == nil {
192
- return fmt .Errorf ("Managed SG passed was empty unable to disassociate from instances. " )
208
+ return fmt .Errorf ("Managed SG passed was empty unable to disassociate from instances" )
193
209
}
194
210
in := & ec2.DescribeInstancesInput {
195
211
InstanceIds : instances ,
@@ -595,13 +611,14 @@ func (e *EC2) GetVPCID() (*string, error) {
595
611
596
612
// If previously looked up (and not expired) the VpcId will be stored in the cache under the
597
613
// key 'vpc'.
598
- key := "vpc"
614
+ cache := "EC2-GetVPCID"
615
+ key := cache
599
616
item := e .cache .Get (key )
600
617
601
618
// cache hit: return (pointer of) VpcId value
602
619
if item != nil {
603
620
vpc = item .Value ().(* string )
604
- albprom .AWSCache .With (prometheus.Labels {"cache" : "vpc" , "action" : "hit" }).Add (float64 (1 ))
621
+ albprom .AWSCache .With (prometheus.Labels {"cache" : cache , "action" : "hit" }).Add (float64 (1 ))
605
622
return vpc , nil
606
623
}
607
624
0 commit comments