Skip to content

Commit

Permalink
Generate licenses, PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Foster committed Sep 10, 2024
1 parent 46d9e14 commit 3a9949a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
12 changes: 12 additions & 0 deletions pkg/monitoring/manager/metrics.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2024 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

package monitoring

import "github.com/prometheus/client_golang/prometheus"
Expand Down
12 changes: 12 additions & 0 deletions pkg/monitoring/manager/metrics_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2024 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

package monitoring

import (
Expand Down
16 changes: 5 additions & 11 deletions pkg/sync/manager/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,15 @@ func (c *SyncController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
defer func() {
elapsed := time.Since(start)
log.Info("end", "duration", elapsed)
// TODO Should I try to get the cluster name out of this? Or is the sync object name good enough?
c.Metrics.RecordReconciliationDur(req.Name, float64(elapsed)/float64(time.Second))
c.Metrics.RecordRequeueCnt(req.Name)
c.Metrics.RecordReconciliationCnt(req.Name)
}()

instance := new(registryv1alpha1.ClusterSync)
if err := c.Get(ctx, req.NamespacedName, instance); err != nil {
c.Metrics.RecordErrorCnt(req.Name)
log.Error(err, "unable to fetch object")
// TODO I'd love to build the requeue metrics into result.go so requeues can't be missed, but I'm hesitant to
// pollute them. Should I do this?
return requeueIfError(client.IgnoreNotFound(err))
return requeueIfError(c, req, client.IgnoreNotFound(err))
}

if instance.ObjectMeta.DeletionTimestamp != nil {
Expand Down Expand Up @@ -114,8 +111,7 @@ func (c *SyncController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
c.Metrics.RecordErrorCnt(req.Name)

if err := c.updateStatus(ctx, instance); err != nil {
c.Metrics.RecordRequeueCnt(req.Name)
return requeueAfter(10*time.Second, err)
return requeueAfter(c, req, 10*time.Second, err)
}
return noRequeue()
}
Expand All @@ -135,15 +131,13 @@ func (c *SyncController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
log.Error(err, "failed to enqueue message")
c.Metrics.RecordErrorCnt(req.Name)
if err := c.updateStatus(ctx, instance); err != nil {
c.Metrics.RecordRequeueCnt(req.Name)
return requeueAfter(10*time.Second, err)
return requeueAfter(c, req, 10*time.Second, err)
}
return noRequeue()
}
if err := c.updateStatus(ctx, instance); err != nil {
c.Metrics.RecordErrorCnt(req.Name)
c.Metrics.RecordRequeueCnt(req.Name)
return requeueAfter(10*time.Second, err)
return requeueAfter(c, req, 10*time.Second, err)
}
return noRequeue()
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/sync/manager/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ import (
"time"
)

func requeueIfError(err error) (ctrl.Result, error) {
func requeueIfError(c *SyncController, req ctrl.Request, err error) (ctrl.Result, error) {
if err != nil {
c.Metrics.RecordRequeueCnt(req.Name)
}
return ctrl.Result{}, err
}

func noRequeue() (ctrl.Result, error) {
return ctrl.Result{}, nil
}

func requeueAfter(interval time.Duration, err error) (ctrl.Result, error) {
func requeueAfter(c *SyncController, req ctrl.Request, interval time.Duration, err error) (ctrl.Result, error) {
c.Metrics.RecordRequeueCnt(req.Name)
return ctrl.Result{RequeueAfter: interval}, err
}

0 comments on commit 3a9949a

Please sign in to comment.