ClusterCockpit / cc-metric-collector

A node agent for measuring, processing and forwarding node level metrics
MIT License
4 stars 7 forks source link

New Message processor #118

Open TomTheBear opened 4 months ago

TomTheBear commented 4 months ago

New message processor using expr instead of gval

Can be integrated anywhere to check:

It accepts a json.RawMessage as configuration and parses it. Therefore it can be integrated into other configs:

type myConfig struct {
  Myfield string `json:"myfield"`
  MessageProcessor json.RawMessage `json:"process_messages"`
}

For initialization:

p, err := mp.NewMessageProcessor()
if err != nil {
  return fmt.Errorf("initialization of message processor failed: %v", err.Error())
}
err = p.FromConfigJSON(config.MessageProcessor)
if err != nil {
  return fmt.Errorf("failed parsing JSON for message processor: %v", err.Error())
}

Usage:

drop, err := p.ProcessMessage(msg)
if err == nil && !drop {
  // do something with m
}

Rules can also be added and removed at runtime using the various Add/Remove functions of p (in the above examples).

Plan is to integrate it in every component that sends or receives messages to filter them based on the configuration.