Table of Contents:
Environment variables will need to be placed into a couple different (potential) places:
app.yaml
ci.env
- Any other .env files desired (such as custom workstation files)
It is best practice have a parent prefix key, such as EVENTS_
to avoid collisions with other potentially needed Queue configurations. The Event code in common-go uses a small handful of variables, The most important of which is the TYPE
var which drives how the others are used. Those being LOG_PATH
, STREAM_NAME
, and QUEUE_URL
For the sake of configuring an SQS queue, we will be focusing on TYPE=QUEUE
. When using the QUEUE
type, we are also required to specify the QUEUE_URL
variable.
Origin will automatically populate the needed variables by providing the following configuration in the app.yaml
:
configuration:
# Generate events
- name: events
type: events
Per the documentation, this defaults to a queue with the same name as the app, but we can customize this to push events into the desired queue by specifying the pipeline: <desired queue pipeline>
, should it differ from the default.
We can set defaults in code to avoid needing to specify them the .env files used by workstation and the CI builds. SCIM takes this approach, and defaults to FILE
for the queue type. Example pull from the jumpcloud-scim defaults:
KeyEvents: map[string]interface{}{
jcconfig.KeyEventType: jcconfig.FileEventType,
jcconfig.KeyEventLogPath: "/var/log/jumpcloud-events/scim-events.log",
},
It seems recommended to let our services default to a file for event logs, and configure it to push to a Queue in staging/production.
Loading the environment variables is done by passing a source into jcconfig.NewEvents(...)
, which will load the appropriate values and perform input verification.
With an EventsLoggerConfig, this can be passed in to jcevents.NewEventLogger(...)
to get the full logger created.
From there, passing the logger to the needed places is all that's needed before logging events:
err = s.eventLogger.Log(...)
if err != nil {
fmt.Printf("error logging event: %v", err)
}
We'll need to build out our generic map, or potentially have some sort of JSON object we build into the event body?
- Do we want a dedicated object for a given event? Maybe that consistency would be good to have pinned down (as opposed to the free-form fun of the JS world?