From 194b6e521f48d2cae2d2c68e78699b8816684884 Mon Sep 17 00:00:00 2001 From: Anders Eknert Date: Thu, 27 Apr 2023 09:52:56 +0200 Subject: [PATCH] docs: mention ID property of sdk.Options and its benefits Fixes #5875 Signed-off-by: Anders Eknert --- docs/content/integration.md | 5 +++++ sdk/options.go | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/content/integration.md b/docs/content/integration.md index fc9a57e340..223260b5e5 100644 --- a/docs/content/integration.md +++ b/docs/content/integration.md @@ -236,6 +236,7 @@ func main() { // create an instance of the OPA object opa, err := sdk.New(ctx, sdk.Options{ + ID: "opa-test-1", Config: bytes.NewReader(config), }) if err != nil { @@ -256,6 +257,10 @@ func main() { If you executed this code, the output (i.e. [Decision Log](https://www.openpolicyagent.org/docs/latest/management-decision-logs/) event) would be logged to the console by default. +Setting an `ID` in `sdk.Options` is optional, but recommended. If you do not set an `ID`, a random one will be created +for the system. While this is fine for testing, it makes it difficult to monitor the system over time, as a new ID will +be created each time the SDK is initialized, such as when the process is restarted. + ### Integrating with the Go API Use the low-level diff --git a/sdk/options.go b/sdk/options.go index ff2371973b..51e9a5a25b 100644 --- a/sdk/options.go +++ b/sdk/options.go @@ -39,7 +39,9 @@ type Options struct { // registered with the OPA SDK instance. Plugins map[string]plugins.Factory - // When calling the sdk the user can specify an opa id so that repeat calls to the sdk don't have a unique opa id + // ID provides an option to set a static ID for the OPA system, avoiding + // the need to generate a random one at initialization. Setting a static ID + // is recommended, as it makes it easier to track the system over time. ID string config []byte