Skip to content

Commit

Permalink
event hub fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-saharn committed Oct 24, 2024
1 parent 88133d0 commit c8d9a9b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
10 changes: 9 additions & 1 deletion plugins/outputs/microsoft_fabric/microsoft_fabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/influxdata/telegraf/plugins/outputs"
ADX "github.com/influxdata/telegraf/plugins/outputs/azure_data_explorer"
EH "github.com/influxdata/telegraf/plugins/outputs/event_hubs"
"github.com/influxdata/telegraf/plugins/serializers/json"
)

//go:embed sample.conf
Expand Down Expand Up @@ -54,8 +55,15 @@ func (m *MicrosoftFabric) Init() error {

if strings.HasPrefix(ConnectionString, "Endpoint=sb") {
m.Log.Info("Detected EventHouse endpoint, using EventHouse output plugin")

//Need discussion on it
serializer := &json.Serializer{
TimestampUnits: config.Duration(time.Nanosecond),
TimestampFormat: time.RFC3339Nano,
}
m.EHConf.ConnectionString = ConnectionString
m.EHConf.Log = m.Log
m.EHConf.SetSerializer(serializer)
m.EHConf.Init()
m.FabricSinkService = m.EHConf
} else if isKustoEndpoint(strings.ToLower(ConnectionString)) {
Expand All @@ -73,7 +81,6 @@ func (m *MicrosoftFabric) Init() error {

func isKustoEndpoint(endpoint string) bool {
prefixes := []string{
"https://",
"data source=",
"addr=",
"address=",
Expand All @@ -98,6 +105,7 @@ func init() {
CreateTables: true,
},
EHConf: &EH.EventHubs{
Hub: &eventHub{},
Timeout: config.Duration(30 * time.Second),
},
}
Expand Down
28 changes: 28 additions & 0 deletions plugins/outputs/microsoft_fabric/microsoft_fabric_eh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package microsoft_fabric

import (
"context"

eventhub "github.com/Azure/azure-event-hubs-go/v3"
)

type eventHub struct {
hub *eventhub.Hub
}

func (e *eventHub) GetHub(connectionString string) error {
hub, err := eventhub.NewHubFromConnectionString(connectionString)
if err != nil {
return err
}
e.hub = hub
return nil
}

func (e *eventHub) Close(ctx context.Context) error {
return e.hub.Close(ctx)
}

func (e *eventHub) SendBatch(ctx context.Context, iterator eventhub.BatchIterator, opts ...eventhub.BatchOption) error {
return e.hub.SendBatch(ctx, iterator, opts...)
}

0 comments on commit c8d9a9b

Please sign in to comment.