Skip to content

Commit

Permalink
Add missing metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jichenjc committed May 18, 2021
1 parent ae90421 commit c657503
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pkg/cloud/services/compute/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,11 @@ func getOrCreateTrunk(is *Service, eventObject runtime.Object, trunkName, portID
}

func replaceAllAttributesTags(is *Service, eventObject runtime.Object, trunkID string, tags []string) error {
mc := metrics.NewMetricPrometheusContext("trunk", "update")
_, err := attributestags.ReplaceAll(is.networkClient, "trunks", trunkID, attributestags.ReplaceAllOpts{
Tags: tags,
}).Extract()
if err != nil {
if mc.ObserveRequest(err) != nil {
record.Warnf(eventObject, "FailedReplaceAllAttributesTags", "Failed to replace all attributestags, trunk %s: %v", trunkID, err)
return err
}
Expand Down Expand Up @@ -494,8 +495,9 @@ func (s *Service) AssociateFloatingIP(instanceID, floatingIP string) error {
opts := floatingips.AssociateOpts{
FloatingIP: floatingIP,
}
mc := metrics.NewMetricPrometheusContext("floating_ip", "update")
err := floatingips.AssociateInstance(s.computeClient, instanceID, opts).ExtractErr()
if err != nil {
if mc.ObserveRequest(err) != nil {
return err
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/services/networking/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ func createSubnet(client *gophercloud.ServiceClient, openStackCluster *infrav1.O
record.Eventf(openStackCluster, "SuccessfulCreateSubnet", "Created subnet %s with id %s", name, subnet.ID)

if len(openStackCluster.Spec.Tags) > 0 {
mc := metrics.NewMetricPrometheusContext("subnet", "update")
_, err = attributestags.ReplaceAll(client, "subnets", subnet.ID, attributestags.ReplaceAllOpts{
Tags: openStackCluster.Spec.Tags,
}).Extract()
if err != nil {
if mc.ObserveRequest(err) != nil {
return nil, err
}
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/cloud/services/networking/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ INTERFACE_LOOP:
// ... and create a router interface for our subnet.
if createInterface {
s.logger.V(4).Info("Creating RouterInterface", "routerID", router.ID, "subnetID", openStackCluster.Status.Network.Subnet.ID)
mc := metrics.NewMetricPrometheusContext("attach_interface", "create")
routerInterface, err := routers.AddInterface(s.client, router.ID, routers.AddInterfaceOpts{
SubnetID: openStackCluster.Status.Network.Subnet.ID,
}).Extract()
if err != nil {
if mc.ObserveRequest(err) != nil {
return fmt.Errorf("unable to create router interface: %v", err)
}
s.logger.V(4).Info("Created RouterInterface", "id", routerInterface.ID)
Expand Down Expand Up @@ -179,7 +180,9 @@ func setRouterExternalIPs(client *gophercloud.ServiceClient, openStackCluster *i
})
}

if _, err := routers.Update(client, router.ID, updateOpts).Extract(); err != nil {
mc := metrics.NewMetricPrometheusContext("router", "update")
_, err := routers.Update(client, router.ID, updateOpts).Extract()
if mc.ObserveRequest(err) != nil {
record.Warnf(openStackCluster, "FailedUpdateRouter", "Failed to update router %s with id %s: %v", router.Name, router.ID, err)
return err
}
Expand All @@ -199,10 +202,11 @@ func (s *Service) DeleteRouter(openStackCluster *infrav1.OpenStackCluster, clust
}

if subnet.ID != "" {
mc := metrics.NewMetricPrometheusContext("attach_interface", "delete")
_, err = routers.RemoveInterface(s.client, router.ID, routers.RemoveInterfaceOpts{
SubnetID: subnet.ID,
}).Extract()
if err != nil {
if mc.ObserveRequest(err) != nil {
if !capoerrors.IsNotFound(err) {
return fmt.Errorf("unable to remove router interface: %v", err)
}
Expand Down

0 comments on commit c657503

Please sign in to comment.