Skip to content

Commit

Permalink
[receiver/azureeventhub] Set Consumer Group by Configuration (open-te…
Browse files Browse the repository at this point in the history
…lemetry#28634)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
Allow the Consumer Group to be set in the Configuration.

**Link to tracking Issue:** <Issue number if applicable>
[open-telemetry#28633]

**Testing:** <Describe what testing was performed and which tests were
added.>
Locally tested and verified. No unit testing added.

**Documentation:** <Describe the documentation added.>
New configuration option added to README.
  • Loading branch information
cparkins authored and RoryCrispin committed Nov 24, 2023
1 parent 544655d commit 4b6f920
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: azureevenhubreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Allow the Consumer Group to be set in the Configuration.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [28633]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
4 changes: 4 additions & 0 deletions receiver/azureeventhubreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Event Hub, transforms them, and pushes them through the collector pipeline.
### connection (Required)
A string describing the connection to an Azure event hub.

### group (Optional)
The Consumer Group to read from. If empty will default to the default Consumer Group $Default

### partition (Optional)
The partition to watch. If empty, it will watch explicitly all partitions.

Expand All @@ -49,6 +52,7 @@ receivers:
azureeventhub:
connection: Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName
partition: foo
group: bar
offset: "1234-5566"
format: "azure"
```
Expand Down
11 changes: 6 additions & 5 deletions receiver/azureeventhubreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ var (
)

type Config struct {
Connection string `mapstructure:"connection"`
Partition string `mapstructure:"partition"`
Offset string `mapstructure:"offset"`
StorageID *component.ID `mapstructure:"storage"`
Format string `mapstructure:"format"`
Connection string `mapstructure:"connection"`
Partition string `mapstructure:"partition"`
Offset string `mapstructure:"offset"`
StorageID *component.ID `mapstructure:"storage"`
Format string `mapstructure:"format"`
ConsumerGroup string `mapstructure:"group"`
}

func isValidFormat(format string) bool {
Expand Down
12 changes: 9 additions & 3 deletions receiver/azureeventhubreceiver/eventhubhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,18 @@ func (h *eventhubHandler) run(ctx context.Context, host component.Host) error {

func (h *eventhubHandler) setUpOnePartition(ctx context.Context, partitionID string, applyOffset bool) error {

offsetOption := eventhub.ReceiveWithLatestOffset()
receiverOptions := []eventhub.ReceiveOption{}
if applyOffset && h.config.Offset != "" {
offsetOption = eventhub.ReceiveWithStartingOffset(h.config.Offset)
receiverOptions = append(receiverOptions, eventhub.ReceiveWithStartingOffset(h.config.Offset))
} else {
receiverOptions = append(receiverOptions, eventhub.ReceiveWithLatestOffset())
}

if h.config.ConsumerGroup != "" {
receiverOptions = append(receiverOptions, eventhub.ReceiveWithConsumerGroup(h.config.ConsumerGroup))
}

handle, err := h.hub.Receive(ctx, partitionID, h.newMessageHandler, offsetOption)
handle, err := h.hub.Receive(ctx, partitionID, h.newMessageHandler, receiverOptions...)
if err != nil {
return err
}
Expand Down

0 comments on commit 4b6f920

Please sign in to comment.