Skip to content

Commit

Permalink
Merge pull request edgexfoundry#795 from lenny-intel/system-events-adr
Browse files Browse the repository at this point in the history
feat: Create System Events ADR
  • Loading branch information
Lenny Goodell authored Jul 25, 2022
2 parents 78249f7 + af55690 commit df1bac9
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 24 deletions.
49 changes: 25 additions & 24 deletions docs_src/design/TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@

## Architectural Design Records (ADRs)

| Name/Link | Short Description |
| -------------------------------------------------------------------- | ----------------------------------------------- |
| [0001 Registry Refactor](./adr/0001-Registy-Refactor.md) | Separate out Registry and Configuration APIs |
| [0002 Array Datatypes](./adr/device-service/0002-Array-Datatypes.md) | Allow Arrays to be held in Readings |
| [0003 V2 API Principles](./adr/core/0003-V2-API-Principles.md) | Principles and Goals of V2 API Design |
| [0004 Feature Flags](./adr/0004-Feature-Flags.md) | Feature Flag Implementation |
| [0005 Service Self Config Init](./adr/0005-Service-Self-Config.md) | Service Self Config Init & Config Seed Removal |
| [0006 Metrics Collection](./adr/0006-Metrics-Collection.md) | Collection of service telemetry data |
| [0007 Release Automation](./adr/devops/0007-Release-Automation.md) | Overview of Release Automation Flow for EdgeX |
| [0008 Secret Distribution](./adr/security/0008-Secret-Creation-and-Distribution.md) | Creation and Distribution of Secrets |
| [0009 Secure Bootstrapping](./adr/security/0009-Secure-Bootstrapping.md) | Secure Bootstrapping of EdgeX |
| [0011 Device Service REST API](./adr/device-service/0011-DeviceService-Rest-API.md) | The REST API for Device Services in EdgeX v2.x |
| [0012 Device Service Filters](./adr/device-service/0012-DeviceService-Filters.md) | Device Service event/reading filters |
| [0013 Device Service Events via Message Bus](./adr/013-Device-Service-Events-Message-Bus.md) | Device Services send Events via Message Bus |
| [0014 Secret Provider for All](./adr/014-Secret-Provider-For-All.md) | Secret Provider for All EdgeX Services |
| [0015 Encryption between microservices](./adr/security/0015-in-cluster-tls.md) | Details conditions under which TLS is or is not used |
| [0016 Container Image Guidelines](./adr/security/0016-docker-image-guidelines.md) | Documents best practices for security of docker images |
| [0017 Securing access to Consul](./adr/security/0017-consul-security.md) | Access control and authorization strategy for Consul |
| [0018 Service Registry](./adr/0018-Service-Registry.md) | Service registry usage for EdgeX services |
| [0019 EdgeX-CLI V2](./adr/core/0019-EdgeX-CLI-V2.md) | EdgeX-CLI V2 Implementation |
| [0020 Delay start services (SPIFFE/SPIRE)](./adr/security/0020-spiffe.md) | Secret store tokens for delayed start services |
| [0021 Device Profile Changes](./adr/core/0021-Device-Profile-Changes.md) | Rules on device profile modifications |
| [0022 Unit of Measure](./adr/core/0022-UoM.md) | Unit of Measure|
| [0023 North South Messaging](./adr/0023-North-South-Messaging.md) | Provide for messaging from north side systems through command down to device services |
| Name/Link | Short Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| [0001 Registry Refactor](./adr/0001-Registy-Refactor.md) | Separate out Registry and Configuration APIs |
| [0002 Array Datatypes](./adr/device-service/0002-Array-Datatypes.md) | Allow Arrays to be held in Readings |
| [0003 V2 API Principles](./adr/core/0003-V2-API-Principles.md) | Principles and Goals of V2 API Design |
| [0004 Feature Flags](./adr/0004-Feature-Flags.md) | Feature Flag Implementation |
| [0005 Service Self Config Init](./adr/0005-Service-Self-Config.md) | Service Self Config Init & Config Seed Removal |
| [0006 Metrics Collection](./adr/0006-Metrics-Collection.md) | Collection of service telemetry data |
| [0007 Release Automation](./adr/devops/0007-Release-Automation.md) | Overview of Release Automation Flow for EdgeX |
| [0008 Secret Distribution](./adr/security/0008-Secret-Creation-and-Distribution.md) | Creation and Distribution of Secrets |
| [0009 Secure Bootstrapping](./adr/security/0009-Secure-Bootstrapping.md) | Secure Bootstrapping of EdgeX |
| [0011 Device Service REST API](./adr/device-service/0011-DeviceService-Rest-API.md) | The REST API for Device Services in EdgeX v2.x |
| [0012 Device Service Filters](./adr/device-service/0012-DeviceService-Filters.md) | Device Service event/reading filters |
| [0013 Device Service Events via Message Bus](./adr/013-Device-Service-Events-Message-Bus.md) | Device Services send Events via Message Bus |
| [0014 Secret Provider for All](./adr/014-Secret-Provider-For-All.md) | Secret Provider for All EdgeX Services |
| [0015 Encryption between microservices](./adr/security/0015-in-cluster-tls.md) | Details conditions under which TLS is or is not used |
| [0016 Container Image Guidelines](./adr/security/0016-docker-image-guidelines.md) | Documents best practices for security of docker images |
| [0017 Securing access to Consul](./adr/security/0017-consul-security.md) | Access control and authorization strategy for Consul |
| [0018 Service Registry](./adr/0018-Service-Registry.md) | Service registry usage for EdgeX services |
| [0019 EdgeX-CLI V2](./adr/core/0019-EdgeX-CLI-V2.md) | EdgeX-CLI V2 Implementation |
| [0020 Delay start services (SPIFFE/SPIRE)](./adr/security/0020-spiffe.md) | Secret store tokens for delayed start services |
| [0021 Device Profile Changes](./adr/core/0021-Device-Profile-Changes.md) | Rules on device profile modifications |
| [0022 Unit of Measure](./adr/core/0022-UoM.md) | Unit of Measure |
| [0023 North South Messaging](./adr/0023-North-South-Messaging.md) | Provide for messaging from north side systems through command down to device services |
| [0024 System Events](./adr/0024-system-events.md) | System Events (aka Control Plane Events) published to the MessageBus |
100 changes: 100 additions & 0 deletions docs_src/design/adr/0024-system-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# System Events ADR
### Submitters
- Lenny Goodell (Intel)

