kubeslice-monitoring

module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: Apache-2.0

README

kubeslice-monitoring

kubeslice-monitoring : Repository for kubeslice-monitoring package

Event Schema

It contains the following fields for each event

  • name: Name of the event
  • reason: Reason for raising the event
  • action: Action which caused the event or the action which need to be taken
  • type: Warning or Normal
  • reportingController: Name of the component which reported the event
  • message: Human readable message explaining the event

Using events framework in your component

  1. Copy the hack/ directory to your component.

It contains generate/generate.go and templates/schema.tmpl files. You will require both to create a helper to generate Events Map. Modify template and output file paths in generate.go if needed.

  1. Create a events schema yaml for your component in the following format:
events:
  - name: ExampleEvent
    reason: ExampleEvent
    action: ExampleEvent
    type: Warning
    reportingController: controller
    message: ExampleEvent message.
  
  1. Add the following lines to your Makefile. (Make path modifications if required.)
.PHONY: generate-events
generate-events:
	go run hack/generate/generate.go <PATH-TO-EVENT-SCHEMA-YAML>
	go fmt ./...
  1. Generate Events Map

Run this command after making any changes to event schema files

make generate-events

This will generate events_generated.go file in the events directory. (Check file output path in hack/generate/generate.go)

  1. Import events package from monitoring framework and the generated Events Map from your component.
import(
	"github.com/kubeslice/kubeslice-monitoring/pkg/events"
	componentEvents "github.com/kubeslice/<YOUR-COMPONENT>/events"
)
  1. Initialize event recorder
recorder := events.NewEventRecorder(k8sClient, schema, componentEvents.EventsMap, events.EventRecorderOptions{
  Version:   "1",
  Cluster:   "cluster-1",
  Component: "controller",
  Namespace: "test-ns",
  Slice: "test-clice",
  Project: "test-project",
})

Slice and Namespace names are optional if the recorder is not part of a slice specific or namespace specific component.

  1. Raise events
err := recorder.RecordEvent(ctx, &events.Event{
  Object:            obj,
  RelatedObject:     robj,
  ReportingInstance: "controller",
  Name:              schema.EventSliceConfigDeletionFailed,
})
  1. Raise events with slice/namespace name added at the time of raising events

In some cases, the recorder will be part of a controller which manages multiple namespaces. In that case, events can be raises by providing namespace like below instead of Initializing the recorder with specific namespace name.

recorder.WithNamespace(ns).RecordEvent(...)

recorder.WithSlice(sliceName).RecordEvent(...)

Disabling events

TODO: fill this section

Directories

Path Synopsis
hack
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL