Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azsystemevents] First generation of package for Azure Event Grid system events #22400

Merged
merged 12 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sdk/messaging/eventgrid/azsystemevents/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 0.1.0 (TBD)

### Features Added

- Initial preview for Event Grid system events.
21 changes: 21 additions & 0 deletions sdk/messaging/eventgrid/azsystemevents/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
103 changes: 103 additions & 0 deletions sdk/messaging/eventgrid/azsystemevents/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Azure Event Grid System Events Module for Go

Azure Event Grid system events are published by Azure services to system topics. The models in this package map to events sent by various Azure services.

Key links:
- [Source code][source]
- [API Reference Documentation][godoc]
- [Product documentation][product_docs]
- [Samples][godoc_examples]

## Getting started

### Install the package

Install the Azure Event Grid system events module for Go with `go get`:

```bash
go get github.com/Azure/azure-sdk-for-go/sdk/messaging/eventgrid/azsystemevents
```

### Prerequisites

- Go, version 1.18 or higher

# Key concepts

Event subscriptions can be used to forward events from an [Event Grid system topic][system_topics] to a data source, like [Azure Storage Queues][event_handler_storage_queues]. The payload will be formatted as an array of events, using the event envelope (Cloud Event Schema or Event Grid Schema) configured within the subscription.

To consume events, use the client package for that service. For example, if the Event Grid subscription uses an an Azure Storage Queue, we would use the [azqeueue](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue) package to consume it.

# Examples

Examples for deserializing system events can be found on [pkg.go.dev][godoc_examples] or in the example*_test.go files in our GitHub repo for [azsystemevents][source].

# Troubleshooting

### Logging

This module uses the classification-based logging implementation in `azcore`. To enable console logging for all SDK modules, set the environment variable `AZURE_SDK_GO_LOGGING` to `all`.

Use the `azcore/log` package to control log event output.

```go
import (
"fmt"
azlog "github.com/Azure/azure-sdk-for-go/sdk/azcore/log"
)

// print log output to stdout
azlog.SetListener(func(event azlog.Event, s string) {
fmt.Printf("[%s] %s\n", event, s)
})
```

# Next steps

More sample code should go here, along with links out to the appropriate example tests.

## Contributing
For details on contributing to this repository, see the [contributing guide][azure_sdk_for_go_contributing].

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

### Additional Helpful Links for Contributors
Many people all over the world have helped make this project better. You'll want to check out:

