3

I am trying to develop an Azure Function to act upon a blob created by the Capture feature of an Event Hub. However, whereas capture blobs are correctly stored on the container, it seems that no Microsoft.EventHub.CaptureFileCreated event is published to the Function subscription. The event subscription to the function endpoint has been created without errors, and the output from the Azure CLI is

{
  "additionalProperties": {},
  "deadLetterDestination": null,
  "destination": {
    "additionalProperties": {},
    "endpointBaseUrl": "https://xxxxx-xxxxx-xxxxx.azurewebsites.net/api/EventGridWebhook",
    "endpointType": "WebHook",
    "endpointUrl": null
  },
  "eventDeliverySchema": "InputEventSchema",
  "filter": {
    "additionalProperties": {},
    "includedEventTypes": [
      "Microsoft.EventHub.CaptureFileCreated"
    ],
    "isSubjectCaseSensitive": null,
    "subjectBeginsWith": "",
    "subjectEndsWith": ""
  },
  "id": "/subscriptions/yyyyy-yyyyy-yyyyyy/resourceGroups/test-event-grid-grp/providers/Microsoft.EventHub/namespaces/capture-hub-namespace/providers/Microsoft.EventGrid/eventSubscriptions/captureFunctionV1Sub",
  "labels": null,
  "name": "captureFunctionV1Sub",
  "provisioningState": "Succeeded",
  "resourceGroup": "test-event-grid-grp",
  "retryPolicy": {
    "additionalProperties": {},
    "eventTimeToLiveInMinutes": 1440,
    "maxDeliveryAttempts": 30
  },
  "topic": "/subscriptions/yyyyy-yyyyy-yyyyyy/resourceGroups/test-event-grid-grp/providers/microsoft.eventhub/namespaces/capture-hub-namespace",
  "type": "Microsoft.EventGrid/eventSubscriptions"
}

The body of the function is a standard Http trigger with the additional validation part needed for the Event Grid endpoint subscription

public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
{
    string jsonContent = await req.Content.ReadAsStringAsync();
    log.Info($"Webhook was triggered! Input: {jsonContent}");
    dynamic events = JsonConvert.DeserializeObject(jsonContent);

    if (req.Headers.GetValues("Aeg-Event-Type").FirstOrDefault() == "SubscriptionValidation")
    {
        var code = events[0].Data["validationCode"];
        return req.CreateResponse(HttpStatusCode.OK,
            new { validationResponse = code });
    }

    return req.CreateResponse(HttpStatusCode.OK);
}

As an experiment, if I add the same function's endpoint for another type of event (f.i. a blob creation event), I can see the function invocations in the logs. Besides, in the Metrics blade of the event subscription, it seems like no event is ever published to the subscribers

Empty subscription publish metrics

Moreover, adding a subscription from the capture event to a Logic App or to a Storage Queue resulted in zero events being published, as with the webhook trigger. It is also worth noting that this doesn't work using both runtime environments for Azure functions (v1 and v2), and even when using the specific EventGridTrigger attribute instead of a generic Http trigger; however, other event types correctly publish the events and trigger the function.

For reference on possible reproduction steps, I took inspiration from this Microsoft tutorial, skipping the SQL Server/Data Warehouse part. While searching for other people having similar issue, I found this question which seems related to my case, but there is no clear answer or clue about what could be the problem. Something must be missing, but I have no idea what to try next.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241

1 Answers1

0

After a few days, it looks like this was a temporary issue with the infrastructure. This morning I performed additional tests and everything worked.

Moreover, I see the logs of my function being triggered successfully in the past days, without me changing anything.

  • Hi Riccardo, I am from the EventGrid team at Microsoft. Yes, this was a configuration issue in EventHub publishing to EventGrid and based on the details provided by you above, we were able to identify and fix the config issue on Jul 5. Sorry, I didn't get a chance to reply back earlier on this post. – J. Kalyana Sundaram Jul 10 '18 at 16:17
  • @j-kalyana-sundaram Thank you for the clarification, I was quite puzzled when I saw that everything started working without touching anything! – Riccardo Bellini Jul 11 '18 at 09:35