Skip to content

Instantly share code, notes, and snippets.

Matias Quaranta ealsur

Block or report user

Report or block ealsur

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ealsur
ealsur / profiles.json
Created Jul 3, 2019
Windows Terminal profiles
View profiles.json
{
"globals" :
{
"alwaysShowTabs" : true,
"defaultProfile" : "{653f5643-f9da-46cf-9887-1ce64c412a11}",
"initialCols" : 120,
"initialRows" : 30,
"keybindings" :
[
{
@ealsur
ealsur / Trigger.cs
Last active Feb 15, 2019
Azure Cosmos DB + Functions Cookbook - monitoring - trigger
View Trigger.cs
[FunctionName("Trigger")]
public static void Trigger([CosmosDBTrigger(
databaseName: "%MonitoredDatabase%",
collectionName: "%MonitoredCollection%",
ConnectionStringSetting = "CosmosDB",
LeaseCollectionPrefix = "%MonitoredDatabaseLeasePrefix%",
LeaseCollectionName = "leases",
CreateLeaseCollectionIfNotExists = true)] IReadOnlyList<Document> documents,
ILogger log)
{
@ealsur
ealsur / CosmosDBConnectionString.cs
Created Feb 15, 2019
Azure Cosmos DB + Functions Cookbook - monitoring - helper
View CosmosDBConnectionString.cs
private class CosmosDBConnectionString
{
public CosmosDBConnectionString(string connectionString)
{
// Use this generic builder to parse the connection string
DbConnectionStringBuilder builder = new DbConnectionStringBuilder
{
ConnectionString = connectionString
};
@ealsur
ealsur / Estimator.cs
Created Feb 15, 2019
Azure Cosmos DB + Functions Cookbook - monitoring - estimator
View Estimator.cs
private static Lazy<IRemainingWorkEstimator> remainingWorkEstimator;
public static IRemainingWorkEstimator GetRemainingWorkEstimator(
DocumentClient monitoredCollectionClient,
DocumentClient leaseCollectionClient)
{
if (remainingWorkEstimator == null)
{
// Pull the Connection string from the environment, Environment.GetEnvironmentVariable will read the local.settings.json file or the deployed Function App configuration
CosmosDBConnectionString cosmosDBConnectionString = new CosmosDBConnectionString(Environment.GetEnvironmentVariable("CosmosDB"));
@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;
You can’t perform that action at this time.