Skip to content

Instantly share code, notes, and snippets.

View paulbatum's full-sized avatar

Paul Batum paulbatum

View GitHub Profile
@paulbatum
paulbatum / program.cs
Last active March 18, 2023 06:37
Channel Factories
using System.Diagnostics;
using System.Threading.Channels;
static async Task MinerLoop(ChannelWriter<IronOre> destination, int total, ProductionMetrics metrics)
{
while (total > 0 && await destination.WaitToWriteAsync())
{
while (total > 0 && destination.TryWrite(new IronOre()))
@paulbatum
paulbatum / sensors.proto
Created September 14, 2017 19:45
Protocol buffers example
syntax = "proto3";
package sensors;
import "google/protobuf/timestamp.proto";
option csharp_namespace = "EventHubsThroughput.Models.Protobuf";
enum SensorType {
UNKNOWN = 0;
SEISMIC = 1;
WEATHER = 2;
@paulbatum
paulbatum / costcalculator.cs
Last active July 12, 2022 15:27
Azure Functions pricing calculation
const decimal executionCountCost = 0.20m / 1000000m;
const decimal gbSecCost = 0.000016m;
const decimal executionUnitsToGbSecConversion = 1m / (1024 * 1000);
long executionCountPerHour = 6500012;
long executionUnitsPerHour = 90305037184;
int runDurationDays = 9;
Console.WriteLine("All prices in USD");
@paulbatum
paulbatum / $readme.md
Last active September 2, 2021 05:30
secretless-azure-functions

Creating a Secretless Function App using Managed Identity

My goal is to make a fully secretless function app, and then add triggers for an Azure Storage queue and a Service Bus queue.

Step 1: Create the Function App without Azure Files

The first step is to create the function app, and configure it without Azure Files (because Azure Files doesn't support managed identity for SMB file shares). There is some documentation on this here. The portal doesn't provide that option today, but I can take the ARM template generated by the portal and modify it for my needs. So I go the through the create wizard, but instead of hitting Create, I hit the template button:

image

// Query Notes
// -------------
// 1. This query display detailed information for Event Hub triggered functions using telemetry emitted by the Event Hubs extension 4.2.0 and greater.
//
// 2. The data is only emitted in the correct format if batched dispatch is used i.e. the function accepts multiple events for each execution. This is the recommended way to write Event Hub triggered functions. For an example see the documentation https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-trigger?tabs=csharp
//
// 3. If sampling is enabled in Application Insights, then there might be gaps in the data. To configure sampling see https://docs.microsoft.com/en-us/azure/azure-functions/configure-monitoring?tabs=v2#configure-sampling
//
// 4. The dispatchTimeMilliseconds value approximates the length of time between when the event was written to the event hub and when it was picked up by the Function App for processing. Note that:
// a) dispatchTimeMilliseconds could be negative or othe
@paulbatum
paulbatum / Function1.cs
Last active January 24, 2019 18:38
Event Hub Batch Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.EventHubs;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace FunctionApp12
@paulbatum
paulbatum / gist:f7170955a46971456da2e69926af9d9d
Created October 19, 2018 18:14
Notification Hubs WebJobs SDK Extension error
DryIoc.ContainerException
HResult=0x80131509
Message=Unable to get constructor of NotificationHubsExtensionConfigProvider using provided constructor selector when resolving singleton NotificationHubsExtensionConfigProvider: IExtensionConfigProvider {ServiceKey=DefaultKey(4), ReturnDefaultIfNotRegistered} #105
in wrapper IEnumerable<IExtensionConfigProvider> as parameter "registeredExtensions" #1
in singleton DefaultExtensionRegistryFactory: IExtensionRegistryFactory #52
from container.
Source=Microsoft.Azure.WebJobs.Script.WebHost
StackTrace:
at DryIoc.Throw.ThrowIfNull[T](T arg, Int32 error, Object arg0, Object arg1, Object arg2, Object arg3) in C:\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs:line 8939
at DryIoc.ReflectionFactory.CreateExpressionOrDefault(Request request) in C:\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs:line 6996
{
"version": "2.0",
"extensions": {
"http": {
"maxConcurrentRequests": 1,
"maxOutstandingRequests": 4
}
}
}

Assembly Resolution in Azure Functions

The goal of this post is to help .NET developers better understand assembly resolution and loading problems and limitations.

One common provide guidance on how to avoid or mitigate some of those issues, when possible, and go over some of the details on how this will be improved in the next version of Azure Functions.

In the following sections, we dive into the details of how things work today

using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
namespace FunctionApp14
{