Skip to content

Instantly share code, notes, and snippets.

Avatar

Matias Quaranta ealsur

View GitHub Profile
@ealsur
ealsur / Function.cs
Created Feb 15, 2019
Azure Cosmos DB + Functions Cookbook - monitoring
View Function.cs
[FunctionName("Monitor")]
public static async Task Monitor(
[TimerTrigger("*/1 * * * * *", RunOnStartup = true)] TimerInfo timer, // Timer will trigger every 1 second, adjust CRON expression
[CosmosDB("%MonitoredDatabase%", "%MonitoredCollection%", ConnectionStringSetting = "CosmosDB")] DocumentClient monitoredCollectionClient,
[CosmosDB("%MonitoredDatabase%", "leases", ConnectionStringSetting = "CosmosDB")] DocumentClient leaseCollectionClient,
ILogger log)
{
var estimator = GetRemainingWorkEstimator(monitoredCollectionClient, leaseCollectionClient);
var remainingWork = await estimator.GetEstimatedRemainingWork();
// Send custom metric to App Insight
@ealsur
ealsur / hosts.json
Created Jan 15, 2019
Azure Cosmos DB + Functions - Health monitoring
View hosts.json
{
"version": "2.0",
"logging": {
"fileLoggingMode": "always",
"logLevel": {
"Host.Triggers.CosmosDB": "Trace"
}
}
}
@ealsur
ealsur / precompiled-output.cs
Created Nov 12, 2018
Azure Cosmos DB + Functions Cookbook - Multi master & preferred region
View precompiled-output.cs
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
[CosmosDB(databaseName: "%CosmosDBDatabase%",
collectionName: "%CosmosDBCollection%",
ConnectionStringSetting = "CosmosDBConnectionString",
UseMultipleWriteLocations = true,
PreferredLocations = "Central US"
)] IAsyncCollector<MyClass> documentsToSave,
ILogger log)
{
@ealsur
ealsur / precompiled-input.cs
Created Nov 12, 2018
Azure Cosmos DB + Functions Cookbook - Multi master & preferred region
View precompiled-input.cs
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "HttpInputBindingByIdInRoute/{id}")] HttpRequestMessage req,
[CosmosDB(databaseName: "%CosmosDBDatabase%",
collectionName: "%CosmosDBCollection%",
ConnectionStringSetting = "CosmosDBConnectionString",
UseMultipleWriteLocations = true,
PreferredLocations = "Central US,North Central US"
Id = "{id}")] Document document,
ILogger log)
{
@ealsur
ealsur / run.csx
Last active Oct 14, 2018
Azure Cosmos DB + Functions Cookbook: static client
View run.csx
#r "Microsoft.Azure.Documents.Client"
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using System.Net;
using System.Configuration;
private static string endpointUrl = ConfigurationManager.AppSettings["cosmosDBAccountEndpoint"];
private static string authorizationKey = ConfigurationManager.AppSettings["cosmosDBAccountKey"];
private static DocumentClient client = new DocumentClient(new Uri(endpointUrl), authorizationKey);
@ealsur
ealsur / run.csx
Created Mar 9, 2018
Azure Cosmos DB + Functions Cookbook —secure access run.csx
View run.csx
#r "Microsoft.Azure.Documents.Client"
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using System.Net;
using System.Configuration;
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.Services.AppAuthentication;
private static HttpClient httpClient = new HttpClient();
private static DocumentClient client = null;
@ealsur
ealsur / project.json
Created Mar 9, 2018
Azure Cosmos DB + Functions Cookbook —secure access project.json
View project.json
{
"frameworks": {
"net46":{
"dependencies": {
"Microsoft.Azure.KeyVault": "2.3.2",
"Microsoft.Azure.Services.AppAuthentication": "1.1.0-preview"
}
}
}
}
@ealsur
ealsur / function.json
Created Mar 9, 2018
Azure Cosmos DB + Functions Cookbook —secure access function.json
View function.json
{
"bindings": [
{
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"name": "$return",
"type": "http",
@ealsur
ealsur / host.json
Created Aug 8, 2018
Custom ConnectionMode and Protocol for Functions V2
View host.json
{
"cosmosDB": {
"connectionMode": "Direct",
"protocol": "Tcp"
}
}
@ealsur
ealsur / host.json
Created Aug 8, 2018
Custom ConnectionMode and Protocol
View host.json
{
"documentDB": {
"connectionMode": "Direct",
"protocol": "Tcp"
}
}
You can’t perform that action at this time.