## Change Log
- [approved](https://github.com/edgexfoundry/edgex-docs/pull/795) (2022-07-12)

## Referenced Use Case(s)
- [System Events for Devices ](https://docs.edgexfoundry.org/2.3/design/ucr/0001-System-Events-for-Devices/)

## Context
System Events, aka Control Plane Events (CPE), are new to EdgeX. This ADR addresses the [System Events for Devices](https://docs.edgexfoundry.org/2.3/design/ucr/0001-System-Events-for-Devices/) use case with an extensible design that can address other System Event use cases that may be identified in the future. This extensible design approach and the fact that System Events are produced and consumed by different EdgeX services makes it architecturally significant warranting this ADR.

## Proposed Design
To address the [System Events for Devices](https://docs.edgexfoundry.org/2.3/design/ucr/0001-System-Events-for-Devices/) use case, Core Metadata will publish a new `SystemEvent` DTO to the EdgeX MessageBus when a device is added, updated or deleted. Consumers of these System Events will subscribe to the MessageBus to receive the new `SystemEvent` DTO .

#### Data Transfer Object (DTO)

This new `SystemEvent` DTO will contain the following data describing the System Event:

- Source - Publisher of the System Event, i.e. core-metadata
- Type - Type of System Event, i.e. device
- Action - The Action that triggered the System Event, i.e. add/update/delete
- Timestamp - Creation date/time for the System Event
- Owner - Owner the data for the System Event, i.e device-onvif-camera as the device owner
- Optional based on the Type
- Tags - Key value pairs to add addition context to the System Event, i.e. device-profile=onvif-camera
- Optional based on the Type and/or Action
- Details - Data details important to the System Event, i.e. Device DTO of added/updated/deleted device
- Optional object which varies based on the Type and/or Action
- This an object similar to `ObjectValue` in `Reading` DTO

!!! note
As defined, this DTO should suffice for future System Event use cases.

#### MessageBus

Services that publish System Events (Core Metadata) must connect to the EdgeX MessageBus and have MessageBus configuration similar to that of Core Data's [here](https://github.com/edgexfoundry/edgex-go/blob/v2.2.0/cmd/core-data/res/configuration.toml#L53-L74). This design assumes that Core Metadata will have this capability and configuration due to planned implementation of Service Metrics.

The `PublishTopicPrefix` property in Core Metadata's `MessageQueue` configuration will be used for System Events and set to `edgex/system-event`.

#### MessageBus Topic

The new `SystemEvent` DTO will be published to a multi-level topic allowing subscribers to filter by topic. The format of this topic for **System Events** will be:

`{PublishTopicPrefix}/{source}/{type}/{action}`

where

- `{source}` = Publisher of the System Event, i.e. `core-metadata`
- `{type}` = Type of System Event, i.e. `device`
- `{action}` = The Action that triggered the System Event, i.e. `add`

Specific use cases may add additional levels as needed. The **Device System Events** use case will add the following levels

- `{owner}` = Owner the data for the System Event, i.e `device-onvif-camera` as the device owner`
- `{profile}` = Device profile associated with the Device, i.e `onvif-camera`

!!! example - "Example - System Event subscription topics"
```
edgex/system-event/# - All system events
edgex/system-event/core-metadata/# - only system events from Core Metadata
edgex/system-event/core-metadata/device/# - only device system events from Core Metadata
edgex/system-event/core-metadata/device/add/device-onvif-camera/# - only add device system events for device-onvif-camera
edgex/system-event/core-metadata/device/#/#/onvif-camera - only device system events for devices created for the onvif-camera device profile
```

#### Consumers

Consumers of Device System Events will likely be custom application services as described in [System Events for Devices ](https://docs.edgexfoundry.org/2.3/design/ucr/0001-System-Events-for-Devices/). No changes are required to the App Functions SDK since it already supports processing of different types via the [Target Type](https://docs.edgexfoundry.org/2.2/microservices/application/AdvancedTopics/#target-type) capability. Developers of custom application services that consume System Events will need to do the following:

- Set the Target Type to `&dtos.SystemEvent{}` when creating an instance of `ApplicationService` using the [NewAppServiceWithTargetType](https://docs.edgexfoundry.org/2.2/microservices/application/ApplicationServiceAPI/#newappservicewithtargettype) factory function.
- Write custom pipeline function that expects the new `SystemEvent` DTO and process it accordingly. Similar to how the [ToLineProtocol](https://docs.edgexfoundry.org/2.2/microservices/application/BuiltIn/#tolineprotocol) pipeline function expects the Metric DTO.

### Services/Modules impacted

- Core Metadata service
- This service is the single point for device Add/Update/Delete and will be the producer of Device System Events.
- Core Contracts module
- The new `SystemEvent` DTO will be added to this repository
- Camera Management App Service Example
- Once Device System Events are implemented, the [Camera Management](https://github.com/edgexfoundry/edgex-examples/tree/main/application-services/custom/camera-management) example can be updated to consume them.
- Device SDK/Service (future)
- Once Device System Events are implemented, the Device SDKs can switch to receiving them via MesssageBus rather than the REST callbacks from Core Metadata. Anything beyond recognizing this future enhancement, it is out-of-scope for this ADR.


## Considerations
- This design approach can be used for future use cases, such as **System Events for Device Profiles** and **System Events for Device Services** when/if they are deemed needed.
- Another design approach that was considered is to use Support Notifications to send the System Events via REST. This would require consumers to create subscriptions to receive the Systems Events via REST to some endpoint on the consuming service. This subscription would be created using the existing Support Notifications [subscription](https://app.swaggerhub.com/apis/EdgeXFoundry1/support-notifications/2.2.0#/default/post_subscription) REST API. Likely each subscription would be for a specific Event Type. System Events would be Published by POSTing them to Support Notification [notification](https://app.swaggerhub.com/apis/EdgeXFoundry1/support-notifications/2.2.0#/default/post_notification) REST API, which would them forward them via REST POST to each service subscribed to the particular System Event. The System Event DTO would still be used, just sent via the REST. This approach is more complex, requires consumer services to have new REST endpoint(s) to receive the System Events and relies on REST rather than messaging, thus this approach was not chosen.

## Decision
This design will satisfy the [System Events for Devices](https://docs.edgexfoundry.org/2.3/design/ucr/0001-System-Events-for-Devices/) use case as well as possibly other future System Event use cases.

## Other Related ADRs
- [Metric Collection ADR](https://docs.edgexfoundry.org/2.2/design/adr/0006-Metrics-Collection/) - Use of EdgeX MessageBus to publish and subscribe service metrics
- [North-South Messaging ADR](https://docs.edgexfoundry.org/2.2/design/adr/0023-North-South-Messaging/) - Use of EdgeX MessageBus to publish and subscribe commands/responses

## References
- Control Plane Events (CPE) (aka System Events) were initially proposed as part of the metrics collection ADR as early as March 2020. You may find discussions relevant to CPE in these ADR and other design/architecture discussions since March 2020.
- [initial ADR on EdgeX service level metrics collection for Hanoi](https://github.com/edgexfoundry/edgex-docs/pull/97)

0 comments on commit df1bac9

Please sign in to comment.