Skip to content

Commit e4c0653

Browse files
authored
Merge pull request #124 from jweite-amazon/feature/custom-reconcile-error-metrics-labeled-by-ACS-error-code
Custom Metrics for ACS API calls.
2 parents 13ed8d7 + fa87ac2 commit e4c0653

File tree

14 files changed

+166
-5
lines changed

14 files changed

+166
-5
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/onsi/gomega v1.19.0
1212
github.com/pkg/errors v0.9.1
1313
github.com/smallfish/simpleyaml v0.1.0
14+
github.com/prometheus/client_golang v1.11.0
1415
github.com/spf13/pflag v1.0.5
1516
gopkg.in/ini.v1 v1.63.2
1617
k8s.io/api v0.23.0

pkg/cloud/affinity_groups.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (c *client) FetchAffinityGroup(group *AffinityGroup) (reterr error) {
4545
affinityGroup, count, err := c.cs.AffinityGroup.GetAffinityGroupByID(group.ID)
4646
if err != nil {
4747
// handle via multierr
48+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
4849
return err
4950
} else if count > 1 {
5051
// handle via creating a new error.
@@ -59,6 +60,7 @@ func (c *client) FetchAffinityGroup(group *AffinityGroup) (reterr error) {
5960
affinityGroup, count, err := c.cs.AffinityGroup.GetAffinityGroupByName(group.Name)
6061
if err != nil {
6162
// handle via multierr
63+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
6264
return err
6365
} else if count > 1 {
6466
// handle via creating a new error.
@@ -78,6 +80,7 @@ func (c *client) GetOrCreateAffinityGroup(group *AffinityGroup) (retErr error) {
7880
p.SetName(group.Name)
7981
resp, err := c.cs.AffinityGroup.CreateAffinityGroup(p)
8082
if err != nil {
83+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
8184
return err
8285
}
8386
group.ID = resp.Id
@@ -90,6 +93,7 @@ func (c *client) DeleteAffinityGroup(group *AffinityGroup) (retErr error) {
9093
setIfNotEmpty(group.ID, p.SetId)
9194
setIfNotEmpty(group.Name, p.SetName)
9295
_, retErr = c.cs.AffinityGroup.DeleteAffinityGroup(p)
96+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
9397
return retErr
9498
}
9599

@@ -98,6 +102,7 @@ type affinityGroups []AffinityGroup
98102
func (c *client) getCurrentAffinityGroups(csMachine *infrav1.CloudStackMachine) (affinityGroups, error) {
99103
// Start by fetching VM details which includes an array of currently associated affinity groups.
100104
if virtM, count, err := c.cs.VirtualMachine.GetVirtualMachineByID(*csMachine.Spec.InstanceID); err != nil {
105+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
101106
return nil, err
102107
} else if count > 1 {
103108
return nil, errors.Errorf("found more than one VM for ID: %s", *csMachine.Spec.InstanceID)
@@ -149,15 +154,18 @@ func (c *client) stopAndModifyAffinityGroups(csMachine *infrav1.CloudStackMachin
149154

150155
p1 := c.cs.VirtualMachine.NewStopVirtualMachineParams(string(*csMachine.Spec.InstanceID))
151156
if _, err := c.cs.VirtualMachine.StopVirtualMachine(p1); err != nil {
157+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
152158
return err
153159
}
154160

155161
if _, err := c.cs.AffinityGroup.UpdateVMAffinityGroup(agp); err != nil {
162+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
156163
return err
157164
}
158165

159166
p2 := c.cs.VirtualMachine.NewStartVirtualMachineParams(string(*csMachine.Spec.InstanceID))
160167
_, err := c.cs.VirtualMachine.StartVirtualMachine(p2)
168+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
161169
return err
162170
}
163171

pkg/cloud/affinity_groups_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ var _ = Describe("AffinityGroup Unit Tests", func() {
8888
// Make the created VM go away quickly by force stopping it.
8989
p := realCSClient.VirtualMachine.NewStopVirtualMachineParams(*dummies.CSMachine1.Spec.InstanceID)
9090
p.SetForced(true)
91-
Ω(realCSClient.VirtualMachine.StopVirtualMachine(p)).Should(Succeed())
91+
_, err := realCSClient.VirtualMachine.StopVirtualMachine(p)
92+
Ω(err).ShouldNot(HaveOccurred())
9293
})
9394

9495
It("Creates and deletes an affinity group.", func() {

pkg/cloud/client.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package cloud
1818

1919
import (
20+
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/metrics"
2021
"strings"
2122

2223
"github.com/apache/cloudstack-go/v2/cloudstack"
@@ -40,9 +41,10 @@ type Client interface {
4041
}
4142

4243
type client struct {
43-
cs *cloudstack.CloudStackClient
44-
csAsync *cloudstack.CloudStackClient
45-
config Config
44+
cs *cloudstack.CloudStackClient
45+
csAsync *cloudstack.CloudStackClient
46+
config Config
47+
customMetrics metrics.ACSCustomMetrics
4648
}
4749

4850
// cloud-config ini structure.
@@ -68,6 +70,7 @@ func NewClient(ccPath string) (Client, error) {
6870
// comments for more details
6971
c.cs = cloudstack.NewAsyncClient(c.config.APIURL, c.config.APIKey, c.config.SecretKey, c.config.VerifySSL)
7072
c.csAsync = cloudstack.NewClient(c.config.APIURL, c.config.APIKey, c.config.SecretKey, c.config.VerifySSL)
73+
c.customMetrics = metrics.NewCustomMetrics()
7174

7275
_, err := c.cs.APIDiscovery.ListApis(c.cs.APIDiscovery.NewListApisParams())
7376
if err != nil && strings.Contains(strings.ToLower(err.Error()), "i/o timeout") {
@@ -91,6 +94,7 @@ func (origC *client) NewClientFromSpec(cfg Config) (Client, error) {
9194
// comments for more details
9295
newC.cs = cloudstack.NewAsyncClient(newC.config.APIURL, newC.config.APIKey, newC.config.SecretKey, newC.config.VerifySSL)
9396
newC.csAsync = cloudstack.NewClient(newC.config.APIURL, newC.config.APIKey, newC.config.SecretKey, newC.config.VerifySSL)
97+
newC.customMetrics = metrics.NewCustomMetrics()
9498

9599
_, err := newC.cs.APIDiscovery.ListApis(newC.cs.APIDiscovery.NewListApisParams())
96100
if err != nil && strings.Contains(strings.ToLower(err.Error()), "i/o timeout") {
@@ -100,6 +104,6 @@ func (origC *client) NewClientFromSpec(cfg Config) (Client, error) {
100104
}
101105

102106
func NewClientFromCSAPIClient(cs *cloudstack.CloudStackClient) Client {
103-
c := &client{cs: cs, csAsync: cs}
107+
c := &client{cs: cs, csAsync: cs, customMetrics: metrics.NewCustomMetrics()}
104108
return c
105109
}

pkg/cloud/instance.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func (c *client) ResolveVMInstanceDetails(csMachine *infrav1.CloudStackMachine)
5656
if csMachine.Spec.InstanceID != nil {
5757
vmResp, count, err := c.cs.VirtualMachine.GetVirtualMachinesMetricByID(*csMachine.Spec.InstanceID)
5858
if err != nil && !strings.Contains(strings.ToLower(err.Error()), "no match found") {
59+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
5960
return err
6061
} else if count > 1 {
6162
return fmt.Errorf("found more than one VM Instance with ID %s", *csMachine.Spec.InstanceID)
@@ -69,6 +70,7 @@ func (c *client) ResolveVMInstanceDetails(csMachine *infrav1.CloudStackMachine)
6970
if csMachine.Name != "" {
7071
vmResp, count, err := c.cs.VirtualMachine.GetVirtualMachinesMetricByName(csMachine.Name) // add opts usage
7172
if err != nil && !strings.Contains(strings.ToLower(err.Error()), "no match") {
73+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
7274
return err
7375
} else if count > 1 {
7476
return fmt.Errorf("found more than one VM Instance with name %s", csMachine.Name)
@@ -84,6 +86,7 @@ func (c *client) ResolveServiceOffering(csMachine *infrav1.CloudStackMachine) (o
8486
if len(csMachine.Spec.Offering.ID) > 0 {
8587
csOffering, count, err := c.cs.ServiceOffering.GetServiceOfferingByID(csMachine.Spec.Offering.ID)
8688
if err != nil {
89+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
8790
return "", multierror.Append(retErr, errors.Wrapf(
8891
err, "could not get Service Offering by ID %s", csMachine.Spec.Offering.ID))
8992
} else if count != 1 {
@@ -99,6 +102,7 @@ func (c *client) ResolveServiceOffering(csMachine *infrav1.CloudStackMachine) (o
99102
}
100103
offeringID, count, err := c.cs.ServiceOffering.GetServiceOfferingID(csMachine.Spec.Offering.Name)
101104
if err != nil {
105+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
102106
return "", multierror.Append(retErr, errors.Wrapf(
103107
err, "could not get Service Offering ID from %s", csMachine.Spec.Offering.Name))
104108
} else if count != 1 {
@@ -116,6 +120,7 @@ func (c *client) ResolveTemplate(
116120
if len(csMachine.Spec.Template.ID) > 0 {
117121
csTemplate, count, err := c.cs.Template.GetTemplateByID(csMachine.Spec.Template.ID, "executable")
118122
if err != nil {
123+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
119124
return "", multierror.Append(retErr, errors.Wrapf(
120125
err, "could not get Template by ID %s", csMachine.Spec.Template.ID))
121126
} else if count != 1 {
@@ -131,6 +136,7 @@ func (c *client) ResolveTemplate(
131136
}
132137
templateID, count, err := c.cs.Template.GetTemplateID(csMachine.Spec.Template.Name, "executable", zoneID)
133138
if err != nil {
139+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
134140
return "", multierror.Append(retErr, errors.Wrapf(
135141
err, "could not get Template ID from %s", csMachine.Spec.Template.Name))
136142
} else if count != 1 {
@@ -148,6 +154,7 @@ func (c *client) ResolveDiskOffering(csMachine *infrav1.CloudStackMachine) (disk
148154
if len(csMachine.Spec.DiskOffering.Name) > 0 {
149155
diskID, count, err := c.cs.DiskOffering.GetDiskOfferingID(csMachine.Spec.DiskOffering.Name)
150156
if err != nil {
157+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
151158
return "", multierror.Append(retErr, errors.Wrapf(
152159
err, "could not get DiskOffering ID from %s", csMachine.Spec.DiskOffering.Name))
153160
} else if count != 1 {
@@ -174,6 +181,7 @@ func (c *client) ResolveDiskOffering(csMachine *infrav1.CloudStackMachine) (disk
174181
func verifyDiskoffering(csMachine *infrav1.CloudStackMachine, c *client, diskOfferingID string, retErr error) (string, error) {
175182
csDiskOffering, count, err := c.cs.DiskOffering.GetDiskOfferingByID(diskOfferingID)
176183
if err != nil {
184+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
177185
return "", multierror.Append(retErr, errors.Wrapf(
178186
err, "could not get DiskOffering by ID %s", diskOfferingID))
179187
} else if count != 1 {
@@ -255,6 +263,8 @@ func (c *client) GetOrCreateVMInstance(
255263

256264
deployVMResp, err := c.cs.VirtualMachine.DeployVirtualMachine(p)
257265
if err != nil {
266+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
267+
258268
// Just because an error was returned doesn't mean a (failed) VM wasn't created and will need to be dealt with.
259269
// Regretfully the deployVMResp may be nil, so we need to get the VM ID with a separate query, so we
260270
// can return it to the caller, so they can clean it up.
@@ -265,6 +275,8 @@ func (c *client) GetOrCreateVMInstance(
265275
listVirtualMachineParams.SetName(csMachine.Name)
266276
if listVirtualMachinesResponse, err2 := c.cs.VirtualMachine.ListVirtualMachines(listVirtualMachineParams); err2 == nil && listVirtualMachinesResponse.Count > 0 {
267277
csMachine.Spec.InstanceID = pointer.StringPtr(listVirtualMachinesResponse.VirtualMachines[0].Id)
278+
} else {
279+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err2)
268280
}
269281
return err
270282
}
@@ -290,6 +302,7 @@ func (c *client) DestroyVMInstance(csMachine *infrav1.CloudStackMachine) error {
290302
// VM doesn't exist. Success...
291303
return nil
292304
} else if err != nil {
305+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
293306
return err
294307
}
295308

@@ -316,6 +329,7 @@ func (c *client) listVMInstanceDatadiskVolumeIDs(instanceID string) ([]string, e
316329

317330
listVOLResp, err := c.csAsync.Volume.ListVolumes(p)
318331
if err != nil {
332+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
319333
return nil, err
320334
}
321335

pkg/cloud/isolated_network.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type IsoNetworkIface interface {
4444
func (c *client) getOfferingID() (string, error) {
4545
offeringID, count, retErr := c.cs.NetworkOffering.GetNetworkOfferingID(NetOffering)
4646
if retErr != nil {
47+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
4748
return "", retErr
4849
} else if count != 1 {
4950
return "", errors.New("found more than one network offering")
@@ -76,6 +77,7 @@ func (c *client) AssociatePublicIPAddress(
7677
p.SetIpaddress(isoNet.Spec.ControlPlaneEndpoint.Host)
7778
p.SetNetworkid(isoNet.Spec.ID)
7879
if _, err := c.cs.Address.AssociateIpAddress(p); err != nil {
80+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
7981
return errors.Wrapf(err,
8082
"associating public IP address with ID %s to network with ID %s",
8183
publicAddress.Id, isoNet.Spec.ID)
@@ -101,6 +103,7 @@ func (c *client) CreateIsolatedNetwork(zone *capcv1.CloudStackZone, isoNet *capc
101103
p := c.cs.Network.NewCreateNetworkParams(isoNet.Spec.Name, isoNet.Spec.Name, offeringID, zone.Spec.ID)
102104
resp, err := c.cs.Network.CreateNetwork(p)
103105
if err != nil {
106+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
104107
return errors.Wrapf(err, "creating network with name %s", isoNet.Spec.Name)
105108
}
106109
isoNet.Spec.ID = resp.Id
@@ -114,6 +117,7 @@ func (c *client) OpenFirewallRules(isoNet *capcv1.CloudStackIsolatedNetwork) (re
114117
if retErr != nil && strings.Contains(strings.ToLower(retErr.Error()), "there is already") { // Already a firewall rule here.
115118
retErr = nil
116119
}
120+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
117121
return retErr
118122
}
119123

@@ -131,6 +135,7 @@ func (c *client) GetPublicIP(
131135
setIfNotEmpty(ip, p.SetIpaddress)
132136
publicAddresses, err := c.cs.Address.ListPublicIpAddresses(p)
133137
if err != nil {
138+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
134139
return nil, err
135140
} else if ip != "" && publicAddresses.Count == 1 { // Endpoint specified and IP found.
136141
// Ignore already allocated here since the IP was specified.
@@ -156,6 +161,7 @@ func (c *client) GetPublicIP(
156161
func (c *client) GetIsolatedNetwork(isoNet *capcv1.CloudStackIsolatedNetwork) (retErr error) {
157162
netDetails, count, err := c.cs.Network.GetNetworkByName(isoNet.Spec.Name)
158163
if err != nil {
164+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
159165
retErr = multierror.Append(retErr, errors.Wrapf(err, "could not get Network ID from %s", isoNet.Spec.Name))
160166
} else if count != 1 {
161167
retErr = multierror.Append(retErr, errors.Errorf(
@@ -167,6 +173,7 @@ func (c *client) GetIsolatedNetwork(isoNet *capcv1.CloudStackIsolatedNetwork) (r
167173

168174
netDetails, count, err = c.cs.Network.GetNetworkByID(isoNet.Spec.ID)
169175
if err != nil {
176+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
170177
return multierror.Append(retErr, errors.Wrapf(err, "could not get Network by ID %s", isoNet.Spec.ID))
171178
} else if count != 1 {
172179
return multierror.Append(retErr, errors.Errorf("expected 1 Network with UUID %s, but got %d", isoNet.Spec.ID, count))
@@ -185,6 +192,7 @@ func (c *client) ResolveLoadBalancerRuleDetails(
185192
p.SetPublicipid(isoNet.Status.PublicIPID)
186193
loadBalancerRules, err := c.cs.LoadBalancer.ListLoadBalancerRules(p)
187194
if err != nil {
195+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
188196
return errors.Wrap(err, "listing load balancer rules")
189197
}
190198
for _, rule := range loadBalancerRules.LoadBalancerRules {
@@ -229,6 +237,7 @@ func (c *client) GetOrCreateLoadBalancerRule(
229237
p.SetProtocol(NetworkProtocolTCP)
230238
resp, err := c.cs.LoadBalancer.CreateLoadBalancerRule(p)
231239
if err != nil {
240+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
232241
return err
233242
}
234243
isoNet.Status.LBRuleID = resp.Id
@@ -278,6 +287,7 @@ func (c *client) AssignVMToLoadBalancerRule(isoNet *capcv1.CloudStackIsolatedNet
278287
lbRuleInstances, retErr := c.cs.LoadBalancer.ListLoadBalancerRuleInstances(
279288
c.cs.LoadBalancer.NewListLoadBalancerRuleInstancesParams(isoNet.Status.LBRuleID))
280289
if retErr != nil {
290+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
281291
return retErr
282292
}
283293
for _, instance := range lbRuleInstances.LoadBalancerRuleInstances {
@@ -290,12 +300,14 @@ func (c *client) AssignVMToLoadBalancerRule(isoNet *capcv1.CloudStackIsolatedNet
290300
p := c.cs.LoadBalancer.NewAssignToLoadBalancerRuleParams(isoNet.Status.LBRuleID)
291301
p.SetVirtualmachineids([]string{instanceID})
292302
_, retErr = c.cs.LoadBalancer.AssignToLoadBalancerRule(p)
303+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
293304
return retErr
294305
}
295306

296307
// DeleteNetwork deletes an isolated network.
297308
func (c *client) DeleteNetwork(net capcv1.Network) error {
298309
_, err := c.cs.Network.DeleteNetwork(c.cs.Network.NewDeleteNetworkParams(net.ID))
310+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
299311
return errors.Wrapf(err, "deleting network with id %s", net.ID)
300312
}
301313

@@ -350,6 +362,7 @@ func (c *client) DisassociatePublicIPAddressIfNotInUse(isoNet *capcv1.CloudStack
350362
if tagsAllowDisposal, err := c.DoClusterTagsAllowDisposal(ResourceTypeIPAddress, isoNet.Status.PublicIPID); err != nil {
351363
return err
352364
} else if publicIP, _, err := c.cs.Address.GetPublicIpAddressByID(isoNet.Status.PublicIPID); err != nil {
365+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
353366
return err
354367
} else if publicIP == nil || publicIP.Issourcenat { // Can't disassociate an address if it's the source NAT address.
355368
return nil
@@ -369,5 +382,6 @@ func (c *client) DisassociatePublicIPAddress(isoNet *capcv1.CloudStackIsolatedNe
369382

370383
p := c.cs.Address.NewDisassociateIpAddressParams(isoNet.Status.PublicIPID)
371384
_, retErr = c.cs.Address.DisassociateIpAddress(p)
385+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
372386
return retErr
373387
}

pkg/cloud/network.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (c *client) ResolveNetwork(net *capcv1.Network) (retErr error) {
5050
netName := net.Name
5151
netDetails, count, err := c.cs.Network.GetNetworkByName(netName)
5252
if err != nil {
53+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
5354
retErr = multierror.Append(retErr, errors.Wrapf(err, "could not get Network ID from %s", netName))
5455
} else if count != 1 {
5556
retErr = multierror.Append(retErr, errors.Errorf(
@@ -65,6 +66,7 @@ func (c *client) ResolveNetwork(net *capcv1.Network) (retErr error) {
6566
if err != nil {
6667
return multierror.Append(retErr, errors.Wrapf(err, "could not get Network by ID %s", net.ID))
6768
} else if count != 1 {
69+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
6870
return multierror.Append(retErr, errors.Errorf("expected 1 Network with UUID %s, but got %d", net.ID, count))
6971
}
7072
net.Name = netDetails.Name

pkg/cloud/tags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func (c *client) DoClusterTagsAllowDisposal(resourceType ResourceType, resourceI
119119
func (c *client) AddTags(resourceType ResourceType, resourceID string, tags map[string]string) error {
120120
p := c.cs.Resourcetags.NewCreateTagsParams([]string{resourceID}, string(resourceType), tags)
121121
_, err := c.cs.Resourcetags.CreateTags(p)
122+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
122123
return ignoreAlreadyPresentErrors(err, resourceType, resourceID)
123124
}
124125

@@ -130,6 +131,7 @@ func (c *client) GetTags(resourceType ResourceType, resourceID string) (map[stri
130131
p.SetListall(true)
131132
listTagResponse, err := c.cs.Resourcetags.ListTags(p)
132133
if err != nil {
134+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
133135
return nil, err
134136
}
135137
tags := make(map[string]string, listTagResponse.Count)
@@ -146,8 +148,10 @@ func (c *client) DeleteTags(resourceType ResourceType, resourceID string, tagsTo
146148
p := c.cs.Resourcetags.NewDeleteTagsParams([]string{resourceID}, string(resourceType))
147149
p.SetTags(tagsToDelete)
148150
if _, err1 := c.cs.Resourcetags.DeleteTags(p); err1 != nil { // Error in deletion attempt. Check for tag.
151+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err1)
149152
currTag := map[string]string{tagkey: tagval}
150153
if tags, err2 := c.GetTags(resourceType, resourceID); len(tags) != 0 {
154+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err2)
151155
if _, foundTag := tags[tagkey]; foundTag {
152156
return errors.Wrapf(multierror.Append(err1, err2),
153157
"could not remove tag %s from %s with ID %s", currTag, resourceType, resourceID)

0 commit comments

Comments
 (0)