The Azure Cosmos DB Blog

All about Cosmos DB, IoT and Azure

Page 3 of 21

Azure Cosmos DB Document Attachment Storage Comparison

Recently I was working on an IoT solution for an international Safety Products manufacturer. One of the micro-service we were designing was to handle updating of device software.

One of the requirements was to be able to have the software updates as close as possible to the device charging station. There software updates were archived into Zip files.

There are two methods for creating a Azure Cosmos DB Document Attachment.

Store the file as an attachment to a Document

The raw attachment is included as the body of the POST.
Two headers must be set:

Store the URL for the file in an attachment to a Document

The body for the POST include the following.

INFO: You can read more about creating an attachment here

The following is an example

{  
    "id": "device\A234",  
    "contentType": "application/x-zip-compressed",  
    "media": "www.bing.com/A234.zip"  
}

Which method works best?

Let’s see how they compare.

Storage Comparison

Service Global Distribution Storage Limitations
Blob Storage Only 1 region None Unlimited
Document Attachment Available for all Azure Regions Supported Limited to 2GB per Cosmos DB Account
Content Delivery Network (CDN) Available for all Azure Regions You can enable Azure Content Delivery Network (CDN) to cache content from Azure storage. Azure CDN offers developers a global solution for delivering high-bandwidth content. It can cache blobs and static content of compute instances at physical nodes in the United States, Europe, Asia, Australia, and South America. Unlimited

Conclusion

  • Since the total size of all the attachment files is an unknown, attaching the file to the document would not work.
  • Blob Storage is out since there is only one region available.
  • Because it supports caching and multi-region instances, Azure Content Delivery Network (CDN) is the only storage solutions that meets my client’s requirements

Using Microsoft PowerApps and Flows to query Cosmos DB Log Analytics

PowerApps with Flow simplify the task of querying Azure Log Analytics.
This tutorial will show you how easy it is to create a PowerApps application

The application does the following

  1. Queries Azure Log Analytics .
  2. Generates a chart result.
  3. Sends an email with the visualization embedded.

Creating the application

The following figure shows the workflow steps.

Workflow


These steps to create the workflow are:

  1. Use a PowerApps button to start the process.
  2. Add the Azure Log Analytics action as shown below

Log Analytics
A. Select Run Query and visualize results

The Chart types are: 

Chart type
Select HTML which creates a Table

  1. Add a Condition to validate that the records exist
    @not(equals(length(body('Run_query_and_visualize_results')?['body']), 0))

    1. if Yes then use the Office 365 action to send a email
      Send Email
    2. If No then add a Terminate action with a Cancelled value
  2. Click Save.

NOTE: For this tutorial we are using live data from Cosmos DB Diagnostic Logging

The following is an example of the Azure Log Analytics data.

{
    "records":
    [

        {
             "time": "2018-02-02T18:21:52.7720997Z",
             "resourceId": "/SUBSCRIPTIONS/XXXXXXXXXXXXXXXXXXXXXXX/RESOURCEGROUPS/FHIR/PROVIDERS/MICROSOFT.DOCUMENTDB/DATABASEACCOUNTS/FHIR",
             "category": "DataPlaneRequests",
             "operationName": "ReadFeed",
             "properties": {"activityId": "4e22c5e3-3169-4e02-a6b5-84fd69284e28","requestResourceType": "Document","requestResourceId": "jdUKAPpYJQA=","collectionRid": "jdUKAPpYJQA=","statusCode": "304","duration": "4092","userAgent": "documentdb-dotnet-sdk/1.17.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0changefeed-0.2","clientIpAddress": "23.101.171.0","requestCharge": "1.000","requestLength": "0","responseLength": "0","resourceTokenUserRid": "","region": "Central US","partitionId": "6a6ca36b-7a1d-42b5-b866-3e5eed09186e"}
        }
        ,
        {
             "time": "2018-02-02T18:22:54.2597286Z",
             "resourceId": "/SUBSCRIPTIONS/XXXXXXXXX/RESOURCEGROUPS/FHIR/PROVIDERS/MICROSOFT.DOCUMENTDB/DATABASEACCOUNTS/FHIR",
             "category": "DataPlaneRequests",
             "operationName": "ReadFeed",
             "properties": {"activityId": "8d2dc86b-e7dc-4727-bab2-b8d3986b298e","requestResourceType": "Document","requestResourceId": "jdUKAPpYJQA=","collectionRid": "jdUKAPpYJQA=","statusCode": "304","duration": "3885","userAgent": "documentdb-dotnet-sdk/1.17.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0changefeed-0.2","clientIpAddress": "23.101.171.0","requestCharge": "1.000","requestLength": "0","responseLength": "0","resourceTokenUserRid": "","region": "Central US","partitionId": "6a6ca36b-7a1d-42b5-b866-3e5eed09186e"}
        }
        ,
        {
             "time": "2018-02-02T18:24:06.0068309Z",
             "resourceId": "/SUBSCRIPTIONS/XXXXXXXXX/RESOURCEGROUPS/FHIR/PROVIDERS/MICROSOFT.DOCUMENTDB/DATABASEACCOUNTS/FHIR",
             "category": "DataPlaneRequests",
             "operationName": "ReadFeed",
             "properties": {"activityId": "cc5a0c11-a523-47c9-9a91-d0889cfae4b6","requestResourceType": "Document","requestResourceId": "jdUKAPpYJQA=","collectionRid": "jdUKAPpYJQA=","statusCode": "304","duration": "4181","userAgent": "documentdb-dotnet-sdk/1.17.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0changefeed-0.2","clientIpAddress": "23.101.171.0","requestCharge": "1.000","requestLength": "0","responseLength": "0","resourceTokenUserRid": "","region": "Central US","partitionId": "6a6ca36b-7a1d-42b5-b866-3e5eed09186e"}
        }
        ,
        {
             "time": "2018-02-02T18:24:16.2453179Z",
             "resourceId": "/SUBSCRIPTIONS/XXXXXXXXX/RESOURCEGROUPS/FHIR/PROVIDERS/MICROSOFT.DOCUMENTDB/DATABASEACCOUNTS/FHIR",
             "category": "DataPlaneRequests",
             "operationName": "ReadFeed",
             "properties": {"activityId": "6f3249cb-d3e3-4756-872c-5de5f6b7a291","requestResourceType": "Document","requestResourceId": "jdUKAPpYJQA=","collectionRid": "jdUKAPpYJQA=","statusCode": "304","duration": "2810","userAgent": "documentdb-dotnet-sdk/1.17.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0changefeed-0.2","clientIpAddress": "23.101.171.0","requestCharge": "1.000","requestLength": "0","responseLength": "0","resourceTokenUserRid": "","region": "Central US","partitionId": "6a6ca36b-7a1d-42b5-b866-3e5eed09186e"}
        }
    ]
}

Testing our Workflow

  1. Start by clicking on as shown below.
    Run
  2. Enter our query and email subject as shown in the following figure.

Button

INFO: You can read more about Log Analytics searches here


  1. After clicking on Run flow, we can view the process results.

Results


Checking our email, we can see the results.

Eamil


Monitoring our workflow

We can view the Flow Analytics as shown below.

Analytics

Finally we can view our Flow administration

Main

Summary

  • You have seen how easy it is to create a PowerApps with Flow application
  • You can create custom log searches.
  • You can edit the flow to change the chart type
  • You can extend the flow to add more actions.
  • You can easily modify the data connections.

More Info

You can ready more about Microsoft PowerApps/Flows here

« Older posts Newer posts »
Skip to toolbar