adding instrumentation
parent
b2aaf46acc
commit
20cf7e9f79
|
@ -12,15 +12,38 @@ import (
|
|||
|
||||
hapi_chart "k8s.io/helm/pkg/proto/hapi/chart"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/keel-hq/keel/extension/notification"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/ghodss/yaml"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"k8s.io/helm/pkg/chartutil"
|
||||
"k8s.io/helm/pkg/helm"
|
||||
"k8s.io/helm/pkg/strvals"
|
||||
)
|
||||
|
||||
var helmVersionedUpdatesCounter = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "helm_versioned_updates_total",
|
||||
Help: "How many versioned helm charts were updated, partitioned by chart name.",
|
||||
},
|
||||
[]string{"chart"},
|
||||
)
|
||||
|
||||
var helmUnversionedUpdatesCounter = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "helm_unversioned_updates_total",
|
||||
Help: "How many unversioned helm charts were updated, partitioned by chart name.",
|
||||
},
|
||||
[]string{"chart"},
|
||||
)
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(helmVersionedUpdatesCounter)
|
||||
prometheus.MustRegister(helmUnversionedUpdatesCounter)
|
||||
}
|
||||
|
||||
// Manager - high level interface into helm provider related data used by
|
||||
// triggers
|
||||
type Manager interface {
|
||||
|
@ -250,6 +273,7 @@ func (p *Provider) createUpdatePlans(event *types.Event) ([]*UpdatePlan, error)
|
|||
|
||||
if update {
|
||||
plans = append(plans, plan)
|
||||
helmUnversionedUpdatesCounter.With(prometheus.Labels{"chart": fmt.Sprintf("%s/%s", release.Namespace, release.Name)}).Inc()
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -270,6 +294,7 @@ func (p *Provider) createUpdatePlans(event *types.Event) ([]*UpdatePlan, error)
|
|||
continue
|
||||
}
|
||||
if update {
|
||||
helmVersionedUpdatesCounter.With(prometheus.Labels{"chart": fmt.Sprintf("%s/%s", release.Namespace, release.Name)}).Inc()
|
||||
plans = append(plans, plan)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@ import (
|
|||
|
||||
"github.com/rusenask/cron"
|
||||
|
||||
// "k8s.io/api/core/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
|
||||
"k8s.io/api/extensions/v1beta1"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/keel-hq/keel/approvals"
|
||||
"github.com/keel-hq/keel/extension/notification"
|
||||
"github.com/keel-hq/keel/types"
|
||||
|
@ -23,6 +23,27 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var kubernetesVersionedUpdatesCounter = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "kubernetes_versioned_updates_total",
|
||||
Help: "How many versioned deployments were updated, partitioned by deployment name.",
|
||||
},
|
||||
[]string{"deployment"},
|
||||
)
|
||||
|
||||
var kubernetesUnversionedUpdatesCounter = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "kubernetes_unversioned_updates_total",
|
||||
Help: "How many unversioned deployments were updated, partitioned by deployment name.",
|
||||
},
|
||||
[]string{"deployment"},
|
||||
)
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(kubernetesVersionedUpdatesCounter)
|
||||
prometheus.MustRegister(kubernetesUnversionedUpdatesCounter)
|
||||
}
|
||||
|
||||
// ProviderName - provider name
|
||||
const ProviderName = "kubernetes"
|
||||
|
||||
|
@ -218,10 +239,12 @@ func (p *Provider) updateDeployments(plans []*UpdatePlan) (updated []*v1beta1.De
|
|||
if reset {
|
||||
// force update, terminating all pods
|
||||
err = p.forceUpdate(&deployment)
|
||||
kubernetesUnversionedUpdatesCounter.With(prometheus.Labels{"deployment": fmt.Sprintf("%s/%s", deployment.Namespace, deployment.Name)}).Inc()
|
||||
} else {
|
||||
// regular update
|
||||
deployment.Annotations["kubernetes.io/change-cause"] = fmt.Sprintf("keel automated update, version %s -> %s", plan.CurrentVersion, plan.NewVersion)
|
||||
err = p.implementer.Update(&deployment)
|
||||
kubernetesVersionedUpdatesCounter.With(prometheus.Labels{"deployment": fmt.Sprintf("%s/%s", deployment.Namespace, deployment.Name)}).Inc()
|
||||
}
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
|
|
|
@ -8,9 +8,23 @@ import (
|
|||
|
||||
"github.com/keel-hq/keel/types"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var newDockerhubWebhooksCounter = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "dockerhub_webhook_requests_total",
|
||||
Help: "How many /v1/webhooks/dockerhub requests processed, partitioned by image.",
|
||||
},
|
||||
[]string{"image"},
|
||||
)
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(newDockerhubWebhooksCounter)
|
||||
}
|
||||
|
||||
// Example of dockerhub trigger
|
||||
// {
|
||||
// "push_data": {
|
||||
|
@ -98,5 +112,7 @@ func (s *TriggerServer) dockerHubHandler(resp http.ResponseWriter, req *http.Req
|
|||
s.trigger(event)
|
||||
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
|
||||
newDockerhubWebhooksCounter.With(prometheus.Labels{"image": event.Repository.Name}).Inc()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -7,10 +7,23 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/keel-hq/keel/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var newNativeWebhooksCounter = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "native_webhook_requests_total",
|
||||
Help: "How many /v1/webhooks/native requests processed, partitioned by image.",
|
||||
},
|
||||
[]string{"image"},
|
||||
)
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(newNativeWebhooksCounter)
|
||||
}
|
||||
|
||||
// nativeHandler - used to trigger event directly
|
||||
func (s *TriggerServer) nativeHandler(resp http.ResponseWriter, req *http.Request) {
|
||||
repo := types.Repository{}
|
||||
|
@ -42,5 +55,7 @@ func (s *TriggerServer) nativeHandler(resp http.ResponseWriter, req *http.Reques
|
|||
s.trigger(event)
|
||||
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
|
||||
newNativeWebhooksCounter.With(prometheus.Labels{"image": event.Repository.Name}).Inc()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -7,10 +7,23 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/keel-hq/keel/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var newQuayWebhooksCounter = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "quay_webhook_requests_total",
|
||||
Help: "How many /v1/webhooks/quay requests processed, partitioned by image.",
|
||||
},
|
||||
[]string{"image"},
|
||||
)
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(newQuayWebhooksCounter)
|
||||
}
|
||||
|
||||
// Example of quay trigger
|
||||
// {
|
||||
// "name": "repository",
|
||||
|
@ -63,9 +76,9 @@ func (s *TriggerServer) quayHandler(resp http.ResponseWriter, req *http.Request)
|
|||
event.Repository.Tag = tag
|
||||
|
||||
s.trigger(event)
|
||||
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
newQuayWebhooksCounter.With(prometheus.Labels{"image": event.Repository.Name}).Inc()
|
||||
}
|
||||
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue