-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #575 from ripienaar/api_limit_reached
Schema and structures for io.nats.jetstream.advisory.v1.api_limit_reached
- Loading branch information
Showing
3 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2024 The NATS Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package advisory | ||
|
||
import ( | ||
"github.com/nats-io/jsm.go/api/event" | ||
) | ||
|
||
// JSAPILimitReachedAdvisoryV1 is an advisory published when the system drops incoming | ||
// API requests in order to protect itself against denial of service. | ||
// | ||
// NATS Schema: io.nats.jetstream.advisory.v1.api_limit_reached | ||
type JSAPILimitReachedAdvisoryV1 struct { | ||
event.NATSEvent | ||
|
||
Server string `json:"server"` // Server that created the event, name or ID | ||
Domain string `json:"domain,omitempty"` // Domain the server belongs to | ||
Dropped int64 `json:"dropped"` // How many messages did we drop from the queue | ||
} | ||
|
||
func init() { | ||
err := event.RegisterTextCompactTemplate("io.nats.jetstream.advisory.v1.api_limit_reached", `{{ .Time | ShortTime }} [JS API Limit] {{ .Server }} {{ if .Domain }}in domain {{.Domain}} {{ end }}discarded {{ .Dropped | Int64Commas }} messages`) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = event.RegisterTextExtendedTemplate("io.nats.jetstream.advisory.v1.api_limit_reached", ` | ||
[{{ .Time | ShortTime }}] [{{ .ID }}] API Limit Reached | ||
Dropped: {{ .Dropped }} | ||
Domain: {{ .Domain }}`) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
schema_source/jetstream/advisory/v1/api_limit_reached.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://nats.io/schemas/jetstream/advisory/v1/api_limit_reached.json", | ||
"description": "An Advisory when the server takes action after very high number of pending API operations", | ||
"title": "io.nats.jetstream.advisory.v1.api_limit_reached", | ||
"type": "object", | ||
"required": [ | ||
"type", | ||
"id", | ||
"timestamp", | ||
"server", | ||
"dropped" | ||
], | ||
"additionalProperties": false, | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"const": "io.nats.jetstream.advisory.v1.api_limit_reached" | ||
}, | ||
"id": { | ||
"type": "string", | ||
"description": "Unique correlation ID for this event" | ||
}, | ||
"timestamp": { | ||
"type": "string", | ||
"description": "The time this event was created in RFC3339 format" | ||
}, | ||
"server": { | ||
"type": "string", | ||
"description": "The server this event originates from, either a generated ID or the configured name", | ||
"minLength": 1 | ||
}, | ||
"domain": { | ||
"type": "string", | ||
"minimum": 1, | ||
"description": "The domain of the JetStreamServer" | ||
}, | ||
"dropped": { | ||
"type": "integer", | ||
"description": "The number of messages removed from the QPI queue" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://nats.io/schemas/jetstream/advisory/v1/api_limit_reached.json", | ||
"description": "An Advisory when the server takes action after very high number of pending API operations", | ||
"title": "io.nats.jetstream.advisory.v1.api_limit_reached", | ||
"type": "object", | ||
"required": [ | ||
"type", | ||
"id", | ||
"timestamp", | ||
"server", | ||
"dropped" | ||
], | ||
"additionalProperties": false, | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"const": "io.nats.jetstream.advisory.v1.api_limit_reached" | ||
}, | ||
"id": { | ||
"type": "string", | ||
"description": "Unique correlation ID for this event" | ||
}, | ||
"timestamp": { | ||
"type": "string", | ||
"description": "The time this event was created in RFC3339 format" | ||
}, | ||
"server": { | ||
"type": "string", | ||
"description": "The server this event originates from, either a generated ID or the configured name", | ||
"minLength": 1 | ||
}, | ||
"domain": { | ||
"type": "string", | ||
"minimum": 1, | ||
"description": "The domain of the JetStreamServer" | ||
}, | ||
"dropped": { | ||
"type": "integer", | ||
"description": "The number of messages removed from the QPI queue" | ||
} | ||
} | ||
} |