* [What are some good first issues for new contributors to the repo?](https://github.com/azure/azure-sdk-for-go/issues?q=is%3Aopen+is%3Aissue+label%3A%22up+for+grabs%22)
* [How to build and test your change][azure_sdk_for_go_contributing_developer_guide]
* [How you can make a change happen!][azure_sdk_for_go_contributing_pull_requests]
* Frequently Asked Questions (FAQ) and Conceptual Topics in the detailed [Azure SDK for Go wiki](https://github.com/azure/azure-sdk-for-go/wiki).

<!-- ### Community-->
### Reporting security issues and security bugs

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) <[email protected]>. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the [Security TechCenter](https://www.microsoft.com/msrc/faqs-report-an-issue).

### License

Azure SDK for Go is licensed under the [MIT](https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/template/aztemplate/LICENSE.txt) license.

<!-- LINKS -->
[azure_sdk_for_go_contributing]: https://github.com/Azure/azure-sdk-for-go/blob/main/CONTRIBUTING.md
[azure_sdk_for_go_contributing_developer_guide]: https://github.com/Azure/azure-sdk-for-go/blob/main/CONTRIBUTING.md#developer-guide
[azure_sdk_for_go_contributing_pull_requests]: https://github.com/Azure/azure-sdk-for-go/blob/main/CONTRIBUTING.md#pull-requests
[azure_cli]: https://docs.microsoft.com/cli/azure
[azure_portal]: https://portal.azure.com
[azure_sub]: https://azure.microsoft.com/free/
[event_handler_storage_queues]: https://learn.microsoft.com/azure/event-grid/handler-storage-queues
[event_handlers]: https://learn.microsoft.com/azure/event-grid/overview#event-handlers
[product_docs]: https://learn.microsoft.com/azure/event-grid/overview
[system_topics]: https://learn.microsoft.com/azure/event-grid/system-topics
[source]: https://azsdk/go/systemevents/src
[godoc_examples]: https://azsdk/go/systemevents/pkg#pkg-examples
123 changes: 123 additions & 0 deletions sdk/messaging/eventgrid/azsystemevents/autorest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
## Go

``` yaml
title: AzureEventGridSystemEvents
description: Azure Event Grid system events
generated-metadata: false
clear-output-folder: false
go: true
require: https://github.com/Azure/azure-rest-api-specs/blob/11bbc2b1df2e915a2227a6a1a48a27b9e67c3311/specification/eventgrid/data-plane/readme.md
license-header: MICROSOFT_MIT_NO_VERSION
openapi-type: "data-plane"
output-folder: ../azsystemevents
override-client-name: ClientDeleteMe
security: "AADToken"
use: "@autorest/[email protected]"
version: "^3.0.0"
module: github.com/Azure/azure-sdk-for-go/sdk/messaging/eventgrid/azsystemevents
slice-elements-byval: true
remove-non-reference-schema: true
batch:
- tag: package-2018-01
directive:
- from: swagger-document
where: $
transform: $['paths'] = {}; return $;
- from: swagger-document
where: $.definitions.MediaJobOutput
transform: >
$.required.push("@odata.type");
$["x-csharp-usage"] = "model,output";
- from: swagger-document
where: $.definitions.CloudEventEvent
transform: $["x-ms-external"] = true
- from:
- models.go
- models_serde.go
where: $
transform: |
return $.replace(/ResourceActionCancelData/g, 'ResourceActionCancelEventData')
.replace(/ResourceActionFailureData/g, 'ResourceActionFailureEventData')
.replace(/ResourceActionSuccessData/g, 'ResourceActionSuccessEventData')
.replace(/ResourceDeleteCancelData/g, 'ResourceDeleteCancelEventData')
.replace(/ResourceDeleteFailureData/g, 'ResourceDeleteFailureEventData')
.replace(/ResourceDeleteSuccessData/g, 'ResourceDeleteSuccessEventData')
.replace(/ResourceWriteCancelData/g, 'ResourceWriteCancelEventData')
.replace(/ResourceWriteFailureData/g, 'ResourceWriteFailureEventData')
.replace(/ResourceWriteSuccessData/g, 'ResourceWriteSuccessEventData')
```

```yaml
directive:
- from:
- models.go
- responses.go
- options.go
where: $
transform: return $.replace(/CloudEventEvent/g, "CloudEvent");
- from:
- models.go
- models_serde.go
- responses.go
- options.go
where: $
transform: return $.replace(/Schema of the Data property of an EventGridEvent/g, "Schema of the Data property of an CloudEvent/EventGridEvent");
```

```yaml
directive:
- from:
- models.go
- models_serde.go
where: $
transform: |
return $
.replace(/ChannelLatencyMs \*string/g, "ChannelLatencyMS *string")
.replace(/m.ChannelLatencyMs/g, "m.ChannelLatencyMS");
```

```yaml
directive:
- from: constants.go
where: $
transform: return $.replace(/EventGridMqttClientDisconnectionReason/g, "EventGridMQTTClientDisconnectionReason")
- from: models.go
where: $
transform: return $.replace(/DisconnectionReason \*EventGridMqttClientDisconnectionReason/, "DisconnectionReason *EventGridMQTTClientDisconnectionReason")
```

Manually map n/a to the zero value for the type for `MediaLiveEventChannelArchiveHeartbeatEventData` and `MediaLiveEventIngestHeartbeatEventData`

```yaml
directive:
- from: models_serde.go
where: $
transform: |
return $
.replace(/(\s+err = unpopulate\(val, "IngestDriftValue", &m.IngestDriftValue\))/, "$1\nfixNAValue(&m.IngestDriftValue)")
.replace(/(\s+err = unpopulate\(val, "ChannelLatencyMs", &m.ChannelLatencyMS\))/, "$1\nfixNAValue(&m.ChannelLatencyMS)");
```

Rename `AcsRouterWorkerSelector.TTLSeconds` to `TimeToLive`

```yaml
directive:
- from:
- models.go
where: $
transform: return $.replace(/TTLSeconds \*float32/g, "TimeToLive *float32");
- from:
- models_serde.go
where: $
transform: return $.replace(/a\.TTLSeconds/g, "a.TimeToLive");
```

Fix the EventGridEvent deserialization to work similar to CloudEvent.

```yaml
directive:
- from: models_serde.go
where: $
transform: |
return $.replace(/err = unpopulate\(val, "Data", &e.Data\)/, "e.Data = []byte(val)")
```
12 changes: 12 additions & 0 deletions sdk/messaging/eventgrid/azsystemevents/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build go1.18
// +build go1.18

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

//go:generate autorest ./autorest.md
//go:generate goimports -w ./..
//go:generate go run ./internal/generate generate
//go:generate goimports -w ./..

package azsystemevents
35 changes: 35 additions & 0 deletions sdk/messaging/eventgrid/azsystemevents/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file.
trigger:
branches:
include:
- main
- feature/*
- hotfix/*
- release/*
paths:
include:
- sdk/messaging/eventgrid/azsystemevents

pr:
branches:
include:
- main
- feature/*
- hotfix/*
- release/*
paths:
include:
- sdk/messaging/eventgrid/azsystemevents

stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: "messaging/eventgrid/azsystemevents"
RunLiveTests: true
UsePipelineProxy: false
Location: westus2
EnvVars:
AZURE_CLIENT_ID: $(AZSYSTEMEVENTS_CLIENT_ID)
AZURE_TENANT_ID: $(AZSYSTEMEVENTS_TENANT_ID)
AZURE_CLIENT_SECRET: $(AZSYSTEMEVENTS_CLIENT_SECRET)
AZURE_SUBSCRIPTION_ID: $(AZSYSTEMEVENTS_SUBSCRIPTION_ID)
Loading