-
Notifications
You must be signed in to change notification settings - Fork 153
Open
Labels
area/alertingAlerting related issues and PRsAlerting related issues and PRsarea/apiAPI related issues and pull requestsAPI related issues and pull requestsenhancementNew feature or requestNew feature or request
Description
After RFC-0008, users have now the ability to define object-level annotations for sending custom metadata to notification providers. This could be used to give users a finer control over how events are rate-limited:
notification-controller/internal/server/event_server.go
Lines 221 to 262 in eddaf14
| // eventKeyFunc generates a unique key for an event based on the provided HTTP | |
| // request, which can be used to deduplicate events. The key is calculated by | |
| // concatenating specific event attributes and hashing them using SHA-256. | |
| // The key is then returned as a hex-encoded string. | |
| // | |
| // The event attributes are prefixed with an identifier to avoid collisions | |
| // between different event attributes. | |
| func eventKeyFunc(r *http.Request) (string, error) { | |
| event := r.Context().Value(eventContextKey{}).(*eventv1.Event) | |
| comps := []string{ | |
| "event", | |
| "name=" + event.InvolvedObject.Name, | |
| "namespace=" + event.InvolvedObject.Namespace, | |
| "kind=" + event.InvolvedObject.Kind, | |
| "message=" + event.Message, | |
| } | |
| objectGroup := event.InvolvedObject.GetObjectKind().GroupVersionKind().Group | |
| originRevisionKey := fmt.Sprintf("%s/%s", objectGroup, eventv1.MetaOriginRevisionKey) | |
| originRevision, ok := event.Metadata[originRevisionKey] | |
| if ok { | |
| comps = append(comps, "originRevision="+originRevision) | |
| } | |
| revisionKey := fmt.Sprintf("%s/%s", objectGroup, eventv1.MetaRevisionKey) | |
| revision, ok := event.Metadata[revisionKey] | |
| if ok { | |
| comps = append(comps, "revision="+revision) | |
| } | |
| tokenKey := fmt.Sprintf("%s/%s", objectGroup, eventv1.MetaTokenKey) | |
| token, ok := event.Metadata[tokenKey] | |
| if ok { | |
| comps = append(comps, "token="+token) | |
| } | |
| key := strings.Join(comps, "/") | |
| digest := sha256.Sum256([]byte(key)) | |
| return fmt.Sprintf("%x", digest), nil | |
| } |
We could use the API eventv1.MetaTokenKey, that was created for this purpose. Today, this key is looked up using the object API Group:
notification-controller/internal/server/event_server.go
Lines 253 to 257 in eddaf14
| tokenKey := fmt.Sprintf("%s/%s", objectGroup, eventv1.MetaTokenKey) | |
| token, ok := event.Metadata[tokenKey] | |
| if ok { | |
| comps = append(comps, "token="+token) | |
| } |
We could look up with the new API Group defined in RFC-0008 the same way:
tokenKey = fmt.Sprintf("%s/%s", eventv1.Group, eventv1.MetaTokenKey)
token, ok = event.Metadata[tokenKey]
if ok {
comps = append(comps, "token="+token)
} Then both tokens can be appended to the rate-limiting key components.
hawkaii
Metadata
Metadata
Assignees
Labels
area/alertingAlerting related issues and PRsAlerting related issues and PRsarea/apiAPI related issues and pull requestsAPI related issues and pull requestsenhancementNew feature or requestNew feature or request