Skip to content

Commit

Permalink
Merge pull request #16 from snapp-incubator/summary
Browse files Browse the repository at this point in the history
feat: add event_summary_k8s
  • Loading branch information
m-yosefpor authored Jan 19, 2022
2 parents d5e3959 + eefe260 commit c2d62d3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# https://golangci-lint.run/usage/configuration/
run:
timeout: 10m
deadline: 5m
3 changes: 2 additions & 1 deletion controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ func (c *EventExporterController) Run(stopCh <-chan struct{}) error {
c.informerFactory.Start(stopCh)
// wait for the initial synchronization of the local cache.
if !cache.WaitForCacheSync(stopCh, c.eventInformer.Informer().HasSynced) {
return fmt.Errorf("Failed to sync")
return fmt.Errorf("failed to sync")
}
return nil
}

func (c *EventExporterController) eventAdd(obj interface{}) {
event := obj.(*v1.Event)
IncSummaryEvent(event)
switch event.Type {
case "Normal":
IncNormalEvent(event)
Expand Down
25 changes: 25 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ var (
},
)

k8sSummaryEvents = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "event",
Subsystem: "summary",
Name: "k8s",
Help: "Exports summary of k8s events count.",
},
[]string{
"namespace",
"reason",
"kind",
"type",
},
)

k8sWarningEvents = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "event",
Subsystem: "warning",
Expand All @@ -45,6 +59,17 @@ func init() {
prometheus.MustRegister(k8sWarningEvents)
}

// IncSummaryEvent parses and increases an event counter with corresponding labels.
func IncSummaryEvent(event *v1.Event) {

k8sSummaryEvents.WithLabelValues(
event.Namespace, // namespace
event.Reason, // reason
event.InvolvedObject.Kind, // kind
event.Type, // type
).Inc()
}

// IncNormalEvent parses and increases an event counter with corresponding labels.
func IncNormalEvent(event *v1.Event) {

Expand Down

0 comments on commit c2d62d3

Please sign in to comment.