Skip to content

Instantly share code, notes, and snippets.

View johanste's full-sized avatar

Johan Stenberg (MSFT) johanste

  • Microsoft Corporation
  • Redmond, WA
View GitHub Profile
@johanste
johanste / pipeline.py
Created January 17, 2019 18:52
Example semi-strongly typed pipeline
from sys import Type
from typing import List
class Policy:
...
class RetryPolicy(Policy):
def __init__(self, max_retries=4, timeout=None):
@johanste
johanste / wrap_async_in_sync.py
Created February 25, 2019 16:54
Wrapping async in sync
import asyncio
import threading
class Client:
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.loop.call_soon_threadsafe(self.loop.stop)
@johanste
johanste / syncasyncwrappedclient.py
Created April 11, 2019 16:08
Experimenting common sync and async code for wrapped autogenerated clients...
import asyncio
import time
class GeneratedSyncClient:
def mapper(self, result, mappings):
if result['timeout'] in mappings:
raise mappings[result['timeout']]()
return result
@johanste
johanste / pagedpageable.py
Created May 31, 2019 03:00
Provide a paged pageable over paged
class FakePagePaged:
""" Iterable over pages of responses
Only intended to show a straw-man for how it could be implemented
"""
def __init__(self, item_paged):
self._item_paged = item_paged
def __iter__(self):
return self
@johanste
johanste / Expected spans.md
Last active July 24, 2019 16:35
Assumptions on capabilities and requirements for distributed tracing for Azure Libraries, preview-2

Two categories:

  1. User has done nothing to enable distributed tracing (no tracing library or plugin referenced, no tracer configured/enabled
  2. User is referencing a distributed tracing plugin and has configured/enabled tracing

For category 1, there are no observable effects. No tracing information is emitted in outgoing requests (e.g. no tracstate/tracecontext headers). Spans may be created in memory, but since no exporter is created/referenced, no span information is created. ISSUE: we could, in theory, still use the span information in logs.

For category 2, see below for what spans to create.

Example scenarios with spans created

@johanste
johanste / cosmos_track2.md
Created July 30, 2019 02:08
Changes needed to get to track 2 for cosmos/python.

Track 2 changes

CosmosClient:

Most prominent per-service-request args to change:

@johanste
johanste / example.py
Created August 23, 2019 16:42
Example more pythonic for event hubs load balancer
import collections
partition_ids = range(1, 7)
ownerships = [
{
'last_modified_time': 7,
'partition_id': 1,
'ownership': 1
},
{
@johanste
johanste / json-patch.py
Created January 23, 2020 03:20
Example wrapping existing model type into something that can build json-patch (like) documents
class JsonPatchProxy:
def __init__(self, wrapped, *, root=None, selector=''):
self.__wrapped = wrapped
self.__root = root or self
self.__selector = selector
self.__operations = []
def __getattr__(self, name):
attr = getattr(self.__wrapped, name)

Azure REST API review board

  • Approval by the board is part of the PLR criteria for services
  • Looks at adherence to the Microsoft REST API Guidelines + Azure REST API Guidelines
  • Follow good practices, avoid anti-patterns across Azure services.
    • Paging
    • Long running operations
    • Error schemas
    • Versioning

Who are on the review board

@johanste
johanste / update.md
Created July 1, 2020 20:55
Design proposal for device update/updates

As a user, I want to create an update. The update take a manifest as input. I do not get a chance to give my update a name - the name is generated by the service. Creating the update can take a long time, and the process can fail in ways that cannot be validated on the initial request since the validation is too costly. If the create fails at any point in time, no update resource will be created.

It is tempting to, as an implementor of a service, use globally unique identifiers as keys. However, if there is any possibilty to use a natural key, that is preferred. Humans are bad a remembering GUIDs. A hybrid apprach is to allow the user to optionally specify a key, and generate a key if one is not provided. The hybrid apprach makes it possible to make the operation idempotent.

There is no need for me (as a user) to list all updates that are being created at any given time. Only the user who is creating a user (or someone they hand off the process to) need to monitor the progress.

This requireme