Skip to content

Commit

Permalink
edit send queue metric
Browse files Browse the repository at this point in the history
  • Loading branch information
npetchapan committed Apr 20, 2020
1 parent 0dab2fc commit a74a737
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
11 changes: 11 additions & 0 deletions internal/desiredcomponent/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
crctrl "sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand All @@ -18,6 +19,7 @@ import (
s2herrors "github.com/agoda-com/samsahai/internal/errors"
s2hlog "github.com/agoda-com/samsahai/internal/log"
"github.com/agoda-com/samsahai/internal/queue"
"github.com/agoda-com/samsahai/internal/samsahai/exporter"
)

const (
Expand Down Expand Up @@ -108,6 +110,15 @@ func (c *controller) Reconcile(req reconcile.Request) (reconcile.Result, error)
return reconcile.Result{}, err
}

queue := &s2hv1beta1.Queue{}
if err = c.client.Get(ctx, types.NamespacedName{
Name: q.Name,
Namespace: req.Namespace}, queue); err != nil {
logger.Error(err, "cannot get the queue")
} else {
exporter.SetQueueMetric(queue)
}

comp.Status.UpdatedAt = &now
if err := c.client.Update(context.TODO(), comp); err != nil {
return reconcile.Result{}, err
Expand Down
2 changes: 1 addition & 1 deletion internal/samsahai/exporter/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var HealthStatusMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
var QueueMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "samsahai_queue",
Help: "Show components in queue",
}, []string{ "teamName", "component", "version", "state","order", "no_of_processed"})
}, []string{"teamName", "component", "version", "state", "order", "no_of_processed"})

var ActivePromotionMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "samsahai_active_promotion",
Expand Down
16 changes: 8 additions & 8 deletions internal/samsahai/internal_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ func (c *controller) updateTeamDesiredComponent(updateInfo updateTeamDesiredComp
}

// Add metric updateQueueMetric
queue := &s2hv1beta1.Queue{}
if err = c.client.Get(ctx, types.NamespacedName{
Name: compName,
Namespace: compNs}, queue); err != nil {
logger.Error(err, "cannot get the queue")
} else {
exporter.SetQueueMetric(queue)
}
//queue := &s2hv1beta1.Queue{}
//if err = c.client.Get(ctx, types.NamespacedName{
// Name: compName,
// Namespace: compNs}, queue); err != nil {
// logger.Error(err, "cannot get the queue")
//} else {
// exporter.SetQueueMetric(queue)
//}

return nil
}
Expand Down

0 comments on commit a74a737

Please sign in to comment.