<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[cisco-fpie - Medium]]></title>
        <description><![CDATA[Cisco Future Product Innovations and Engineering - Medium]]></description>
        <link>https://medium.com/cisco-fpie?source=rss----e03a79ee8c73---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>cisco-fpie - Medium</title>
            <link>https://medium.com/cisco-fpie?source=rss----e03a79ee8c73---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:50:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/cisco-fpie" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Taming of the Queue]]></title>
            <link>https://medium.com/cisco-fpie/taming-of-the-queue-f320f855a09?source=rss----e03a79ee8c73---4</link>
            <guid isPermaLink="false">https://medium.com/p/f320f855a09</guid>
            <category><![CDATA[aws-msk]]></category>
            <category><![CDATA[data-pipeline]]></category>
            <category><![CDATA[aws-documentdb]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <dc:creator><![CDATA[Tal Maoz]]></dc:creator>
            <pubDate>Wed, 10 Aug 2022 17:45:13 GMT</pubDate>
            <atom:updated>2022-08-11T07:19:56.806Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building Dynamic Data Pipes Using AWS DocumentDB, MSK and Lambda</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*peJzFvRL2NOVFD8t8keEMA.jpeg" /></figure><p>There are many data driven applications that require online processing of data as well as storing the raw data. Some examples include recommendation engines, IoT processors, event-driven services and more. If you’ve ever needed to build some kind of data processing pipeline or workflow, you’re probably familiar with the challenges of handling multiple data types while accounting for the possibility of new data types coming in during the lifetime of your system.</p><p>In this article I will discuss a solution I came up with for a recent project using AWS DocumentDB, MSK and Lambda functions, and will provide instructions for deploying a simple pipeline along with useful Go code snippets.</p><h3>The Design</h3><p>When building a data processing pipeline, one typically needs two components: data transmission and processing blocks. Processing blocks are manipulations applied to the incoming data in a given sequence that may change depending on the type of data, while the data transmission is the means by which data is moved between the various processing blocks. You can think of this as a production line where the conveyor belt moves the products in their various stages between the various stations until the final product comes out the end of the line. The conveyor belt is our data transmission, and the stations are the processing blocks.</p><p>More often than not, you also want a means of storage for the raw data because you never know what you may want to do with it later on, or if some error would force you to run your data through the pipeline again.</p><p>My design requirements were simple:</p><ol><li>Build a fully managed system</li><li>Keep a copy of all the raw data</li><li>Process data in near real-time and in low-latency</li><li>Account for the possibility of new data types coming in over time without requiring system downtime</li></ol><p>After looking into several options, I settled on the following design for my pipeline:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5iW1HV-591RfTn0ZxSP3ug.png" /><figcaption>Architecture Diagram</figcaption></figure><p>Let us start by going over the building blocks we will use to understand what they are and how we can use them:</p><p><a href="https://aws.amazon.com/documentdb/">AWS DocumentDB</a> is Amazon’s managed <a href="https://www.mongodb.com/">MongoDB</a> service based on MongoDB 3.6 or 4.0. As such, it can store, query and index JSON and BSON data. MongoDB is a source-available NoSQL JSON database that uses <a href="https://en.wikipedia.org/wiki/JavaScript">JavaScript</a> as the basis for its query language thus allowing you to also run JavaScript functions server-side. Within a MongoDB deployment, one can define multiple DBs with multiple collections in each one. One useful feature introduced in Mongo 3.6 are <a href="https://www.mongodb.com/docs/manual/changeStreams/">Change Streams</a>. Change Streams allow applications to access real-time data changes by registering for events on specific collections. The event notifications can be configured to include the deltas or full documents and capture “insert”, “change” and “delete” events.</p><p><a href="https://aws.amazon.com/msk/">AWS MSK (Managed Streaming for Apache Kafka)</a> is Amazon’s managed Kafka service. <a href="https://kafka.apache.org/">Apache Kafka</a> is a widely used open-source distributed event store and stream-processing platform. Kafka is designed for high-throughput low-latency real-time data processing. With Kafka you can define “topics” to which you can publish key/value messages. Multiple publishers can publish to a topic and multiple consumers can consume it. Kafka topics are managed using a <a href="https://zookeeper.apache.org/">ZooKeeper</a> cluster while publishing and consuming is done via Kafka brokers.</p><p><a href="https://aws.amazon.com/lambda/">AWS Lambda</a> is a serverless, event-driven compute service that lets you run code in response to various events and triggers while automatically managing the underlying compute resources required by your code. Lambda supports many programming languages including Node.js, Python, Java, Ruby, C# and Go. A very useful feature of Lambda is the ability to trigger functions on Kafka topics, which makes it ideal for usage as part of a data processing pipeline.</p><p><a href="https://aws.amazon.com/vpc/">AWS VPC</a> is a way to create Virtual Private Networks within AWS. This allows you to contain services in a more secure environment and gives you total control over who and what has access to the network and the resources within.</p><p><a href="https://aws.amazon.com/ec2/">AWS EC2</a> is Amazon’s Elastic Compute Cloud where you can deploy virtual or physical instances (computers) and manage their security and networking properties.</p><p><a href="https://aws.amazon.com/s3/">AWS S3</a> is a Simple Storage Service. With the S3 object storage you can create buckets and then store files and folders within them. S3 gives you full access control and security.</p><p><a href="https://aws.amazon.com/iam/">AWS IAM</a> is Amazon’s Identity and Access Management system. IAM lets you manage users, roles, and policies so you can achieve fine grained access control over your resources and grant access to other users and AWS accounts in a secure way.</p><p><a href="https://aws.amazon.com/cloudwatch/">AWS CloudWatch</a> is Amazon’s observability platform where you can aggregate logs from AWS services and easily filter and search through them.</p><h3>Putting Things Together</h3><p>The idea is that DocumentDB is used as the entry point into the pipeline while MSK acts as the data transmission. Each path between processing blocks is implemented using a Kafka topic. One processing block publishes its output to the topic while the next block in line consumes the topic to get its input. The first processing block will act as a “router” that analyses the new data and decides what type it is. It the published the data to a dedicated topic for that data type so the proper processing blocks can be used on that data.</p><p>I start by inserting a new piece of raw data into DocumentDB. Next, I use an MSK connector to register to a change stream for my DocumentDB collection and push the newly inserted documents into an initial MSK topic, which is the input to the “router”. Then, I configure a Lambda-based “router” function to consume the initial MSK topic, analyze the messages and publish each one to a dedicated MSK topic. Finally, for each data-type dedicated topic, I would have a specific Lambda function that knows how to process that data. I can then continue building more processing elements on the pipeline as required.</p><p>Once all the pieces are in place, all I have to do to run new data through the pipeline is simply insert it into my DocumentDB collection. From that point on, everything happens automatically. Moreover, by using the combination of Kafka topics and Lambda functions, I can dynamically create topics for new types of data messages and then define handlers to process them. The messages would wait in the topic until I build a processor that can handle them, and as soon as I deploy the new processor, it can start processing the messages, which means messages are never lost. This design also allows me to dynamically change the layout of my processing pipeline over time.</p><p>In order to configure DocumentDB and MSK, I make use of a bastion instance that I deploy on EC2. This instance allows me to connect to my VPC using a secure SSH connection as well as use port forwarding to give my local environment access to the VPC.</p><p>I use an S3 bucket to store the Kafka connector package as well as my Lambda functions’ code package. In addition, I use IAM to create the required execution roles for the Kafka connector and the Lambda functions.</p><p>Finally, I use CloudWatch to gain visibility to what the Lambda functions are doing by funneling the Lambda logs into CloudWatch log groups.</p><p>Let us now go over each of the components and see how to provision and/or deploy them.</p><h3>VPC Gateway</h3><p>DocumentDB as well as MSK are both deployed only in a VPC. Thus, in order to connect to them from your local machine for development, testing and debugging, you need to create a gateway into your VPC. We will use the default VPC, but any VPC can be used instead. Please refer to the <a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpc-getting-started.html">AWS documentation</a> for information on how to create a new VPC in case the default one is not appropriate.</p><p>We start by creating an EC2 instance that we will use as our gateway. Simply launch a new EC2 instance in the default VPC and choose Ubuntu 20.04 as the OS image (there is no support for the mongo CLI in Ubuntu 22.04 at the time of writing this article):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*UNQQyz06Q51fFYSveLqYPQ.png" /><figcaption>Launch New EC2 Instance</figcaption></figure><p>Next, create an SSH key-pair you will use to access the new instance from your local machine. Click on “Create new key pair” to create a new key pair and download the public key, or choose an existing one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ZNNhRZq4aIEYgQ-cHnOX7A.png" /><figcaption>New EC2 Instance SSH Key Pair</figcaption></figure><p>Next, we look at the “Network Settings” section. Make sure you select the VPC you wish to use and the security group:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*RqQnnMeqqVtTJbtE8t02dg.png" /><figcaption>New EC2 Instance Network Settings</figcaption></figure><p>Finally, launch your new instance. Once your instance is up, you can SSH into the new instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Xkpt8gRVRu35S7095p9how.png" /><figcaption>SSH Into the New Instance</figcaption></figure><h3>DocumentDB</h3><p>Now that we have a VPC, we can start looking into deploying DocumentDB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*zGQHMkz_A9iNMHQrBAFH8w.png" /><figcaption>Architecture — DocumentDB</figcaption></figure><p>Start by going into the Amazon DocumentDB dashboard and click on “Create Cluster”. Give your cluster a name, make sure the selected engine version (MongoDB version) is “4.0.0” and select the desired instance class.</p><p>The connectors we will use to let MSK register to the DocumentDB change stream require that the MongoDB deployment be part of a replica-set so make sure the number of instances is greater than 1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*W-FPfjbuZi9SECGesref-g.png" /><figcaption>DocumentDB — Launch New Instance</figcaption></figure><p>Next, under the authentication section, fill in the admin username and password you would like to use in your cluster.</p><p>Now, click on the “Show advanced settings” toggle at the bottom to open the network settings and make sure that the selected VPC is the same as the one in which you deployed your EC2 instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*_Ur2zrU0UC47bDDN30ZG6A.png" /><figcaption>DocumentDB — New Instance Network Settings</figcaption></figure><p>Tweak any other settings and then click on the “Create cluster” button at the bottom to launch the new cluster. The process takes a few minutes and then you will see the following or similar according to your choices:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0V7SBCLuByJIpjxNuxt1xA.png" /><figcaption>AWS Document DB Cluster</figcaption></figure><p>To test our new cluster, we need to install the mongo client in our EC2 gateway instance. Follow these instructions to do so: <a href="https://www.mongodb.com/docs/mongodb-shell/install/">https://www.mongodb.com/docs/mongodb-shell/install/</a></p><p>Next, go into the cluster details in the AWS console and follow the instruction to download the CA certificate to your EC2 instance and then run the newly installed mongo client to connect to your new cluster:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*pVOLc0YNRbpRuD653xRtog.png" /><figcaption>Connecting to DocumentDB using mongo shell</figcaption></figure><p>If the connection fails, you may need to manage the DocumentDB cluster’s security group to allow access to your EC2 instance’s security group. To do so, go into the cluster’s details and scroll down to the “Security Groups” section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g9wL6L0jbu86ygJuswTSjA.png" /><figcaption>AWS Security Groups</figcaption></figure><p>Select the security group and then go into the “Inbound rules” tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_EgHJ9OzXcILZF3pTpY4w.png" /><figcaption>AWS Security Group Inbound Rules</figcaption></figure><p>Click on the “Edit inbound rules” button to edit the inbound rules and then add a rule that allows the traffic type you need (if you need to specify a port, use 27017) from a “Custom” source. In the search box, search for and select the security group you used for the EC2 instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KMUR8HOS-Pmx0oB5oZAOVg.png" /><figcaption>Adding Inbound Rule to AWS Security Group</figcaption></figure><p>Finally, save the rules. You should now have access from your instance to DocumentDB.</p><p>To make development and debugging easier, you may want to use a tool such as <a href="https://snapcraft.io/install/robo3t-snap/ubuntu">Robo 3T</a>,that lets you access MongoDB using a nice GUI that is intuitive and easy to use and that lets you view and manage data conveniently. You will need to forward port 27017 from your local machine to DocumentDB via the EC2 instance using SSH:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KQhEzt-slgAPsFQVV0AVww.png" /><figcaption>SSH to the Gateway with Port Forwarding to DocumentDB</figcaption></figure><p>Now you can configure your local Robo 3T or mongo client to access port 27017 on your local machine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8RxEGm9P-Xp9FGrTH_UQoA.png" /><figcaption>Robo 3T — New Connection</figcaption></figure><p>For Robo 3T, make sure to allow invalid hostnames because your local hostname is different than the one in the CA certificate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iku-6IXiaWj-_hHjoh3kAw.png" /><figcaption>Robo 3T — setting CA Certificate</figcaption></figure><p>Now, we can create a new Database called “pipeline” and in it a collection called “intake”. We also create a new user called “puser” that has read permissions for the “pipeline” database:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*-M1Jxm4Kh3nv7hvooStMTw.png" /><figcaption>Robo 3T — After Creating A Collection and A User</figcaption></figure><p>The last thing we need to do is enable change streams on our new collection. To do that we need to connect to DocumentDB as we did above and then run the following command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2768c4d5b8765bf0fdc05eb42a521b8/href">https://medium.com/media/c2768c4d5b8765bf0fdc05eb42a521b8/href</a></iframe><p>If you are using Robo 3T as I do, right click on the “pipeline” database in the tree on the left and then select “Open Shell”. Now you can enter the above command and use <em>CTRL+ENTER</em> to execute it.</p><h3>MSK</h3><p>Now that we have DocumentDB set up, we can move on to MSK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eee4MKULcxOZsBj_WurFmg.png" /><figcaption>Architecture — MSK</figcaption></figure><p>We will be deploying our MSK cluster using the “Quick create” option. For this little demo we will use the “kafka.t3.small” flavor and allocate only 1GB of space. If you need to change the network settings to choose a different VPC, zones and subnets, you will have to switch from “Quick create” to “Custom create”.</p><p>In any case, make sure that your MSK cluster is in the same VPC and subnets as the gateway EC2 instance. Otherwise, you would have to start configuring routing between the VPC or subnets, which we will NOT cover in this article.</p><p>When done, click on the “Create cluster” button and wait until your cluster is up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ugwhrORKn7F8jy3PkyWLTQ.png" /><figcaption>MSK Cluster</figcaption></figure><p>To test our cluster, we need to get the brokers’ addresses. Click on the cluster, select the “properties” tab and scroll down to the “Brokers” section. There, you will find a list of the brokers that have been deployed as part of the cluster:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4uCmciFMw0H_Btk4BBReFw.png" /><figcaption>MSK Cluster Brokers</figcaption></figure><p>Managing a Kafka cluster is done using the Kafka CLI tools. The CLI tools require the Java runtime as Kafka is written in Scala which runs on a JVM (Java Virtual Machine). We are using openjdk-8-jre. Now, download the Kafka package from <a href="https://kafka.apache.org/downloads">https://kafka.apache.org/downloads</a> to the EC2 instance and extract it. For this document, we are using Kafka 2.13–3.1.0 .</p><p>Next, use the “kafka-topics” command to get the list of existing topics. You need to provide a bootstrap server, which can be any of the brokers in the cluster (we use the first one):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JFPiIe6NpJkm4WsrTdascA.png" /><figcaption>List Kafka Topics</figcaption></figure><p>Please note that port 9092 does NOT use TLS. If you wish to use a secure TLS connection, you should follow these steps:</p><ol><li>Create a client profile:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R1evcO6hvaiadv-WJ6b54A.png" /></figure><p>2. Create the initial trust store:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9QdZQUg_PHDJMdrGl0eKMg.png" /></figure><p><em>Note that the location of the “cacerts” file will change according to the JRE you installed on your machine.</em></p><p>3. Finally run the command as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*edYURmF2t41vJiKui6rKZA.png" /></figure><p>Now that we have our MSK cluster deployed and accessible, we can create our initial topic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IRiK8c1b5o0RGr4F9okojA.png" /></figure><p>Let us publish a test message to our new topic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pBaGRNJVzKezt34nu9rvNQ.png" /></figure><p>We can see that our new message was, indeed, published and can be consumed as well.</p><p>But how do we clear out a topic? There is no way to directly delete messages from a topic. Instead, we have to change the retention policy and wait for Kafka to delete all the expired messages for us before we can restore our original retention policy.</p><p>First, we get the current settings and see that there is no policy set:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C383mHaEiVdLCVAGTgKV7Q.png" /></figure><p>Thus, the default policy applies which is 7 days (<a href="https://docs.confluent.io/platform/current/installation/configuration/topic-configs.html">https://docs.confluent.io/platform/current/installation/configuration/topic-configs.html</a>). We now change that policy to one second:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZuDtkxcZVQ4e_vKaQiBh-w.png" /></figure><p>It takes a little while for the new policy to take effect, but once it does, we can run our consumer and see that there is nothing in the topic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nUvbG6vknSSyfPzmwOkMSA.png" /></figure><p>Finally, we can restore the default policy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V_qutKDbsJ5mx8cMgBwlxA.png" /></figure><h3>S3</h3><p>If order to create a Kafka MongoDB connector and to make reusing Lambda code easier, we need to create an S3 bucket where the code packages would be kept.</p><p>To do that, start by going to the S3 dashboard and create a new bucket by clicking the “Create bucket” button. Fill in the name for your new bucket, select the requested region and then scroll down and click on the “Create bucket” button. We keep all the default options for now, but you can play with them later if you wish to change anything.</p><h3>IAM Execution Role</h3><p>Our next challenge is tying DocumentDB to Kafka so that inserting new documents into DocumentDB would automatically put notifications with the full document data into a given Kafka topic. For this we are going to use a Kafka connector that will register for a Mongo change stream for our collection and then publish the new documents to the chosen Kafka topic.</p><p>We will start by creating an IAM execution role for our new connector. Note, that when creating a connector, AWS will give you the option to create an execution role. However, it turns out that due to some changes made by AWS to how <a href="https://docs.aws.amazon.com/msk/latest/developerguide/msk-connect-service-execution-role.html">execution roles work</a>, using this option results in a Service Linked role that is not usable by MSK Connect. AWS is aware of <a href="https://stackoverflow.com/questions/70885951/aws-msk-connectors-for-debezium-iam-role-problem">this issue</a> but has not fixed it as of the date of writing this article. So, we need to create our own role manually…</p><p>Go to the IAM console, select the “Roles” section on the left and then click on “Create role” on the top right:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtHynSy3LORO5-eOHxMtog.png" /><figcaption>IAM — Create New Role</figcaption></figure><p>Next, select the “AWS account” option and then click on “Next”. At this point you can select a policy to use. None of these policies are good for us so just click on “Next” again. Now give your role a name and description and then scroll to the bottom and click on “Create role”.</p><p>Now that we have a role, we need to configure the proper permissions so find your role in the list of roles and click on it. Under the “Permissions” tab click on the “Add permissions” button to open the drop-down menu and select “Create inline policy”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nL0c7MVHX5l-VyQKAbxiWw.png" /><figcaption>IAM — Creating a New Policy For MSK Connect</figcaption></figure><p>We would now like to manually enter a policy so select the “JSON” tab and then replace the existing empty policy with the following one:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c7af97f151d66e9f5b8b950a71b55a1/href">https://medium.com/media/4c7af97f151d66e9f5b8b950a71b55a1/href</a></iframe><p>Now click on “Review policy” and then give your new policy a name:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RyWwvXroxbPSYxzXTvLqXg.png" /><figcaption>IAM — Review Policy</figcaption></figure><p><em>Note that this policy grants many permissions. We do this for simplicity, but you may want to experiment and limit the permissions you grant for better security.</em></p><p>Finally, click on the “Create policy” button at the bottom. You will now be able to see your new policy listed in your role:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wWMzgDQNtv1kW2C-VUbx1w.png" /><figcaption>IAM — New Inline Policy</figcaption></figure><p>Next, we need to add the proper trust policy so click on the “Trust relationships” tab and then on “Edit trust policy”. In the editor that opened, replace all the text with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/279429c99c4bddbaccc9bd751b89b497/href">https://medium.com/media/279429c99c4bddbaccc9bd751b89b497/href</a></iframe><p>Finally, click on “Update policy” to finalize the new role.</p><h3>CloudWatch</h3><p>In order to keep track of what is going on with our connector and Lambda functions, we need a place to keep our logs. We will use CloudWatch and so we need to create a log group.</p><p>Go to the CloudWatch dashboard, select “Logs” on the left and then “Log groups”. Click on “Create log group” on the right, give your log group a name and a retention setting, and then click on “Create” on the bottom and you are done.</p><p>That was simple!</p><h3>MSK Security Group</h3><p>Another thing to tackle before we can create a Kafka connector is configuring our security group to allow internal communications.</p><p>Go to your MSK cluster’s configurations, click on the “Properties” tab, and then click on the security group that is applied. If you followed this article, you should only have a single security group applied.</p><p>Once you get to the EC2 dashboard and to the security group settings, you need to click on the “Edit inbound rules” button to add the required rule.</p><p>Now, click on the “Add rule” button on the bottom left, select “All traffic” for the rule type and then find your security group in the custom “Source” search box. Make sure to select the same security group as the one you are currently editing. Note that the name of the security group appears in the navigation bar on the top left of the page.</p><p>Finally, click on “Save rules” and you should be set.</p><h3>MSK and DocumentDB Security</h3><p>Now I must point out a slight problem with the DocumentDB connection. We used the default DocumentDB configurations that enables TLS. This means that in order to connect to DocumentDB, we needed to supply the client with the CA file we downloaded from the DocumentDB dashboard. However, since MSK is a managed service, we have no way of installing these certificates in the new plugin. Furthermore, while there is a way to specify the CA file within the MongoDB URI, the current MongoDB driver used within both the Confluent and Debezium connectors simply ignores this option and/or the CA file if we try to include it in the JAR file or in a ZIP file that holds both. If any readers are aware of a way to do this, please let me know so I can update this document. The only other option would be to implement our own connector that would contain the certificates and use them without relying on external files or certificate registries, but this is out of scope for this article.</p><p>Thus, we first need to turn off TLS in our DocumentDB. For this, go back to the DocumentDB dashboard, select “Parameter groups” from the left side menu and then click on the “Create” button on the right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GVeOabHgxYwAlwn9ZUh9PQ.png" /><figcaption>DocumentDB — Creating a New Parameter Group</figcaption></figure><p>Fill in a name for the new parameter group, add a description and click on “Create”.</p><p>Next, click on the new group from the list, then select “tls” from the new list that opens, click on the “Edit” button on the top right of the screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eiZ98OJIXeYP0ZhgdEu4Jw.png" /><figcaption>DocumentDB — Modify the “tls” Parameter</figcaption></figure><p>Set the selection to “disabled” and click on “Modify cluster parameter”.</p><p>Now, click on “Clusters” from the left side menu and then click on your cluster. Go to the “Configuration” tab and click on the “Modify” button within that tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dQKei-UjzmW5F4o8ntcAjw.png" /><figcaption>DocumentDB — Modify Cluster Options</figcaption></figure><p>Under the “Cluster options” section, select the new parameter group that we just created and then scroll down, click on the “Continue” button and finally click on the “Modify cluster” button. This will modify the settings and take you back to the cluster list.</p><p>However, the new settings will not take effect until you reboot the cluster. If you click on the cluster again, you will see that the summary section indicates “pending-reboot”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EMGqFvQscxSe_Vxu_dPVQA.png" /><figcaption>DocumentDB — Cluster Pending Reboot</figcaption></figure><p>Go back to the cluster list, select the cluster by clicking on the checkbox next to it, then click on the “Actions” button to open the menu and select “Reboot”. The cluster will now reboot and in a few minutes will be ready for work.</p><h3>Kafka MongoDB Connector</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZkqfgvBFzMVApDd8K1pg3A.png" /><figcaption>Architecture — Kafka MongoDB Source Connector</figcaption></figure><p>There are two options we can use, the Confluence connector and the Debezium connector. Both are Java based but the Confluence connector is easier to use so we will focus on that one and mention the differences in the Debezium connector briefly.</p><p>Do NOT go to <a href="https://www.confluent.io/hub/mongodb/kafka-connect-mongodb/">https://www.confluent.io/hub/mongodb/kafka-connect-mongodb/</a> to download the connector from there. Although we ARE going to use this connector, the version you will find there is designed specifically for the confluence cloud and so missing some dependencies required by MSK that are provided by the Confluence cloud.</p><p>Instead, go to the Maven repo at <a href="https://search.maven.org/search?q=a:mongo-kafka-connect">https://search.maven.org/search?q=a:mongo-kafka-connect</a>, click on the “Download” icon on the right and select “all”. This will download a JAR file that includes all the required dependencies. Upload this JAR file to your S3 bucket.</p><p>In MSK, you first need to create a plugin, and then a connector which is an instance of the plugin. In our case, MSK does not have a built-in MongoDB plugin and so we need to create a custom plugin. Fortunately for us, MSK can wrap the process of creating both plugin and connector into a single sequence.</p><p>Go to the MSK dashboard, select “Connectors” from the left side menu and then click on the “Create connector” button. You can see that MSK takes you to the “Custom plugin” screen to first create the new custom plugin. Select the “Create custom plugin” option, and then click on the “Browse S3” button to find your S3 bucket and select the JAR you just uploaded. Next, give your plugin a name and add a description, and then click on “Next” to start creating the connector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*txLZYQSNLekpLhCW8OXxZg.png" /><figcaption>MSK — Create a Custom Plugin</figcaption></figure><p>To create a connector, start by choosing a name and add a description. Then choose you MSK cluster from the “Apache Kafka Cluster” list and the “None” authentication method as our plugin does not support the IAM authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*SCGx5Zkg2xJpkFEZgKnVvA.png" /><figcaption>MSK — Create a New Connector</figcaption></figure><p>Now we need to configure our connector. You can find detailed configuration information in the <a href="https://www.mongodb.com/docs/kafka-connector/current/source-connector/configuration-properties/#std-label-source-configuration-index">MongoDB connectors documentation site</a> and more information about MongoDB and change stream settings in the <a href="https://www.mongodb.com/docs/v4.2/introduction/">MongoDB documentation</a>.</p><p>We want to monitor the “intake” collection in the “pipeline” database and publish new documents to the pipeline.intake.inserts topic. We also want to poll the change stream every second (this might be high so consider reducing the polling frequency according to your application) and get the results in JSON format. The following configurations specify these choices:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6893c0ca518285b9dd6655670c0f674f/href">https://medium.com/media/6893c0ca518285b9dd6655670c0f674f/href</a></iframe><p><em>Note that for </em><em>&lt;YOUR_CONNECTOR_NAME&gt; you have to use the exact same name you chose for your connector. Also make sure to use your actual password instead of </em><em>&lt;YOUR_PASSWORD&gt; in the URI.</em></p><p>We leave the rest of the settings in the page on the defaults, but you can try and change them according to your needs. We need to give our connector access permissions using an AWS IAM role, so we choose the IAM execution role we created before and then click on the “Next” button.</p><p>The next section deals with security and the defaults here are good for us, so we touch nothing and simply click on the “Next” button again.</p><p>Now we need to choose where to send logging information. We previously created a CloudWatch log group and now is the time to use it. So, choose “Deliver to Amazon CloudWatch Logs” and then select the log group using the “Browse” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kmw2xp34A9gaYTMXM7Eodg.png" /><figcaption>MSK — Sending Connector Logs to AWS CloudWatch</figcaption></figure><p>Click “Next” one more time to get to the “Review and create” screen. This screen shows you a summary of your choices and configurations and gives you the ability to edit things you missed. After making sure everything is as it should be, click the “Create connector” button to finish the process. Your new connector will now be created. This process can take a few minutes.</p><p>You can go to the CloudWatch console and select your log group to watch for progress. First you will see a new log stream titled “log_stream_created_by_aws_to_validate_log_delivery_subscriptions” appearing to indicate that the connector has permissions to log to CloudWatch. If you never see this, you need to go back and check the execution role settings to make sure you got them right.</p><p>After a couple of more minutes, you should see a log stream titled something like “medium-connector-33190fb9-ae60–471b-8a8f-412186b023ce-3”. If you click on this log stream you will be able to see all the output from your new connector as it initializes. If you see any errors during initialization, which may be in the form of Java exceptions and stack traces, you probably missed some of the steps above so go back and make sure you configured everything correctly. Note that you can NOT modify an existing connector so you would need to delete it once it reaches a “failed” state and create a new one instead.</p><p>If everything works and the connector was able to connect to DocumentDB and initialize the change stream, you will see messages like these appearing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tGvjFr7V2VAQAkOg2lzJKw.png" /><figcaption>MSK COnnector Logs in CloudWatch</figcaption></figure><p>Your plugin is now ready for work!</p><p>We can run the CLI Kafka consumer as before and then use our MongoDB client to insert some documents:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YRhw9qKXV7OcYLW1nnL3WQ.png" /><figcaption>Inserting New Documents to DocumentDB using Robo 3T</figcaption></figure><p>The consumer will then show us that the connector picked up the documents and published them to our chosen topic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SPyQvQMctXw-XehjvrQ2tg.png" /><figcaption>Kafka CLI Consumer Showing the New Documents in the Topic</figcaption></figure><p>The connector is working as expected!</p><p>As for the Debezium connector, the documentation and download link can be found <a href="https://debezium.io/documentation/reference/2.0/connectors/mongodb.html">here</a>. Once downloaded, extract the archive, and upload the JAR to S3 so it can be used in MSK as with the Confluence connector.</p><p>The configurations are a bit different for the Debezium connector:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc2273737cb98711c5a4efc7dc7df096/href">https://medium.com/media/bc2273737cb98711c5a4efc7dc7df096/href</a></iframe><p>Unlike the Confluence connector, the Debezium one does not let you set a suffix for the topic name but rather uses the “mongodb.name” logical name as a prefix. Thus, we cannot use a topic like pipeline.intake.inserts. These configs will actually cause the connector to try and publish to a topic named inserts.pipeline.intake so make sure to name your topic correctly if you wish to use this connector. Otherwise testing should be done in the same way as before.</p><h3>Lambda</h3><p>This is where we start building our actual processing pipeline/graph. We need to create a new Lambda function and set an MSK based trigger for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dUopohXUU_u6E4RktgwjzQ.png" /></figure><p>Start by going to the Lambda dashboard and click on the “Create function” button on the top right. Make sure to choose “Author from scratch” and fill in a name for your function. We are going to use Go code so select “Go 1.x” from the “Runtime” list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VEigOQg6EXq4r3cm2cxcDw.png" /><figcaption>Lambda — Create a New Function</figcaption></figure><p>Next, expand the “Change default execution role” section, select “Create a new role from AWS policy templates” and give the role a name. This will create a new “service-role” to be used as the execution role for the Lambda function. Once created, we will need to tweak the permissions.</p><p>Expand the “Advanced settings” section and tick the “Enable VPC” box. We need our Lambda function to have access to the MSK cluster so the trigger can read from a topic and so we can publish to the next topic in line. Choose your VPC from the list, ALL the subnets where the MSK brokers are deployed and finally the security group as we defined previously:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*QxwXWYI2qni6tYjv14yVmw.png" /><figcaption>Lambda — Function VPC Settings</figcaption></figure><p>Create the function by clicking on “Create function”.</p><p>Once the function is created, click on it and then go to the “Configuration” tab and select “Permissions” from the left menu:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*_OShuk4yV8KVXtLVT385oQ.png" /><figcaption>Lambda — Execution Role</figcaption></figure><p>This shows you the execution role created for you, and you can browse the list of permissions it gives your Lambda function. Click on the role to open it in the IAM dashboard, remove the current policy and then create a new one that has the following permissions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f077f71cde5f64727a6746b3b901813/href">https://medium.com/media/4f077f71cde5f64727a6746b3b901813/href</a></iframe><p><em>Note to replace the </em><em>&lt;REGION&gt; with your selected region and </em><em>&lt;ACCOUNT_ID&gt; with your AWS account ID.</em></p><p>Go back to the Lambda function’s configurations, click on the “Monitor” tab and then click on “View logs in CloudWatch”. This should take you to the log group that was created for you Lambda functions. If, for some reason, this group was not automatically created, you will get an error message like this one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q2p0jlb97CWIHIIAtSB9mg.png" /><figcaption>CloudWatch — Log Group Missing Error</figcaption></figure><p>You will need to manually create the log group. To do this, note the group’s required name in the error message, which in this case is /aws/lambda/medium-pipline-router. Now click on “Log groups” from the navigation bar under the error message or by expanding the left sidebar and clicking on “Log groups” there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OnorFGlvn7Zc9o_s92kB5Q.png" /><figcaption>CloudWatch — Showing Log Groups</figcaption></figure><p>Now click on “Create log group”, fill in the required name and then click on the “Create” button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RLuqOgCAWu87Szkcd6igzg.png" /><figcaption>CloudEWatch — Creating a New Log Group</figcaption></figure><h3>VPC Revisited</h3><p>Another thing we need to take care of at this point is making sure we have network connectivity to some required AWS services for our trigger. Depending on your VPC of choice, you may not have connectivity to the STS, Lambda and/or Secrets Manager services. We can fix this by adding VPC endpoints for each of these to our VPC. If you get an error message about this when setting up the MSK trigger for the Lambda function, follow these instructions:</p><p>Go to the VPC dashboard and select “Endpoints” from the left side menu. Then click on “Create Endpoint” on the top right. Fill in a descriptive name for your endpoint and then search and select the com.amazonaws.&lt;REGION&gt;.sts service from the “Services” list. Remember to replace &lt;REGION&gt;with your region.</p><p>Now select your VPC from the VPC list, select ALL the subnets where MSK brokers are deployed, and for each, Select the subnet ID from the combobox. Select the “IPv4” IP address type and then select the security group we set up for our VPC:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*PJKfui4OZVIq2bTZmmfLpg.png" /><figcaption>Creating VPC Endpoints</figcaption></figure><p>Leave the rest as is and click on “Create Endpoint” at the bottom. Repeat the process for the lambda and secretsmanager services as well.</p><h3>Lambda Router</h3><p>Now that you have a Lambda function, we can write code for it and configure a trigger. Here is an example Go code that will take care of everything our Lambda’s will do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55a3cde9f232ba9bec9f353c521ba365/href">https://medium.com/media/55a3cde9f232ba9bec9f353c521ba365/href</a></iframe><p>As can be seen, this code encapsulates the Lambda Go SDK functionality required to run the proper handler function when the Lambda function is activated. The handlers specifically expect a Kafka data structure (this is being deserialized by the AWS Lambda SDK for us) and we then take the JSON items contained within and convert to our own Go data structure. Finally, if specified using the KAFKATOPICand KAFKABROKERS environment variables, we also publish to a Kafka topic.</p><p>This code contains handlers for both a router and a worker, and chooses the correct one based on the NODE_ROLEenvironment variable.</p><p>Please note that while the Confluence MSK connector we used publishes the data to Kafka in JSON format, the Debezium connector uses the Rust <a href="https://serde.rs/">Serde</a> serialization instead. The resulting structure looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b505e6e7fac959315fa7edacbac8433a/href">https://medium.com/media/b505e6e7fac959315fa7edacbac8433a/href</a></iframe><p>This means we will need to replace the JSON deserialization code with something like <a href="https://github.com/Xuanwo/serde-go">serde-go</a>, which we will not cover in this article.</p><p>In order to build you code for Lambda, you need to specify some Go build parameters like this:</p><pre>GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o medium-lambda-node</pre><p>and then zip the resulting binary. If you which to easily reuse your code, it is recommended to upload the zip file to S3 at this point.</p><p>Now go to your Lambda function’s settings and select the “Code” tab. Click on “Upload from”, select “.zip file”, click “Upload” in the dialog that popped up and select your zip file. If you uploaded to S3, select “Amazon S3 location” instead then paste the S3 link URL to your zip file.</p><p>Next, under the “Runtime settings” section, click the “Edit” button and enter your compiled binary’s filename in the “Handler” box:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4LEgjM71MO3CKKf2Jk8AGQ.png" /><figcaption>Lambda — Uploading Code to the function</figcaption></figure><p>Click on “Save” and give your lambda a few minutes to load the new code.</p><h3>Lambda MSK Trigger</h3><p>Next, we will set up the MSK trigger. This trigger will connect to the MSK cluster, listen on our initial topic, and then trigger the Lambda on new incoming messages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mw4ZSfLF3R_ErD9nVoaaxg.png" /></figure><p>You can either click on “+ Add Trigger” from the “Function overview” section, or go to the “Configuration” tab, select the “Triggers” section on the left and then click on “Add trigger” on the right.</p><p>In the new dialog, select the “MSK” trigger type. This will open the trigger’s settings. Select the MSK cluster, set the desired batch size, your “Batch Window” (the max polling time in seconds for the topic) and then fill in the topic name.</p><p>By default, the trigger will handle new incoming messages. If you want it to process ALL the messages in the topic, select “Trim horizon” from the “Starting position” box. This is the desired action for us as one of our requirements was that we do not want to lose messages so we can dynamically plug in components into our pipeline to start handling previously unknown message types.</p><p>In this article we are not taking care of Authentication. However, there is a fine point to note here. We created the MSK cluster with the default Authentication settings, which means that both “Unauthenticated” and “IAM role-based authentication” are enabled. The trigger will default to using “IAM role-based authentication” for which we previous added the “kafka-cluster” actions to our Lambda execution role’s policy. If these permissions are missing, you will get a “SASL authentication failed” error message from the trigger. We did NOT enable SASL authentication in our MSK cluster, so why are we getting this error? Well, this is because behind the scenes, AWS implements the “IAM role-based authentication” mechanism using SASL.</p><p>As we are not tackling authentication here, just go ahead and click the “Add” button to create the new trigger:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*c3lq0oIx_KRPbVvRbLLsFw.png" /><figcaption>Lambda — Creating an MSK Trigger</figcaption></figure><p>Deploying the trigger can take a few minutes, and once deployed we can configure and test our router.</p><p>Under the “Configuration” section, select “Environment variables” on the left and then click the “Edit” button and add the NODE_ROLE variable with ROUTER as the value.</p><p>If we now add this new document to our DocumentDB, it will be published to the pipeline.intake.inserts topic by the MSK connector as we saw before. The trigger will then pick it up and trigger the Lambda. Our sample code will output the information read in the message to CloudWatch so if you go to the log group we created above, you will see a new log entry appearing and within something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TieO-8e_B5UU9pjgXnlf9w.png" /><figcaption>Lambda — Successful RunCloudWatch Output</figcaption></figure><p>In order to finalize the router’s work, we want to demonstrate that it can actually route messages to different topics based on their type. The Lambda code will use the color field as a type for the message and will route the message to a Kafka topic named pipeline.type.&lt;COLOR&gt;. So, create two new topics: pipeline.type.blue and pipeline.type.green.</p><p>Next, we should tell our Lambda where MSK is so it can actually publish the messages to the various topics so go back to the environment variables and add a variable called KAFKABROKERS and set its value to be a comma-separated list of the brokers in you MSK cluster. For example:</p><pre>b-1.medium-msk.i78wus.c3.kafka.eu-west-2.amazonaws.com:9094,b-2.medium-msk.i78wus.c3.kafka.eu-west-2.amazonaws.com:9094,b-3.medium-msk.i78wus.c3.kafka.eu-west-2.amazonaws.com:9094</pre><p>You may note that we are using port 9094 here as our nodes are connecting to MSK securely using TLS. This will tell our example code to publish the data to the proper queue in MSK in addition to printing to the log.</p><p>Now, if we add a new document with the same message as before, we will be able to use the console consumer as we did before to listen on the pipeline.type.blue topic and we will see the message appear under that topic with a few seconds from creation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8PJ3OGbkASpzTkAyTlhl_Q.png" /><figcaption>Kafka CLI Consumer</figcaption></figure><p>Our router picked up the new document, determined that the message type is blue and published the data to the pipeline.type.blue queue as desired.</p><h3>Lambda Processor</h3><p>The final piece of the puzzle is the processor node, which is just another Lambda function that uses the same code as before. Go ahead and replicate the process we used for the router Lambda to create a new Lambda with an MSK trigger listening on the pipeline.type.blue topic. This time, set the NODE_ROLE environment variable to WORKER so the worker handler function is used.</p><p>Finally, we can test the full E2E mechanism by adding a new document as before, and we will see a new log entry in CloudWatch for the new Lambda function with the content of the document.</p><p>If we create another document with green as the color, we will see the new message appearing under the pipeline.type.green topic, but no Lambda function will be activated as we do not have a trigger listening on this topic. The messages will accumulate in this topic until we create a new Lambda function capable of processing “green” messages and add a trigger for it that listens on the pipeline.type.green topic.</p><p>Our sample pipeline is now complete!</p><h3>Conclusion</h3><p>In this article we demonstrated how to configure various AWS components (VPC, EC2, DocumentDB, S3, IAM, CloudWatch, MSK and Lambda) and tie them together to create an E2E processing pipeline that triggers automatically when new documents are inserted into the DB. For this article, we chose the smallest available instance sizes for the various service so our EC2 instance and our DocumentDB are running for free while our Lambda functions are only billed when running (i.e., when triggered by a new document published into the proper topic until they finish processing it).</p><p>Our pipeline can be dynamically configured to accommodate any processing structure by creating Kafka topics as edges in our graph and Lambda functions as nodes with triggers for the specific Kafka topics. Restructuring can be done while the system is running without losing any data.</p><p>We also covered various CLI, shell and GUI tools for working with MongoDB and Kafka as well as remotely connecting to our resources via SSH port forwarding.</p><p>Hopefully, this document provides a good starting point for anyone interested in building fully managed cloud-based processing pipelines using AWS services.</p><h3>Thanks</h3><p>I wish to thank <a href="https://medium.com/@juliarvalenti">Julia Valenti</a> for her amazing assistance in reviewing and editing this article ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f320f855a09" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cisco-fpie/taming-of-the-queue-f320f855a09">Taming of the Queue</a> was originally published in <a href="https://medium.com/cisco-fpie">cisco-fpie</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Reasons DevOps Should Integrate Apache Airflow & Great Expectations]]></title>
            <link>https://medium.com/cisco-fpie/5-reasons-devops-should-integrate-apache-airflow-great-expectations-9427a177da7b?source=rss----e03a79ee8c73---4</link>
            <guid isPermaLink="false">https://medium.com/p/9427a177da7b</guid>
            <category><![CDATA[great-expectations]]></category>
            <category><![CDATA[data-pipeline]]></category>
            <category><![CDATA[apache-airflow]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Shiv Deshmukh]]></dc:creator>
            <pubDate>Tue, 24 May 2022 21:34:10 GMT</pubDate>
            <atom:updated>2022-05-24T21:34:10.058Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*pwf48cKQ2coB_1Seb6Rs7A.png" /></figure><p>Data pipelines can present numerous challenges for DevOps. This is because the more data pipelines you work with, the higher the risk that your data will become difficult to manage.</p><p>As we know, data is not static. It changes constantly, and it must be validated continuously to ensure that data quality issues don’t destroy whichever pipelines you are feeding your data through. You must also be able to react quickly to problems with your data in order to avoid disrupting workflows.</p><h3>Introducing Great Expectations and Apache Airflow</h3><p>Fortunately, the open source community has built some great tools to solve this challenge.</p><p>One is <a href="https://greatexpectations.io/">Great Expectations</a>, an open-source software used for vetting data quality. Great Expectations data validation helps teams avoid bad data propagate in the pipeline through data testing, documentation and profiling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*T14yB_c4Lg32Qy4n.png" /></figure><p>Great Expectations in a real-world data pipeline.</p><p>Another tool is <a href="https://airflow.apache.org/">Apache Airflow</a>, which lets you programmatically author, schedule and monitor data workflows. Airflow provides an orchestration and management framework for integrating data pipelines with DevOps tasks. It supports any type of mainstream environment — containers, public cloud, VMs and so on.</p><p>You can use Great Expectations and Airflow separately. But to maximize your ability to keep your data pipelines moving efficiently, you should integrate these tools together. Here are 5 reasons these tools should be integrated.</p><h3>Catch data issues early on</h3><p>The concept of <a href="https://devops.com/devops-shift-left-avoid-failure/">“shifting left”</a> — which means catching issues early, when they are easier to resolve — is central to the DevOps methodology.</p><p>Integrating Great Expectations and Airflow helps DevOps teams apply this principle to data pipelines. It lets you identify issues earlier in the pipeline, ensuring that only validated data is passed into the next stage of the workflow. Instead of waiting to discover that data quality issues have broken your workflow, you can detect and resolve them as early as possible, significantly increasing efficiency.</p><h3>Achieve greater precision</h3><p>By using Great Expectations and Airflow together, you can see exactly where in a workflow data issues lie. In turn, you can fix the data efficiently. Instead of having to guess how low-quality data impacts your workflow, you can pinpoint the relationship between problematic data and workflow tasks, then remedy it directly. This means that the workflow will proceed smoothly as planned without being impacted by data-quality issues.</p><h3>Avoid pipeline-wide searches</h3><p>The Airflow dashboard displays each particular task and task failure automatically. That means there is no need to search through your entire pipeline when troubleshooting workflow issues or understanding the state of data within your workflow. By automatically identifying exactly where the data issue lies, you can take the appropriate steps to remedy it in a timely manner.</p><h3>Minimize failure risks</h3><p>When you use Great Expectations and Airflow together, you can be confident that each new step in your workflow will be executed only after the data it depends on has been validated from a quality perspective.</p><p>This means you can limit the potential for failure and clean up errors that would result in incorrect data filtering through your directed acyclic graph (DAG).</p><h3>Create scalable pipelines</h3><p>Data pipelines built with Airflow are highly scalable, and Great Expectations data validation helps you double-down on scalability, no matter how much data you have to work with.</p><p>So, no matter the quantity of your data, Airflow and Great Expectations ensure that you can operate efficiently and at scale.</p><h3>Conclusion</h3><p>Although integration between Great Expectations data validation and Apache Airflow is relatively new, there are excellent reasons to use the tools in tandem. Doing so exponentially increases the value that you could achieve by using either tool on its own. By automatically validating data in your pipeline, you ensure that DevOps time is used more efficiently, rather than having to manually check for data quality issues. This allows you to focus more on development, rather than worrying about data quality in the pipelines.</p><p>Learn how to integrate the tools in this <a href="https://shivdesh.medium.com/optimize-your-data-pipeline-with-apache-airflow-and-great-expectations-8d378e70db6a?source=your_stories_page-------------------------------------">blog post</a>, which walks through the process step-by-step.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9427a177da7b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cisco-fpie/5-reasons-devops-should-integrate-apache-airflow-great-expectations-9427a177da7b">5 Reasons DevOps Should Integrate Apache Airflow &amp; Great Expectations</a> was originally published in <a href="https://medium.com/cisco-fpie">cisco-fpie</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Open Source Well Architected]]></title>
            <link>https://medium.com/cisco-fpie/open-source-well-architected-8702e383c0e5?source=rss----e03a79ee8c73---4</link>
            <guid isPermaLink="false">https://medium.com/p/8702e383c0e5</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[frameworks-and-libraries]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[architectural-design]]></category>
            <dc:creator><![CDATA[Sushama Shroff]]></dc:creator>
            <pubDate>Tue, 17 May 2022 14:17:16 GMT</pubDate>
            <atom:updated>2022-05-17T14:17:16.510Z</atom:updated>
            <content:encoded><![CDATA[<p>We are increasingly seeing the rise of Open-Source Software (OSS) solutions. Also, more and more organizations are now using Open-Source projects as part of their solutions — Whether it means, integrating with a single open-source solution or a combination of open-source solutions to come up with a unified product, there may be several challenges.</p><p>This article discusses prospective solutions/processes that would help design well architected products that are built using primarily open-source solutions as its sub-components, in-turn driving the adoption of open-source.</p><p><strong>Motivation</strong></p><p>Recently, as part of the “<strong><em>Future Products and Innovation” </em></strong><em>team at the</em><strong><em> “Emerging Technologies and Incubation” </em></strong><em>group at</em><strong><em> Cisco</em></strong>, our team has been working on exploring several open-source solutions for a holistic data landscape.</p><p>We researched several open-source solutions, trying to see how these would fit into a data landscape. This got me thinking-How can we design processes around easing open-source adoption?</p><p>Ideally, it would be similar to how cloud vendors have built processes and tools to ease their cloud adoption journey.</p><p><strong>Problem</strong></p><p>As we combine several open-source solutions and try to build a product based on that, integrating those with our in-house product, things start to get complicated.</p><ul><li>Which open-source solutions do you use?</li><li>How do these open-source solutions rate on various factors? Licensing, developer community, ease of use, ability to contribute, design and architecture, customer adoption, product roadmap etc.</li><li>How do these open-source solutions interact with each other — Are they compatible — do they complement or contrast each other?</li><li>Are they modular enough to be plug n’ play solutions — so you can pick and choose the right features from each?</li><li>Do they expose enough APIs that will help integrate — how convenient is it to add more?</li><li>How easy is it to modify the interfaces to make them seamlessly work with each other?</li><li>Can they be deployed standalone or have dependencies — what’s the deployment strategy?</li><li>How do these open-source solutions fit into the overall product architecture?</li><li>How do you ensure you integrate with them, while not violating good architecture principles?</li><li>How do you make all this a time efficient process?</li></ul><p>And the list goes on …</p><p>Well, let me ask you this? How about if we had a framework, a toolkit to guide us through the process of architecting our products that are based on open-source solutions or maybe hybrid solutions using open source and in-house developed projects.</p><p>With all major cloud vendors, there is a well-architected toolkit or a well-architected framework that provides guidance on how to build and architect your products on the cloud. As an example, AWS offers the <a href="https://aws.amazon.com/architecture/well-architected/?wa-lens-whitepapers.sort-by=item.additionalFields.sortDate&amp;wa-lens-whitepapers.sort-order=desc">AWS Well architected framework</a> and the <a href="https://aws.amazon.com/well-architected-tool/?whats-new-cards.sort-by=item.additionalFields.postDateTime&amp;whats-new-cards.sort-order=desc">AWS Well architected Tool</a>, which helps you review the state of your workloads and compares them to the latest AWS architectural best practices, while guiding you through the process. This is true for other cloud vendors as well.</p><p>There are cloud solution architects that offer help with architecting products on the cloud. There are solution architects, enterprise architects, technical architects that help with designing solutions using a multitude of products.</p><p>But do we have either of those dedicated to open-source? NO</p><p>- There is no Open-Source Well architected framework/ toolkit per say. There are several resources that we can refer to, but coming from disparate sources, it is a rather time and effort consuming process.</p><p>- There is no explicit Open-Source Solution architect position in the industry. Engineers/Architects/Solution Architects/Product leaders replace them. They need to keep themselves up to date with the evolving open-source community and the new solutions that are launched.</p><h4>Solution</h4><p>There cannot be a ‘one size fits all’ kind of solution to this problem. But can there be a middle ground?</p><p>Can we have a hybrid solution — combining an Open-source Well architected framework, an Open Source Well architected toolkit, supervised by an Open-Source Solution architect?</p><p>- <strong>Open-Source Well Architected Framework</strong></p><p>This could focus on the architectural principles that have commonalities with the microservices design patterns and general distributed system design principles, focusing more on the factors that would ease the integration between open-source solutions as well as building hybrid solutions comprising open-source and in-house products.</p><p>- <strong>Open-Source Well Architected Toolkit</strong></p><p>This could be designed as a toolkit that could provide users with different options for open-source solutions that can be used based on the filters and preferences they enter.</p><p>Provide important insights like concise reports on the open-source options, compatibility scores with other open-source options etc. Additionally, indicate if the choices adhere to the Open-Source Well architected framework and provide tips on design modifications. Of course, this would include a human in the loop.</p><p>- <strong>Open-Source Solution Architects</strong></p><p>This is mostly an extension of the current role performed by say, Engineers/Technical Architects/Solution Architects. This is different from an open-source advocate/evangelist role, that focuses more on advocating specific open-source products. The distinction being that — an open-source Solution architect would primarily be responsible for evaluating different open-source solutions to see how they would fit into the current product landscape.</p><p><strong>Benefits</strong></p><ul><li>Would increase the adoption of open-source solutions.</li><li>Would help design and architect solutions based on open-source with a quicker turn-around time. This is especially important for the “Design Thinking” approach used for Innovation products.</li><li>A single repository of good design patterns, around designing products using open-source solutions.</li><li>A single product to help you in designing products using open-source solutions.</li><li>For open-source enthusiasts — a new position dedicated to working in open-source.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8702e383c0e5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cisco-fpie/open-source-well-architected-8702e383c0e5">Open Source Well Architected</a> was originally published in <a href="https://medium.com/cisco-fpie">cisco-fpie</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimize Your Data Pipeline with Apache Airflow and Great Expectations]]></title>
            <link>https://medium.com/cisco-fpie/optimize-your-data-pipeline-with-apache-airflow-and-great-expectations-8d378e70db6a?source=rss----e03a79ee8c73---4</link>
            <guid isPermaLink="false">https://medium.com/p/8d378e70db6a</guid>
            <category><![CDATA[data-pipeline]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[apache-airflow]]></category>
            <category><![CDATA[great-expectations]]></category>
            <category><![CDATA[application]]></category>
            <dc:creator><![CDATA[Shiv Deshmukh]]></dc:creator>
            <pubDate>Tue, 17 May 2022 14:16:40 GMT</pubDate>
            <atom:updated>2022-05-17T14:16:40.603Z</atom:updated>
            <content:encoded><![CDATA[<p>If you build or maintain applications that rely on data, there’s a decent chance you’re familiar with both Apache Airflow and Great Expectations.</p><p><a href="https://airflow.apache.org/">Apache Airflow</a> is an open source tool that helps DevOps teams build and manage workflows programmatically. It can help drive data pipelines by using standard Python features to define complex workflow requirements as Directed Acyclic Graphs, or DAGs, then execute those workflows automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/0*C-TCUhaFSHa1MTRO.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*GxS_J9X9NrZ8kKZr.png" /></figure><p><a href="https://greatexpectations.io/">Great Expectations</a>, which is also open source, is a data validation tool. Engineers can use it to define data testing, documentation and profiling requirements which data must pass before it is moved down the workflow pipeline. It also flags data quality errors so that teams can remedy them before progressing to the next step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*x46TIqsLF8d0dswe.png" /></figure><h3>Combining Apache Airflow with Great Expectations data</h3><p>You can use Airflow and Great Expectations separately. But wouldn’t it be great if you could integrate them in such a way that they work seamlessly in tandem, with Airflow defining data pipeline flows and Great Expectations automatically validating data as it moves according to those flows? Well, you can, and this blog shows you how.</p><p>By integrating Airflow and Great Expectations, you not only save time, but you can also validate data quality automatically within a database. You can find data errors faster, reduce the occurrence of data quality issues that may slow down your data pipeline, and minimize the manual effort that your engineers spend managing data quality and movement.</p><p>Keep reading for a step-by-step guide to using Airflow and Great Expectations in tandem.</p><h3>Step 1: Set up Great Expectations</h3><p>We’ll start by installing and configuring Great Expectations.</p><p>We will use simple MySQL DB “world_x” containing four tables country, city, countrylanguage, countryinfo listed here:</p><p><a href="https://dev.mysql.com/doc/world-x-setup/en/">https://dev.mysql.com/doc/world-x-setup/en/</a></p><p>Follow the instructions above to set it up on your local host and port 3306</p><p>With our MySQL database set up, let’s install Great Expectations. Here’s a Bash script (ge.sh) that will do everything you require.</p><pre><strong>#!/bin/bash</strong></pre><pre>## Database Credentials<br>world_db_host=&quot;localhost&quot;<br>port=&quot;3306&quot;<br>username=&quot;demo_user&quot;<br>password=&quot;demo_pass&quot;<br>world_db=&quot;world_x&quot;</pre><pre>printf &quot;Setting up Great Expectations for UMP...\n\n&quot;</pre><pre>printf &quot;Using following Database config:\n&quot;<br>printf &quot;HOST: %s\n&quot; &quot;$world_db_host&quot;<br>printf &quot;PORT: %s\n&quot; &quot;$port&quot;<br>printf &quot;USERNAME: %s\n&quot; &quot;$username&quot;<br>printf &quot;DATABASE: %s\n&quot; &quot;$world_db&quot;</pre><pre>printf &quot;Remove existing GE dirs, if exists...\n\n&quot;<br>rm -rf great_expectations</pre><pre>printf &quot;Setting up Python venv...\n\n&quot;<br>python3 -m venv venv<br>source ./venv/bin/activate</pre><pre>printf &quot;Installing required GE pip packages...\n\n&quot;<br>python3 -m pip install --upgrade pip<br>pip3 install great_expectations<br>pip3 install pymysql<br>pip3 install sqlalchemy<br>pip3 install jupyterlab<br>pip3 install notebook</pre><pre>printf &quot;\nGE is up with version:\n&quot;<br>great_expectations --version</pre><pre>printf &quot;Initializing GE and datasource...\n\n&quot;<br>/usr/bin/expect -c &#39;<br>spawn great_expectations --v3-api init<br>expect -re {OK to proceed?} {send &quot;Y\r&quot;}<br>send &quot;great_expectations --v3-api datasource new\n&quot;<br>expect -re &quot;:&quot;<br>send &quot;2\r&quot;<br>expect -re &quot;:&quot;<br>send &quot;1\r&quot;<br>&#39;<br>ls -l</pre><pre>printf &quot;Setting up MySQL Data Sources...\n\n&quot;<br>python3 setup_datasources.py world_db_datasource $world_db_host $port $username $password $world_db</pre><pre>printf &quot;Setting up Expectations Suites for world_x DB...\n\n&quot;<br>python3 setup_expectations.py world_db_city_expectation world_db_datasource city ID,Name,CountryCode,District,Info<br>python3 setup_expectations.py world_db_country_expectation world_db_datasource country Code,Name,Capital,Code2,Covid_Hotspot<br>python3 setup_expectations.py world_db_countryinfo_expectation world_db_datasource countryinfo doc,_id,_json_schema<br>python3 setup_expectations.py world_db_countrylanguage_expectation world_db_datasource countrylanguage CountryCode,Language,IsOfficial,Percentage</pre><pre>printf &quot;Setting up checkpoints for world_x DB...\n\n&quot;<br>python3 setup_checkpoints.py world_db_city_checkpoint world_db_city_expectation world_db_datasource city<br>python3 setup_checkpoints.py world_db_country_checkpoint world_db_country_expectation world_db_datasource country<br>python3 setup_checkpoints.py world_db_countryinfo_checkpoint world_db_countryinfo_expectation world_db_datasource countryinfo<br>python3 setup_checkpoints.py world_db_countrylanguage_checkpoint world_db_countrylanguage_expectation world_db_datasource countrylanguage</pre><pre>printf &quot;Setting up s3_site locations for GE...\n\n&quot;<br>sed -i &quot;&quot; &quot;/class_name: DefaultSiteIndexBuilder/r s3_site.txt&quot; great_expectations/great_expectations.yml<br>sed -i &quot;&quot; &quot;s/site_names: \[\]/site_names: \[\&quot;local_site\&quot;\, \&quot;s3_site\&quot;\]/g&quot; great_expectations/checkpoints/*.yml</pre><pre>printf &quot;Listing all checkpoints...\n\n&quot;<br>great_expectations checkpoint list</pre><p>Specifically, this script does the following:</p><ul><li>Install required packages.</li><li>Initialize great_expectations.</li><li>Creates new datasource for MySQL using python script setup_datasources.py</li><li>and locally hosted “world_x” DB .</li><li>Creates expectations for each table in the DB using python script setup_expectations.py</li><li>Create checkpoints for each table in the database using the setup_checkpoints.py script.</li></ul><p>You’ll notice that the script references a configuration file called S3_site.txt. This script stores the S3 bucket name where you’ll store Great Expectations data:</p><pre>s3_site:<br>  class_name: SiteBuilder<br>  store_backend:<br>    class_name: TupleS3StoreBackend<br>    bucket: greatexpectations-s3<br>  site_index_builder:<br>    class_name: DefaultSiteIndexBuilder</pre><p>Once setup is complete, you should see the following data_docs sites (local and s3) added in your great_expectations.yml file:</p><pre>data_docs_sites:<br>  local_site:<br>    class_name: SiteBuilder<br>    show_how_to_buttons: <strong>true</strong><br>    store_backend:<br>      class_name: TupleFilesystemStoreBackend<br>      base_directory: uncommitted/data_docs/local_site/<br>    site_index_builder:<br>      class_name: DefaultSiteIndexBuilder<br>  s3_site:<br>    class_name: SiteBuilder<br>    store_backend:<br>      class_name: TupleS3StoreBackend<br>      bucket: ump-greatexpectations-s3<br>    site_index_builder:<br>      class_name: DefaultSiteIndexBuilder</pre><p>Note that this ge.sh script calls additional Python scripts to complete installation. One is setup_datasources.py, which looks like this:</p><pre>import sys<br>import great_expectations as ge<br>from great_expectations.cli.datasource import sanitize_yaml_and_save_datasource, check_if_datasource_name_exists<br>context = ge.get_context()</pre><pre>print(sys.argv)<br>datasource_name = sys.argv[1]<br>host = sys.argv[2]<br>port = sys.argv[3]<br>username = sys.argv[4]<br>password = sys.argv[5]<br>database = sys.argv[6]</pre><pre>example_yaml = f&quot;&quot;&quot;<br>name: {datasource_name}<br>class_name: Datasource<br>execution_engine:<br>  class_name: SqlAlchemyExecutionEngine<br>  credentials:<br>    host: {host}<br>    port: &#39;{port}&#39;<br>    username: {username}<br>    password: {password}<br>    database: {database}<br>    drivername: mysql+pymysql<br>data_connectors:<br>  default_runtime_data_connector_name:<br>    class_name: RuntimeDataConnector<br>    batch_identifiers:<br>      - default_identifier_name<br>  default_inferred_data_connector_name:<br>    class_name: InferredAssetSqlDataConnector<br>    name: whole_table&quot;&quot;&quot;<br>print(example_yaml)</pre><pre>context.test_yaml_config(yaml_config=example_yaml)</pre><pre>sanitize_yaml_and_save_datasource(context, example_yaml, overwrite_existing=False)<br>context.list_datasources()</pre><p>Another is setup_expectations.py:</p><pre>import sys</pre><pre>from great_expectations.checkpoint import SimpleCheckpoint<br>from great_expectations.profile.user_configurable_profiler import UserConfigurableProfiler</pre><pre>import great_expectations as ge<br>from great_expectations.core.batch import BatchRequest<br>from great_expectations.data_context.types.resource_identifiers import ExpectationSuiteIdentifier<br>from great_expectations.exceptions import DataContextError</pre><pre>print(sys.argv)<br>expectation_suite_name = sys.argv[1]<br>datasource_name = sys.argv[2]<br>data_asset_name = sys.argv[3]<br>ignored_columns = sys.argv[4].split(&#39;,&#39;)<br>open_data_docs = sys.argv[5] if len(sys.argv) &gt;= 6 else &#39;false&#39;</pre><pre>context = ge.data_context.DataContext()</pre><pre>try:<br>    suite = context.get_expectation_suite(expectation_suite_name=expectation_suite_name)<br>    print(<br>        f&#39;Loaded ExpectationSuite &quot;{suite.expectation_suite_name}&quot; containing {len(suite.expectations)} expectations.&#39;)<br>except DataContextError:<br>    suite = context.create_expectation_suite(expectation_suite_name=expectation_suite_name)<br>    print(f&#39;Created ExpectationSuite &quot;{suite.expectation_suite_name}&quot;.&#39;)</pre><pre>print(context.get_expectation_suite(expectation_suite_name=expectation_suite_name))<br>context.save_expectation_suite(expectation_suite=suite, expectation_suite_name=expectation_suite_name)</pre><pre>suite_identifier = ExpectationSuiteIdentifier(expectation_suite_name=expectation_suite_name)<br>context.build_data_docs(resource_identifiers=[suite_identifier])</pre><pre>batch_request = {&#39;datasource_name&#39;: datasource_name, &#39;data_connector_name&#39;: &#39;default_inferred_data_connector_name&#39;,<br>                 &#39;data_asset_name&#39;: data_asset_name, &#39;limit&#39;: 1000}</pre><pre>validator = context.get_validator(<br>    batch_request=BatchRequest(**batch_request),<br>    expectation_suite_name=expectation_suite_name<br>)<br>column_names = [f&#39;&quot;{column_name}&quot;&#39; for column_name in validator.columns()]<br>print(f&quot;Columns: {&#39;, &#39;.join(column_names)}.&quot;)<br>validator.head(n_rows=5, fetch_all=False)</pre><pre>profiler = UserConfigurableProfiler(<br>    profile_dataset=validator,<br>    excluded_expectations=None,<br>    ignored_columns=ignored_columns,<br>    not_null_only=False,<br>    primary_or_compound_key=False,<br>    semantic_types_dict=None,<br>    table_expectations_only=False,<br>    value_set_threshold=&quot;MANY&quot;,<br>)<br>suite = profiler.build_suite()</pre><pre># Additional Expectations<br>for x in range(len(ignored_columns)):<br>    validator.expect_column_values_to_not_be_null(column=ignored_columns[x])</pre><pre>print(validator.get_expectation_suite(discard_failed_expectations=False))<br>validator.save_expectation_suite(discard_failed_expectations=False)</pre><pre>checkpoint_config = {<br>    &quot;class_name&quot;: &quot;SimpleCheckpoint&quot;,<br>    &quot;run_name_template&quot;: &quot;%Y%m%d-%H%M%S-&quot; + expectation_suite_name,<br>    &quot;validations&quot;: [<br>        {<br>            &quot;batch_request&quot;: batch_request,<br>            &quot;expectation_suite_name&quot;: expectation_suite_name<br>        }<br>    ]<br>}<br>checkpoint = SimpleCheckpoint(<br>    f&quot;_tmp_checkpoint_{expectation_suite_name}&quot;,<br>    context,<br>    **checkpoint_config<br>)<br>checkpoint_result = checkpoint.run()</pre><pre>context.build_data_docs()</pre><pre>validation_result_identifier = checkpoint_result.list_validation_result_identifiers()  # [0]<br>if open_data_docs == &#39;true&#39;:<br>    context.open_data_docs()</pre><p>Finally, we have setup_checkpoints.py:</p><pre>from ruamel.yaml import YAML<br>import great_expectations as ge<br>from pprint import pprint<br>import sys</pre><pre>yaml = YAML()<br>context = ge.get_context()</pre><pre>print(sys.argv)<br>my_checkpoint_name = sys.argv[1]<br>expectation_suite_name = sys.argv[2]<br>datasource_name = sys.argv[3]<br>data_asset_name = sys.argv[4]<br>open_data_docs = sys.argv[5] if len(sys.argv) &gt;= 6 else &#39;false&#39;</pre><pre>yaml_config = f&quot;&quot;&quot;<br>name: {my_checkpoint_name}<br>config_version: 1.0<br>class_name: SimpleCheckpoint<br>run_name_template: &quot;%Y%m%d-%H%M%S-{my_checkpoint_name}&quot;<br>validations:<br>  - batch_request:<br>      datasource_name: {datasource_name}<br>      data_connector_name: default_inferred_data_connector_name<br>      data_asset_name: {data_asset_name}<br>      data_connector_query:<br>        index: -1<br>    expectation_suite_name: {expectation_suite_name}<br>&quot;&quot;&quot;<br>print(yaml_config)</pre><pre># Run this cell to print out the names of your Data Sources, Data Connectors and Data Assets<br>pprint(context.get_available_data_asset_names())</pre><pre>context.list_expectation_suite_names()</pre><pre>my_checkpoint = context.test_yaml_config(yaml_config=yaml_config)</pre><pre>print(my_checkpoint.get_substituted_config().to_yaml_str())<br>context.add_checkpoint(**yaml.load(yaml_config))</pre><pre>context.run_checkpoint(checkpoint_name=my_checkpoint_name)</pre><pre>if open_data_docs == &#39;true&#39;:<br>    context.open_data_docs()</pre><p>How to Execute</p><ul><li>Copy all files (ge.sh, s3_site.txt, setup_datasources.py, setup_expectations.py, setup_checkpoints.py) in the same directory.</li><li>Execute ge.sh script which will do all the required setup and creates necessary great_expectation’s new Data Context to hold your project configuration.</li></ul><p>Great Expectations will create a new directory with the following structure:</p><pre>great_expectations<br>|-- great_expectations.yml<br>|-- expectations<br>|-- checkpoints<br>|-- plugins<br>|-- .gitignore<br>|-- uncommitted<br>    |-- config_variables.yml<br>    |-- data_docs<br>    |-- validations</pre><p>Note: Ensure path for above root directory for great_expectations is set to ENV variable “GE_ROOT_DIR” before proceeding with Airflow setup</p><h3>Step 2: Set up Apache Airflow</h3><p>Now that Great Expectations is installed, you can set up Apache Airflow and configure DAGs to integrate Airflow with Great Expectations.</p><p>Copy following two files airflowinstall.sh and airflow_greatexpectations.py in a directory</p><p>This script(airflowinstall.sh) will do basic setup required for Airflow on your machine</p><pre><strong>#! /bin/bash</strong></pre><pre># set airflow home as<br>export AIRFLOW_HOME=$(pwd)/air<br>export AIRFLOW__CORE__ENABLE_XCOM_PICKLING=True</pre><pre>printf $AIRFLOW_HOME</pre><pre>printf &quot;Installing required pip packages...\n\n&quot;<br>pip3 install apache-airflow<br>pip3 install great_expectations airflow-provider-great-expectations&gt;=0.1.0<br>pip3 install pymysql</pre><pre>printf &quot;Moving DAG file to airflow dir...\n\n&quot;<br>pwd<br>mkdir -p air/dags<br>cp airflow_greatexpectations.py air/dags/<br>ls -l air/dags/</pre><pre>printf &quot;Initialize and Start Airflow...\n\n&quot;<br>airflow dags list</pre><pre># initialize the database<br>airflow db init</pre><pre># provide your user login credentials and save<br>airflow users create \<br>    --username demo_user \<br>    --firstname airflowr \<br>    --password demo_pass \<br>    --lastname airflowr\<br>    --role Admin \<br>    --email demo123@gmail.com</pre><pre># start the web server and scheduler<br>airflow webserver --port 8080 -D<br>airflow scheduler</pre><p>This is a script (airflow_greatexpectations.py) to execute great_expectations checkpoints with Airflow DAGs using GreatExpectationsOperator:</p><pre>import datetime<br>import logging<br>import os</pre><pre>from airflow import DAG<br>from great_expectations_provider.operators.great_expectations import GreatExpectationsOperator</pre><pre># Set ENV variable(GE_ROOT_DIR) path to absolute path of great_expectations directory on your machine<br>ge_root_dir = os.environ.get(&#39;GE_ROOT_DIR&#39;)<br>print(&quot;GE_ROOT_DIR:&quot;, ge_root_dir)<br></pre><pre>def on_failure_func(context):<br>    &quot;&quot;&quot;Define custom failure notification behavior&quot;&quot;&quot;<br>    dag_run = context.get(&#39;dag_run&#39;)<br>    task_instances = dag_run.get_task_instances()<br>    print(&quot;WARNING: These task instances failed which can cause data consistencies&quot;, task_instances)<br>    logging.error(&#39;WARNING: These task instances failed which can cause data consistencies: {}&#39;.format(task_instances))<br></pre><pre>with DAG(<br>        dag_id=&quot;great_expectations_dag&quot;,<br>        start_date=datetime.datetime(2022, 1, 19),<br>        on_failure_callback=on_failure_func,<br>        catchup=False,<br>        schedule_interval=None<br>) as dag:<br>    ge_world_db_city_checkpoint_pass = GreatExpectationsOperator(<br>        task_id=&quot;task_world_db_city_checkpoint&quot;,<br>        data_context_root_dir=ge_root_dir,<br>        checkpoint_name=&quot;world_db_city_checkpoint&quot;<br>    )<br>    ge_world_db_country_checkpoint_pass = GreatExpectationsOperator(<br>        task_id=&quot;task_world_db_country_checkpoint&quot;,<br>        data_context_root_dir=ge_root_dir,<br>        checkpoint_name=&quot;world_db_country_checkpoint&quot;,<br>        trigger_rule=&quot;all_done&quot;<br>    )<br>    ge_world_db_countryinfo_checkpoint_pass = GreatExpectationsOperator(<br>        task_id=&quot;task_world_db_countryinfo_checkpoint&quot;,<br>        data_context_root_dir=ge_root_dir,<br>        checkpoint_name=&quot;world_db_countryinfo_checkpoint&quot;,<br>        trigger_rule=&quot;all_done&quot;<br>    )<br>    ge_world_db_countrylanguage_checkpoint_pass = GreatExpectationsOperator(<br>        task_id=&quot;task_world_db_countrylanguage_checkpoint&quot;,<br>        data_context_root_dir=ge_root_dir,<br>        checkpoint_name=&quot;world_db_countrylanguage_checkpoint&quot;,<br>        trigger_rule=&quot;all_done&quot;<br>    )</pre><pre>    ge_world_db_city_checkpoint_pass &gt;&gt; ge_world_db_country_checkpoint_pass &gt;&gt; ge_world_db_countryinfo_checkpoint_pass \<br>        &gt;&gt; ge_world_db_countrylanguage_checkpoint_pass</pre><p>Now, run the airflowinstall.sh script to complete Airflow setup.</p><h3>Step 3: View Apache Airflow &amp; Great Expectations in action</h3><p>With all the pieces in place, you can see your creation by opening a browser to <a href="http://localhost:8080/">http://localhost:8080/</a>.</p><p>Notice the Airflow dashboards and Great Expectations DAG. You can trigger the DAG and validate that all tasks have run successfully:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*hCbLssWmKc0U9Mgj.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*OpLYyqjPUfOrmkep.png" /></figure><p>Upon completion of this run, you’ll see all the Great Expectations results in the S3 bucket you defined earlier, and/or localhost based on data_docs_sites entries in great_expectations.yml:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*joyWCFcpDyaKQaFp.png" /></figure><p>You can also get detailed results on individual expectation suites by clicking on individual rows for specific tables:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*9v_3SuJWC-6RVId8.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*nVYm_PMUlT9iThUc.png" /></figure><p>Congratulations! Your data pipeline is now built, and you can automatically validate and monitor scheduled workflows.</p><h3>Conclusion</h3><p>Integrating Apache Airflow and Great Expectations helps engineers double down on the value of both tools. The ability to automate data validation within an automated data workflow saves time and adds efficiency.</p><p>Learn more by checking out the <a href="https://docs.greatexpectations.io/docs/">Great Expectations</a> and <a href="https://airflow.apache.org/docs/apache-airflow/stable/">Apache Airflow</a> documentation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d378e70db6a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cisco-fpie/optimize-your-data-pipeline-with-apache-airflow-and-great-expectations-8d378e70db6a">Optimize Your Data Pipeline with Apache Airflow and Great Expectations</a> was originally published in <a href="https://medium.com/cisco-fpie">cisco-fpie</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Render RTSP Streams within a React App]]></title>
            <link>https://medium.com/cisco-fpie/how-to-render-rtsp-streams-within-a-react-app-e7957e591075?source=rss----e03a79ee8c73---4</link>
            <guid isPermaLink="false">https://medium.com/p/e7957e591075</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[security-camera]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Julia Valenti]]></dc:creator>
            <pubDate>Fri, 15 Apr 2022 11:56:16 GMT</pubDate>
            <atom:updated>2022-04-15T11:56:16.642Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Prerequisites</em>: <em>NodeJS, Docker, git<br></em>Repository for this tutorial can be found <a href="https://github.com/juliarvalenti/rtsp-react">here</a>.</p><p>If you need to incorporate an <strong>RTSP stream</strong> into an existing web app, you might think its as easy as adding the RTSP URL into your HTML5 &lt;video /&gt;. However, it’s not really that simple. In this article, we will stand up a simple React application with <a href="https://vitejs.dev/"><strong>Vite</strong></a>, a Golang-based video encoding service with <a href="https://github.com/deepch/RTSPtoWeb"><strong>RTSPtoWeb</strong></a>, and view the encoded and streamed video in our React application using the <a href="https://videojs.com/"><strong>VideoJS</strong></a> package.</p><p>Before we get started with coding, let’s learn a little bit about the history of RTSP.</p><h3>Time for a little history lesson…</h3><p><a href="https://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol">RTSP, a.k.a. Real-Time Streaming Protocol,</a> is a protocol for streaming video online. RTSP is most commonly used for security footage streaming, such as those coming from CCTV or IP cameras. The strength of RTSP is that rather than forcing the viewers to download an entire video before watching it, the RTSP stream allows them to watch the content before the download is fully complete. Nowadays, this is not very special, but when RTSP was first proposed in 1996 it was a very cutting edge concept.</p><p>Developers who try to integrate RTSP into their apps today may struggle because you cannot directly stream RTSP within web applications. A few extra steps need to be taken before it can be rendered within a browser. The process outlined below is just one of the many ways that we can solve this issue, but it is the one which worked best for me. Your situation may vary!</p><h3>Getting Started</h3><p>If you don’t have a proper RTSP video stream ready before you begin development, you can check out this article <a href="https://g33ktricks.blogspot.com/p/the-rtsp-real-time-streaming-protocol.html">here</a> which has good amount of video links to use as placeholders in your project. For my examples, I will be using rtsp://rtsp/stream/pattern. This example RTSP just shows some simple SMPTE color bars, text, visual noise, and a repeating tone.</p><figure><img alt="Screengrab from rtsp://rtsp/stream/pattern" src="https://cdn-images-1.medium.com/max/802/1*GKq7ZSkh2BBi_7zsxeliiw.png" /><figcaption>Screengrab from rtsp://rtsp/stream/pattern</figcaption></figure><p>Opening the link in the browser is not enough to view the stream, but if you have <a href="https://www.videolan.org/vlc/">VLC</a> installed, you should be able to view it by going “<em>File &gt; Open Network”</em> and pasting the RTSP URL into the box and clicking “<em>Open</em>.” If you cannot view this example and you do not have an example of your own, I suggest you scour the internet for an alternative. This guide won’t be very useful without an RTSP feed!</p><p>After we’ve confirmed that we can see the example stream, we’ll work on setting up our web app. You may already have a React app that you’re working on for an existing project, so feel free to use that instead, but for this tutorial will stand up a small example app. The same concepts can be applied to Vue, Angular, or Svelte as well, but you will need to figure out a few things on your own.</p><h3>Creating our example React app</h3><p>We’re going to be using Vite for our React app build tooling. Let’s create a new project by running npm create vite@latest, going through the wizard, and choosing “react-ts” when prompted. Run npm install in the directory shown in order to install dependencies and then run npm run dev to spin up the development server.</p><figure><img alt="Your app should look something like this now." src="https://cdn-images-1.medium.com/max/1024/0*I4-giH94cjhlJPxf" /><figcaption>Your app should look something like this now.</figcaption></figure><p>Now, dive into the App.tsx file and clear mostly everything out.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9586bdb5f0c28e0e6d1c7a73711ff924/href">https://medium.com/media/9586bdb5f0c28e0e6d1c7a73711ff924/href</a></iframe><p>This gives us a simple playground where we can start iterating on our code.</p><h3>Starting RTSPtoWeb</h3><p>Now that we have an <em>incredibly</em> simple web app, we can begin setting up our RTSP conversion service. For this, we will be leveraging <a href="https://github.com/deepch/RTSPtoWeb">RTSPtoWeb</a>. RTSPtoWeb is a Golang-based service which converts RTSP streams to a browser-friendly format.</p><p>Lets start by cloning the RTSPtoWeb project by running the following commands:</p><pre>git clone <a href="https://github.com/deepch/RTSPtoWeb">https://github.com/deepch/RTSPtoWeb</a><br>cd RTSPtoWeb</pre><p>RTSPtoWeb requires a config.json file to be defined and configured before runtime in order to understand where your RTSP videos are. After cloning the repo, we can edit the config.json that they’ve provided by running vim config.json inside of the RTSPtoWeb folder. We can leave most of the fields as they are, but we’re going to update the “streams” item to have the following information:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/388f8e31618882409ef9a2e8fff48587/href">https://medium.com/media/388f8e31618882409ef9a2e8fff48587/href</a></iframe><p>If you’re following along with the Git repo, I’ve included the full <a href="https://github.com/juliarvalenti/rtsp-react/blob/main/rtsp-to-web-config.json">config.json here</a>. Let’s note a few things about this configuration:</p><ol><li>That we’ve defined a stream titled <strong>“pattern”</strong></li><li>Within that stream we have defined a <strong>channel 0</strong> containing the URL of our example RTSP stream.</li></ol><p>Keep this structure in mind, because we’ll be using it later to help us understand what URL to access when we want to define our video src in our web app.</p><p>Now that we’ve updated the config.json, all that’s left to do is to start the RTSPtoWeb service by running the following command:</p><pre>GO111MODULE=on go run *.go</pre><p>You may receive a network notifications request during this stage, but just allow it to proceed. We can now confirm that the service is running by visiting <a href="http://localhost:8083/">localhost:8083</a> in our browser. If your dashboard looks like the image below, then you should be in the clear!</p><figure><img alt="RTSPtoWeb Dashboard" src="https://cdn-images-1.medium.com/max/915/0*Pn9zw2xKQd656DEZ" /><figcaption>RTSPtoWeb Dashboard</figcaption></figure><p>Within this dashboard we can see a few of the different formats that RTSPtoWeb can convert our stream: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Media_Source_Extensions_API">MSE</a>, <a href="https://en.wikipedia.org/wiki/HTTP_Live_Streaming">HLS</a>, and <a href="https://webrtc.org/">WebRTC</a>. For our use, we will be leveraging the HLS stream. Confirm that your HLS stream loads properly by clicking on the HLS button. You should see the following image confirming that the video is being appropriately converted by RTSPtoWeb.</p><figure><img alt="“pattern” RTSP -&gt; hls video feed" src="https://cdn-images-1.medium.com/max/1024/0*46zxqeCXAHVy8O7Q" /><figcaption>“pattern” RTSP -&gt; hls video feed</figcaption></figure><p>Under the hood, the HLS video format consists of two key parts:</p><ol><li>An .m3u8 playlist digest file which defines the references to the segments of the video</li><li>A series of .ts files which contain the individual video segments (note that .ts does <strong>not </strong>stand for “TypeScript” here 🙂)</li></ol><p>The src for our video will be this .m3u8 file.</p><h3>Integrating VideoJS</h3><p>In order to bring our HLS video into the browser, we need to add a new library to our front-end. Let’s stop our Vite React server with cmd+c, install the necessary package, and start the server again with the following commands:</p><pre>npm install --save-dev video.js @types/video.js<br>npm run dev</pre><p>In order to set up video.js in an app, we will need to define a special component to handle the video feed. Lets start by creating a new file named VideoFeed.tsx. For this component, we will be using the <a href="https://docs.videojs.com/tutorial-react.html">Video.js React tutorial documentation</a> to build out our component. I’ll provide the snippet below, but if any of it is confusing, I recommend checking out that tutorial for more information.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec90df07fa370b9fff011e3b03dbdd4b/href">https://medium.com/media/ec90df07fa370b9fff011e3b03dbdd4b/href</a></iframe><h3>Bringing it all together now…</h3><p>Now that we have our VideoFeed component set up, we can integrate our stream into it. Remember from our previous setup that we defined our stream as being named “pattern” and our channel as “0”? In order to access the appropriate m3u8 file, we’re going to need to formulate the correct URL. The format is <a href="http://localhost:8083/stream/%7Bstream_name%7D">http://localhost:8083/stream/{stream_name}</a>/channel/{channel_name}/hls/live/index.m3u8 . Let’s replace stream_name with “pattern” and channel_name with “0”. This makes our final URL <a href="http://localhost:8083/stream/pattern/channel/0/hls/live/index.m3u8.">http://localhost:8083/stream/pattern/channel/0/hls/live/index.m3u8.</a></p><p>Let’s add our VideoFeed component into our main App.tsx file with the correct src.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b92c92a6c21051db301ded76f63e15c5/href">https://medium.com/media/b92c92a6c21051db301ded76f63e15c5/href</a></iframe><p>Now when we refresh our page, we should be able to see our RTSP feed appropriately in our web browser!</p><figure><img alt="Hello world! with RTSP feed below" src="https://cdn-images-1.medium.com/max/343/1*Wus5y9pIdm0qWAZ35e27xQ.png" /><figcaption>Hello world!</figcaption></figure><h3>Conclusion</h3><p>RTSP is a pain in the butt, but it doesn’t have to be so difficult with these wonderful open source projects. Like I said before, there are a few ways around this problem. If this method didn’t work for you, then I highly recommend checking out <a href="https://dev.to/tejasvi2/rtsp-stream-to-web-browser-using-ffmpeg-1cb">this article detailing a similar approach with FFMPEG</a>, this project called <a href="https://github.com/aler9/rtsp-simple-server">rtsp-simple-server</a>, or <a href="https://stackoverflow.com/questions/32708716/embed-rtsp-video-stream-on-html-website">this method using VLC</a>.</p><p>If you just want to check out the finished code from this article, check out the code repository <a href="https://github.com/juliarvalenti/rtsp-react">here</a>. Follow the instructions in the <a href="https://github.com/juliarvalenti/rtsp-react/blob/main/README.md">README</a> and you should be good to go.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7957e591075" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cisco-fpie/how-to-render-rtsp-streams-within-a-react-app-e7957e591075">How to Render RTSP Streams within a React App</a> was originally published in <a href="https://medium.com/cisco-fpie">cisco-fpie</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decentralized Identities Demystified]]></title>
            <link>https://medium.com/cisco-fpie/decentralized-identities-demystified-49a65159196c?source=rss----e03a79ee8c73---4</link>
            <guid isPermaLink="false">https://medium.com/p/49a65159196c</guid>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[verifiable-credentials]]></category>
            <dc:creator><![CDATA[aviva vaknin]]></dc:creator>
            <pubDate>Wed, 16 Feb 2022 20:28:32 GMT</pubDate>
            <atom:updated>2022-02-17T14:23:57.304Z</atom:updated>
            <content:encoded><![CDATA[<p>In a world that revolves about online transactions we use our digital identity at work, at home, and across every app, service, and device. Users must register for an account with a different username &amp; password for every service provider with whom they wish to engage, and in such systems the user’s identity is managed by each service provider so that our identity and digital interactions are owned and controlled by other parties, some of whom we aren’t even aware of. Access to our IDs can be removed at any time by external parties and security of the information we send to perform minimal transactions may be easily comprised. We grant consent and access rights to many apps and devices, which requires a high degree of vigilance to track who has access to what information. For enterprise, collaboration requires complex orchestration to securely exchange data. Centralized and federated systems are the main identity models and neither has provided an identity service that is both private and easy to use.</p><p>Users want transactions to be more secure while incurring less overhead. Towards this end a new ecosystem is evolving based on decentralized identities. The Decentralized Identity Model describes how to handle scenarios when working over the internet in a secure manner that respects users’ privacy. It is based on distributed ledger technology<em> </em>(e.g., blockchain) and provides users with the ability to prove their identity <em>without giving it away</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*Pp6GYIYiZ8i-dQ4mLOjrcg.jpeg" /><figcaption>Figure 1: The data model for verifiable credentials is a World Wide Web Consortium (W3C) Recommendation, “Verifiable Credentials Data Model 1.0 — Expressing verifiable information on the Web”, published 19 November 2019.</figcaption></figure><h3><strong>DID Building Blocks</strong></h3><p>The DID ecosystem employs the following building blocks:</p><ul><li><strong><em>decentralized identities (DID)</em></strong></li></ul><p>DIDs are a new type of identifier that enables verifiable, decentralized digital identity. A DID represents a piece of information you wish to prove, and can identify any subject — a person, organization, thing, data model, abstract entity, etc. — that the controller of the DID decides that it identifies. DIDs restore control of identity to consumers using an identity wallet containing verified information about themselves from certified issuers, by enabling the controller to prove control over it. They are implemented independently of any centralized registry, identity provider, or certificate authority.</p><ul><li><strong><em>decentralized identities documents</em></strong></li></ul><p>DIDs are presented in the form of a document which contains information associated with the DID. DID documents specify verification methods and services relevant to interactions with the DID subject. The W3C DID Working Group is developing a standard for the core architecture, data model and representation of DIDs. A DID document can express cryptographic material, verification methods, or service endpoints, which provide a set of mechanisms enabling a DID controller to prove control of the DID. A DID document may also contain semantics about the subject that it identifies.</p><p>The standard elements of DID document include <em>the DID</em> <em>itself</em> for self-description, <em>a set of public keys</em> for verification, <em>a set of authentication methods</em>, <em>a set of service endpoints</em> for interaction, a <em>timestamp</em> for audit history and a <em>signature</em> for integrity.</p><ul><li><strong><em>verifiable credentials (VC)</em></strong></li></ul><p>A verifiable credential is certified proof of your identity which is stored by the user in their own wallet. More formally, verifiable credentials are data objects consisting of claims made by an accredited issuer attesting to the validity of information about the user (holder of the VC).</p><p>Verifiable credentials represent information found in physical credentials — passport or license — as well as new things that have no physical equivalent — ownership of a bank account. They are digitally signed and therefore tamper-resistant and instantaneously verifiable. VCs can be issued by anyone, about anything, and can be presented to and verified by everyone and are comprised of metadata, claims, and proofs of those claims. An open standard for digital credentials is being defined by the W3C working group.</p><ul><li><strong><em>verifiable claims</em></strong></li></ul><p>A verifiable claim is a claim of possession of a VC. A verifiable claim may be a qualification, an achievement, a quality, or a piece of information about an entity’s background. Examples include a person’s name, government ID, payment provider, home address, university degree, etc.</p><ul><li><strong><em>verifiable presentations</em></strong></li></ul><p>Verifiable presentations are signed proof of your claim that can be presented to a verifying party. They contain identity data, taken from Verifiable IDs and/or attestations, that the holder creates and chooses to share with a verifier, and proofs that can be signed with cryptographic keys. Verifiable presentations are generated or derived from verifiable credentials and can be cryptographically verified by the verifier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*2mNfMZSLyIEFqWgHmRYggw.png" /><figcaption><em>Figure 2: Sample verifiable presentation</em></figcaption></figure><ul><li><strong><em>distributed verifiable data registry</em></strong></li></ul><p>The verifiable data registry, or ledger, stores <em>proofs</em> of claims, not the claims themselves; issuers of credentials write to the registry and verifiers read from the registry. A distributed verifiable data registry is any system that supports recording DIDs and returning data necessary to produce a DID in a non-centralized manner. Examples include distributed ledgers, decentralized file systems, blockchains, databases of any kind, peer-to-peer networks, and other forms of non-centralized trusted data storage.</p><p>The distributed ledger/data registry acts as the source of truth in place of a central authority. The identity information is not held on the ledger but within a wallet managed by the user. Ledgers store keys (or other) to prove the validity of the claims and presentations presented by the holder to the verifier.</p><h3><strong>DID Personas</strong></h3><p>The personas in the DID ecosystem are termed<strong><em> issuers, holders,</em></strong> and <strong><em>verifiers</em></strong>. Certified credential <strong><em>issuers</em></strong> of credentials attest that the user’s proof is accurate and create verifiable credentials signed with the issuer’s DID as well as the users’ DIDs. The <strong><em>holder</em></strong> can then present the verifiable credentials as proof of their identity to any <strong><em>verifier</em></strong> that requests it. <strong><em>Verifiers </em></strong>can verify that the proofs are true via a distributed ledger.</p><h3><strong>Putting it all together: DID ecosystem data flow</strong></h3><p>Users create a <strong><em>decentralized identity (DID)</em> </strong>for each piece of information to be shared.</p><p>An<strong> </strong>issuer validates the DID and records the proof in a public distributed ledger and returns a <strong><em>verifiable credential (VC)</em> </strong>with the issuers signature. The user/<strong>holder</strong> of the VC then stores it in a digital wallet<strong>.</strong></p><p>In order for the <strong>holder</strong> of a VC to make a <strong>verifiable claim </strong>using the VC to prove an identity, the holder signs the VC, and creates a verifiable presentation of the claimed identity. The holder then submits it to the <strong>verifier</strong> who validates the presentation using the proof from the distributed ledger.</p><p>A full view of the DID ecosystem and data flow is depicted below in Figure 3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*0Gh8AU7rleUFt5jC_JZTNg.png" /><figcaption><em>Figure 3: The DID Ecosystem</em></figcaption></figure><p>To best illustrate the ecosystem data flow let us look at an example.</p><p>Say, <em>Woodgrove</em> Inc. is a company, <em>Proseware</em> is another company that offers Woodgrove employees discounts, and <em>Alice</em> is an employee at Woodgrove, Inc. who wants to get a discount from Proseware.</p><p>Woodgrove is deploying a verifiable credential (VC) solution to provide a more manageable way for Alice to prove she is an employee of Woodgrove. To enable Alice to use her VC the following setup takes place:</p><ul><li>The <strong>issuer</strong> of the credential, Woodgrove Inc., creates a public key and a private key.</li><li>The public key is stored on a decentralized ledger.</li><li>When the key is added to the infrastructure, the entry is recorded in the ledger.</li><li>The <strong>issuer</strong> provides Alice the private key which she stores in her wallet application.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*gCKzMvR-J6Vwtk4fpOBoRg.png" /><figcaption><em>Figure 4: VC Data Flow Diagram</em></figcaption></figure><p>When Alice is ready to make a purchase from Proseware and obtain her discount, the transaction flow is as described in Figure 4. Specifically,</p><ul><li>First, Alice requests a Woodgrove Inc. company discount from Proseware.</li><li>Next, Alice grants access to her credential to Proseware, the <strong>verifier</strong>, via her Authenticator wallet app.</li><li>In her wallet Alice has a <strong>verifiable credential </strong>signed with Woodgrove’s (the issuer) private key, as described above.</li><li>Alice then adds her signature with her private key and generates a <strong>verifiable presentation </strong>which she sends to Proseware.</li><li>Finally, Proseware, the <strong>verifier</strong>, validates Alice’s employee credentials by matching with the public keys from the public decentralized ledger.</li></ul><p>Each time Alice successfully uses the private key the transaction is logged in the wallet application.</p><h3><strong>DID syntactic components</strong></h3><p>The W3C working group is defining a standard syntax for decentralized identifiers, documents, presentations, and verifiable credentials using the components defined below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*7HfO8mxCJ83JCXS19HVPAw.png" /><figcaption><em>Figure 5: DID URI Syntax</em></figcaption></figure><p>A DID URI is composed of three parts: the scheme DID, a method identifier, and a unique method-specific identifier specified by the DID method. A DID URL is a basic DID that incorporates other standard URI components such as path, query, and fragment, used to locate a particular resource. DIDs are resolvable to DID documents.</p><p>A <em>DID subject</em> is the entity identified by the DID; anything can be the subject of a DID: person, group, organization, thing, or concept or even the DID controller.</p><p>A DID <em>controller</em> is the entity — person, organization, or autonomous software — that has the capability to make changes to a DID document. This capability is typically asserted by the control of a set of cryptographic keys used by software acting on behalf of the controller. A DID might have more than one controller and a DID subject can be one of the DID controllers.</p><p>A DID <em>method</em> is the mechanism by which a particular type of DID and its associated DID document is created, resolved, updated, and deactivated. It is defined using separate DID method specifications.</p><p>A DID <em>resolver</em> is a system component that takes a DID as input and produces a conforming DID document as output. This process is called DID <em>resolution</em>. The steps for resolving a specific type of DID are defined by the relevant DID method specification.</p><p>A DID <em>URL de-referencer</em> is a system component that takes a DID URL as input and produces a resource as output.</p><h3><strong>DID syntax</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hMSw39V9o8imqXNE8q8Mcw.png" /></figure><h4>A simple example of a verifiable credential:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7fbOygDJL4kwxL1M0sjTgw.png" /></figure><h3><strong>Ecosystem Players</strong></h3><p>The <strong><em>Decentralized identity foundation (DIF)</em></strong> is an engineering-driven organization focused on developing the foundational elements necessary to establish an open ecosystem for decentralized identity and ensure interoperation between all participants. Their vision is to enable a world where decentralized identity solutions allow entities to gain control over their identities and allow trusted interactions, and currently entertain an extensive membership.</p><p>The <strong><em>OpenID Foundation</em></strong> is a nonprofit international standards development organization that is promoting the OpenID community and technologies.</p><p>The <strong><em>World Wide Web Consortium (WC3)</em></strong> <strong><em>working group</em></strong> is leading the way in defining the syntax and standards for DID components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*69iuREwrlyUCMEVmVgsicA.png" /><figcaption><em>Figure 6: Microsoft DID Ecosystem</em></figcaption></figure><p><strong><em>Microsoft</em></strong> has pioneered the way with its own complete ecosystem based on Microsoft Azure AD Verifiable Credentials. Their ecosystem components include (1) <em>W3C</em> <em>Decentralized Identifiers </em>(DIDs) as the document and data, (2) an <em>Azure Identity Overlay Network (ION) Node </em>— did:ion — as their decentralized data registry, (3) the <em>Microsoft Authenticator App </em>as the user’s digital wallet, (4) the <em>Microsoft Resolver</em> as the API that connects to their ION node to look up and resolve DIDs using the did:ion method and return the DID Document Object (DDO), and (5) the <em>Microsoft Azure Active Directory Verified Credentials Service</em> which is an issuance and verification service in Azure that uses a REST API for W3C Verifiable Credentials that are signed with the did:ion method. It enables identity owners to generate, present, and verify claims, and forms the basis of trust between users of the systems.</p><p>Microsoft Partner service providers include A<strong><em>cuant, AU10TIX identity intelligence, CLEAR, IDEMIA, Jumio, LexisNexis Risk Solutions, Onfido, Socure, </em></strong>and<strong><em> Vu</em></strong>.</p><p>Pilots are underway in Government of Flanders in Belgium, at the National Health System in the United Kingdom, and at Keio University Tokyo Japan.</p><h3><strong>Where is this all headed?</strong></h3><p>I applaud Microsoft for leading the way into data privacy ecosystems, enabling users to parallel using their physical identification with a secure privacy preserving digital solution. Part of Microsoft’s business model is likely based on having users of their DID ecosystem register with Microsoft Azure Active Directory thus increasing their client base. However, as consumers become acquainted with and use their ecosystem, and as other ecosystems hopefully arise, users will prefer and eventually demand DID based ecosystems for their transactions, rather than having to submit personal ID numbers, birth date, and more to order lunch. It is still early in the game and the arena is open for big players to join and secure a good portion of the market.</p><p><em>This article has also been published in the </em><a href="https://techblog.cisco.com/blog/decentralized-identities-de-mystified/"><em>Cisco Tech Blog</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49a65159196c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cisco-fpie/decentralized-identities-demystified-49a65159196c">Decentralized Identities Demystified</a> was originally published in <a href="https://medium.com/cisco-fpie">cisco-fpie</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Great (data) expectations — automatic data quality validation]]></title>
            <link>https://medium.com/cisco-fpie/great-data-expectations-automatic-data-quality-validation-889852819bc9?source=rss----e03a79ee8c73---4</link>
            <guid isPermaLink="false">https://medium.com/p/889852819bc9</guid>
            <category><![CDATA[data-quality]]></category>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[great-expectations]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Mirko Raca]]></dc:creator>
            <pubDate>Fri, 11 Feb 2022 22:12:44 GMT</pubDate>
            <atom:updated>2022-02-12T10:45:25.230Z</atom:updated>
            <content:encoded><![CDATA[<h3>Great (data) expectations — automatic data quality validation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*_Qe6ZoDk-CJ0PIH0oGrPlA.png" /></figure><p>You’re working with data and you’re happy. You might be creating dashboards, recommendation systems, classifying faults — but it all starts with getting the data, and putting it through your deluxe data-massage center. You have done your exploratory data analysis, figured out value distributions, might even be lucky and got data formatted for supervised learning, and after spending an embarrassing amount of time and CPU/GPU/TPU power training your models…. the data has changed. And if you’re lucky — you noticed before your manager.</p><p>That’s where <a href="https://greatexpectations.io/">Great Expectations</a> comes in. Great Expectations (<em>GrExp</em> in the rest of text) can be simply thought of as “unit tests for your data”. As long as your system is getting new inputs through some form of <a href="https://en.wikipedia.org/wiki/Extract,_transform,_load">ETL</a>, you want to make sure that the structure, data types, and value ranges stay the same as when you trained your model(s). The library comes from the startup <a href="https://www.superconductive.com/">Superconductive</a> helmed by Abe Gong and James Campbell which has raised <a href="https://greatexpectations.io/blog/series-a-announcement/">$21M in Series A</a> in May 2021.</p><p>In the era of data-hamster mentality, GrExp is, of course, not the only solution on the market. <a href="https://www.getdbt.com/product/data-testing/">dbt</a> contains its own data integrity tests but is out-of-the-box much poorer in choice of tests, which makes sense since it’s trying to address a broader subject than GrExp (you can read about it in our <a href="https://medium.com/cisco-fpie/transforming-your-data-with-data-build-tool-dbt-854dddc5f37f">other post</a>). <a href="https://www.soda.io/">Soda</a> is another solution with the same goal but was more platform-oriented and tries to be a bit too smart and UI-dialog-clicky (for authors taste). GrExp became the preferred choice because it’s a drop-in python library, which plays well with the rest of our pipeline, and can be locally deployed.</p><blockquote><strong>Tip #1</strong>: GrExp library sends anonymous usage statistics by default, which can be disabled in the configuration file (<a href="https://greatexpectations.io/blog/anonymous-usage-statistics/">notes here</a>).</blockquote><p>GrExp does three things:</p><ol><li>The library in its core is a set of python functions with easy syntax to define your data expectations (pun intended by the library creators);</li><li>based on the defined set of expectations, GrExp automatically generates HTML documentation which describes your data sources (think pydoc for data tables and fields) which you can host on-line for low-effort public documentation;</li><li>you can (and should) re-validate your data sources periodically and easily review records of those validations to find/debug issues if.</li></ol><h3>How did it work for us?</h3><p>Each of our ingestion processes was populating a table, so we defined each of them as a GrExp data source with a suite of expectations. GrExp will offer to generate initial set of expectations for you with its automated profiler, and it does a decent job in cutting down the legwork needed for basic tests. A short tutorial on this can be found <a href="https://docs.greatexpectations.io/docs/tutorials/getting_started/intro/">here</a>. You can go over <a href="https://greatexpectations.io/expectations/">all expectations</a> but some of the regular ones we used:</p><ul><li>expect_table_columns_to_match_ordered_list — will guarantee that you’ll know about a new pre-processed column your college added and forgot to tell you about,</li><li>expect_column_values_to_be_unique — so that your primary keys really make sense, and in case of composite primary key, you can use expect_compound_columns_to_be_unique,</li><li>expect_column_values_to_be_in_set — great for detecting typos in categorical fields,</li><li>expect_column_min_to_be_between , expect_column_max_to_be_between and expect_column_values_to_be_between for basic range-sanity checks and flagging unexpected inputs,</li><li>expect_column_values_to_be_dateutil_parseable — to be sure that your textual date fields have meaningful data.</li></ul><blockquote><strong>Tip #2:</strong> mostly is an expectation-function parameter which allows you to relax the condition of the check by allowing a percentage of records not to honor it. This gives leeway in your processing and means that you will not break your ETL update on a single NULL value in a non-critical field.</blockquote><p>As our ETL process was already <a href="https://airflow.apache.org/">Airflow</a>-based, so adding another python library was very easy. GrExp team is maintaining an Airflow provider (<a href="https://github.com/great-expectations/airflow-provider-great-expectations">git repo here</a>), and folks from Astronomer provided a set of useful <a href="https://github.com/astronomer/airflow-data-quality-demo/tree/main/dags/great_expectations">examples</a>.</p><p>Based on the test suits, each ingestion process (or <em>DAG</em> in Airflow terminology) got a validation step as illustrated in Figure 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*9-QgFtIEg-I8biR0HEIlhA.png" /><figcaption><em>Figure 1</em> Great expectations validation steps after local processing</figcaption></figure><p>Finally, we are hosting on our team-private server the results of validation which get refreshed on each ETL cycle. In case of validation failure, our pipeline saves the processing inputs and outputs for debugging, and GrExp validation results provide an insightful context as illustrated in Figure 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*jNDhK9uz9IBxCtykoA8EXw.png" /><figcaption><em>Figure 2</em> Example of failed validation and debugging information provided by Great Expectations</figcaption></figure><h3>Conclusion</h3><blockquote>“In a word, I was too cowardly to do what I knew to be right, as I had been too cowardly to avoid doing what I knew to be wrong.”</blockquote><blockquote>~ Charles Dickens on how technical debt occurs, Great Expectations, 1860</blockquote><p>GrExp has made us more comfortable with our daily work by timely signaling issues in both data and our processing code so far (unless my manager is reading this, in which case we had NO issues, and this is clearly just hypothetical). Data quality is the most important thing that you are not actively paying attention to, and we hope that this article will draw attention to that (potential) blind spot and propose one way of addressing it. If you have experiences with other data quality platforms/frameworks, please share them here — we await with great expectations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=889852819bc9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cisco-fpie/great-data-expectations-automatic-data-quality-validation-889852819bc9">Great (data) expectations — automatic data quality validation</a> was originally published in <a href="https://medium.com/cisco-fpie">cisco-fpie</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Virtualization with Trino Part 2]]></title>
            <link>https://medium.com/cisco-fpie/data-virtualization-with-trino-part-2-fe2b4f432e15?source=rss----e03a79ee8c73---4</link>
            <guid isPermaLink="false">https://medium.com/p/fe2b4f432e15</guid>
            <category><![CDATA[etl]]></category>
            <category><![CDATA[data-virtualization]]></category>
            <category><![CDATA[data-processing]]></category>
            <category><![CDATA[trinos]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Juacall Bernard]]></dc:creator>
            <pubDate>Mon, 07 Feb 2022 17:06:21 GMT</pubDate>
            <atom:updated>2022-02-16T17:59:34.421Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9cHxFNg2gKg7CfsT" /><figcaption>Photo by <a href="https://unsplash.com/@gamell?utm_source=medium&amp;utm_medium=referral">Joan Gamell</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Welcome back! I will be explaining some of the details of Trino, going through the process of setting up Trino and running some queries that combine data from multiple sources. A Linux operating system or a MAC, a 64-bit version of Java 11 and a Java Development Kit are required for running Trino.</p><p><strong>Trino Cluster Setup</strong></p><p>You will find everything you need to get started at <a href="https://trino.io/download.html">https://trino.io/download.html</a> . There will be downloads for the server package, a CLI, and a JDBC driver. There is also a docker image available. There’s information about the docker image at <a href="https://hub.docker.com/r/trinodb/trino">https://hub.docker.com/r/trinodb/trino</a> . The server package is a ZIP file that contains the files needed to run a Trino server. This package does not contain a default config. After unzipping the contents the config files will need to be added. Given the fact that you are performing the setup it will be beneficial when troubleshooting because it allows you to easily locate the configuration files. The first part of the battle when using software is locating these files.</p><p>First you have to create an “etc” directory inside the installation directory. This directory will hold:</p><ul><li>Node Properties: environmental configuration specific to each node</li><li>JVM Config: command line options for the Java Virtual Machine</li><li>Config Properties: configuration for the Trino server</li><li>Catalog Properties: configuration for <a href="https://trino.io/docs/current/connector.html">Connectors</a> (data sources)</li></ul><p>The node properties file should be named node.properties. The contents will look like:</p><pre>node.environment=trino_test<br>node.id=coordinator_node_one<br>node.data-dir=/var/trino/data</pre><p>The “node.environment” setting describes a cluster. All nodes within a cluster will need to have the same environment name. The “node.id” is a unique id for this instance of Trino. Remember every node is a separate instance of a Trino server. The “node.data-dir” is where the logs and other data will reside. There will also be a link to your etc directory and the plugin directory in the data directory.</p><p>The JVM config will be named jvm.config. The JVM config should look something like…</p><pre>-server<br>-Xmx16G<br>-XX:-UseBiasedLocking<br>-XX:+UseG1GC<br>-XX:G1HeapRegionSize=32M<br>-XX:+ExplicitGCInvokesConcurrent<br>-XX:+ExitOnOutOfMemoryError<br>-XX:+HeapDumpOnOutOfMemoryError<br>-XX:-OmitStackTraceInFastThrow<br>-XX:ReservedCodeCacheSize=512M<br>-XX:PerMethodRecompilationCutoff=10000<br>-XX:PerBytecodeRecompilationCutoff=10000<br>-Djdk.attach.allowAttachSelf=true<br>-Djdk.nio.maxCachedBufferSize=2000000</pre><p>At first glance it could look daunting, at least it did to me. The options are straight forward like other configs. Something to make note of. When a out of memory exception occurs the process is terminated because the JVM becomes inconsistent. Also the default /tmp directory does not allow execution of code in some installations, which prevents Trino from starting. You can workaround this by overriding the temporary directory by adding -Djava.io.tmpdir=/path/to/other/tmpdir to the list of JVM options.</p><p>Lets move on to config properties. Config properties will be named config.properties in your etc directory. Config properties is where you decide if your Trino server or node will function as a coordinator or a worker. For testing, a coordinator can process work as a worker and handle coordinating. This is not ideal for larger clusters. A coordinator looks like:</p><pre>coordinator=true<br>node-scheduler.include-coordinator=false<br>http-server.http.port=8080<br>query.max-memory=50GB<br>query.max-memory-per-node=1GB<br>discovery.uri=http://example.net:8080</pre><p>For a worker:</p><pre>coordinator=false<br>http-server.http.port=8080<br>query.max-memory=50GB<br>query.max-memory-per-node=1GB<br>discovery.uri=http://example.net:8080</pre><p>Changing node-scheduler.include-coordinator=true will allow a coordinator to schedule work.</p><ul><li>query.max-memory: The maximum amount of distributed memory, that a query may use.</li><li>query.max-memory-per-node: The maximum amount of user memory, that a query may use on any one machine.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*c0BuDVyj8PEHXSxPLNaceA.png" /><figcaption>Distributed Memory Figure from <a href="https://www.futurelearn.com/info/courses/supercomputing/0/steps/24022">Future Learn</a></figcaption></figure><p>Distributed memory is memory used in a multiprocessor computer system where each processor has its own private memory. This is also could be multiple computers communicating through a network.</p><p>From here you will need some sort of client. I’ll be using the CLI tool that Trino provides. There will be an example of the catalog.properties file when we start moving data.</p><p><strong>Command Line Interface</strong></p><p>The CLI comes as a jar and will need permission to execute. If you are using the CLI you can do that by typing chmod +x path-to-cli.jar in a terminal. To the execute the jar run the command ./name-of-jar.jar --server localhost:8080 --catalog medium --schema default. The server is where the CLI will be sending the queries and where the server we set up earlier will be listening. You can exit the CLI by typing quit or exit.</p><p><strong>Catalog.properties/Connectors</strong></p><p>I will be using some MySQL databases. Connectors will need to be created in a “catalog” folder. The path should be your-server-path/etc/catalog. A docker setup will also have a ‘etc’ directory. The mysql.properties connector will look something like the following.</p><pre>connector.name=mysql<br>connection-url=jdbc:mysql://example.net:3306<br>connection-user=root<br>connection-password=secret</pre><p>Each connector can also have connection options that can be altered depending on which database you’re using. You can view the options of each connector in Trino’s documentation. That can be found at <a href="https://trino.io/docs/current/connector/mongodb.html">https://trino.io/docs/current/connector/mongodb.html</a>.</p><p>Now that the connectors are setup, run the server then your client. I run my server locally and in the foreground when testing to catch any errors. If there are any issues I will see them print out to the terminal.</p><p><strong>SQL Queries</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*papRhGivPXqF2Wl_jX4Jag.png" /><figcaption>Trino Table Request Breakdown by Juacall - Bracket icons created by Roundicons Premium</figcaption></figure><p>The above image shows how a request to a table will be structured. The catalog will be the name of the connector/catalog properties file. Do not confuse this with the name inside the file. That represents what database you’re using. In this case I’m using a MySQL database. The schema holds the tables and functions. The tables hold the data.</p><p>Some things to make note of. You cannot create auto-incrementing columns. or use select into queries. The select into query creates the result table for you when merging/joining data from multiple tables. The result table will have to be created beforehand and then an insert into query can be used. Also for MySQL you cannot drop tables unless you add the config option allow-drop-table=true .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xkz2jmh6Uqp8qXVmR9nagw.png" /></figure><p>Before starting, run the query show catalogs; . This is to make sure your connectors are available to use. So what I am going to be doing first is taking data from the airport database and world_x database and add it to the trino_result database. First we need to create the table. Unless it is necessary to know what kinda of data is in the columns. You can just run a show columns query to pick the columns of interest that will be used to create a new trino_result table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0So1XRzVe4rzSNuMAVpWbQ.png" /><figcaption>Create Table Query</figcaption></figure><p>If the connector supports it you can also use create view . Views do not contain any data. Instead, the query stored by the view is executed every time the view is referenced by another query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*434raIOCvn4q21FqvpjLjw.png" /><figcaption>Insert Into Query</figcaption></figure><p>In the insert into query you can see aliases for the tables. I recommend using aliases when possible to prevent typing the long call to the table and misspellings. When that’s done. A simple select query will need to be run to make sure our data was moved and combined successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*51PZGXWxFQ8s5P6L1Y-B3A.png" /><figcaption>Trino Result Table</figcaption></figure><p>Trino also provides functions and operators for advanced users of SQL. Like not showing airports from the country ‘AFG’ or showing all countries where the amount of people who speak English is between 10 to 20 percent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ixhcskSISoaoPiaEDpsO9w.png" /></figure><p>Trino is a powerful tool and hopefully this gives you a good intro on how to use Trino and what Trino can do.</p><p><em>Thanks for reading this article! Leave a comment below if you have any questions.</em></p><p>References:<a href="https://trino.io/">https://trino.io/</a>, <a href="https://www.starburst.io/info/oreilly-trino-guide/">https://www.starburst.io/info/oreilly-trino-guide/</a>, <a href="https://hub.docker.com/r/trinodb/trino">https://hub.docker.com/r/trinodb/trino</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe2b4f432e15" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cisco-fpie/data-virtualization-with-trino-part-2-fe2b4f432e15">Data Virtualization with Trino Part 2</a> was originally published in <a href="https://medium.com/cisco-fpie">cisco-fpie</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go micro services using gRPC & gRPC Gateway servers]]></title>
            <link>https://medium.com/cisco-fpie/go-micro-services-using-grpc-gateway-server-87c2e77bc990?source=rss----e03a79ee8c73---4</link>
            <guid isPermaLink="false">https://medium.com/p/87c2e77bc990</guid>
            <dc:creator><![CDATA[Suresh Yekasiri]]></dc:creator>
            <pubDate>Sat, 29 Jan 2022 00:36:22 GMT</pubDate>
            <atom:updated>2022-01-29T00:36:22.910Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong>:</h3><p>It’s go time!!</p><p>Article helps you understanding, setting up <a href="https://grpc.io/">gRPC</a> &amp; <a href="https://github.com/grpc-ecosystem/grpc-gateway">gRPC gateway</a> servers with Golang and implementing a simple micro service. Target audience for this article are developers and tech enthusiasts. gRPC is a great framework, it generates client and server <a href="https://developers.google.com/protocol-buffers">protobuf’s</a> (stubs) in <a href="https://developers.google.com/protocol-buffers/docs/tutorials">many languages</a>, faster, easy to implement and highly scalable.</p><p>There are some situations or clients does not support this modern technology from client side due to lack of support for <a href="https://en.wikipedia.org/wiki/HTTP/2">HTTP/2</a>, so gRPC gateway is a great way to integrate with very few additions on top of gRPC stuff.</p><h4>Why would you need to consider gRPC &amp; gRPC gateway over traditional Go micro services?</h4><p>Very easy to implement &amp; work with protobuf’s, it avoids writing HTTP routes in the code and manually passing the handlers. So it will let developers to focus on business logic implementation. Highly performable, scalable and proven concept from Google.</p><p><strong>gRPC</strong>:</p><ul><li>A modern open-source high performance Remote Procedure Call framework.</li><li>Simple service definition</li><li>Start quickly and scale</li><li>Works across languages and platforms</li><li>Bi-directional streaming with HTTP/2 and integrated auth.</li><li>Protobuf: Binary format crafted by Google and supports based off HTTP/2. Captures less size compare to JSON or XML, hence faster to transport.</li></ul><p><strong>gRPC gateway:</strong></p><ul><li>Acts as a reverse proxy to the gRPC server.</li><li>A server those routes with HTTP/1.1 with JSON payloads</li><li>Internally converts the requests into a gRPC protobuf’s .</li><li>Allows you to define API’s as gRPC methods with requests &amp; response defined as protobuf, and then implement those gRPC handlers on your api server.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*WmjwrLGWasQkTRDzmevk-A.png" /></figure><p><strong>What knowledge do you need to understand this article?</strong></p><ul><li>Basic knowledge on REST services with Go, HTTP and JSON etc.</li></ul><h3>Setup</h3><ol><li><strong>Golang</strong></li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc07c252a2d58e6eb1ae9f009935527e/href">https://medium.com/media/bc07c252a2d58e6eb1ae9f009935527e/href</a></iframe><p>2<strong>. Docker</strong></p><p>3. <strong>Protobuf</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b002ea37d6818fe73db474f6b033d5c/href">https://medium.com/media/9b002ea37d6818fe73db474f6b033d5c/href</a></iframe><p>Refer: <a href="http://google.github.io/proto-lens/installing-protoc.html">http://google.github.io/proto-lens/installing-protoc.html</a> for any issues with protobuf setup.</p><p>4. <strong>Update Env</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fcef9d7834937478365b9a55710204d/href">https://medium.com/media/1fcef9d7834937478365b9a55710204d/href</a></iframe><h3>Implementation</h3><p>Let us get started with creating gRPC &amp; gRPC gateway servers, wiring them, and implementing a test service.</p><p><strong>Step 1</strong>: Define the proto</p><p>Start defining a .proto file with Request &amp; Response protobuf messages. The api example that we are trying to implement here is a simple HTTP POST request with a name field and response as Greet message with the provided name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b44c55a497c7025c93fb403d27e392a/href">https://medium.com/media/0b44c55a497c7025c93fb403d27e392a/href</a></iframe><p>Define gRPC messages for req, resp and rpc method declaration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7d93a29824612681ce5018e8e980236/href">https://medium.com/media/d7d93a29824612681ce5018e8e980236/href</a></iframe><p>Now let us make above “SayHello” declaration to gRPC gateway compatible by providing additional info like HTTP method, url pattern etc.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/412f39c234d7540c35ddcd7c5a800891/href">https://medium.com/media/412f39c234d7540c35ddcd7c5a800891/href</a></iframe><p>Complete proto snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4566adcfc76567ca80fa5fcbc1e79645/href">https://medium.com/media/4566adcfc76567ca80fa5fcbc1e79645/href</a></iframe><p><strong>Step 2:</strong> Generate protobuf’s</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd8347e1bd57c992936134a722840578/href">https://medium.com/media/dd8347e1bd57c992936134a722840578/href</a></iframe><p>This step generates gRPC protobuf’s and gRPC gateway files. gRPC gateway file holds standard HTTP handlers that will convert the request into protobuf’s &amp; routes the request to gRPC controllers.</p><p><strong>Step 3:</strong> Start gRPC Server</p><p>Below function sets up gRPC server running at port 50000, this is internal one and can not exposed to outside of the world.</p><p>Major components:</p><p>i. Creating gRPC server</p><p>ii. Get a provider that will hold actual service definitions. Refer #Step 5 for more details about server struct.</p><blockquote>s := &amp;server{log: log} // line #5</blockquote><p>iii. Register server and provider. Below one is generated method from #Step 2</p><blockquote>api.RegisterTestServicesServer // line #9</blockquote><p>Below is complete snippet for gRPC server creation &amp; setup:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68e94b7b9cb0ad69bc10ca1c343abd09/href">https://medium.com/media/68e94b7b9cb0ad69bc10ca1c343abd09/href</a></iframe><p><strong>Step 4:</strong> Start gRPC Gateway Server</p><p>Setting up gateway server to run at 9091. As mentioned in the above diagram, it acts as a <strong>Reverse Proxy</strong> and redirects all requests to gRPC server.</p><p>Following statement wires the connection between two servers.</p><blockquote>api.RegisterTestServicesHandlerFromEndpoint(ctx, gatewayMux, dialAddr, dialOpts) // line #34</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a41b66628b7c902c7f5de319d22f101b/href">https://medium.com/media/a41b66628b7c902c7f5de319d22f101b/href</a></iframe><p><strong>Step 5:</strong> main and utility functions</p><p>Here we using the Uber’s dependency injection framework to start &amp; maintain gRPC servers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a700795091fadb9eb169d99a20de698c/href">https://medium.com/media/a700795091fadb9eb169d99a20de698c/href</a></iframe><p><strong>Step 6:</strong> Implement the “SayHello” service</p><p>We registered “server” object as a provider while creating the gRPC server. This way server knows the handler method for the SayHello request.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3de84aabde1a568099fd30da5c9df5f/href">https://medium.com/media/b3de84aabde1a568099fd30da5c9df5f/href</a></iframe><p><strong>Step 7:</strong> Deploy and Test</p><p>Build and run the app and use the curl cmd mentioned in #Step 1 to test the SayHello api.</p><h3><strong>Conclusion</strong></h3><p>Step 3,4,5 are one time setups. So this process avoids all other ad-hoc steps and you can focus straight away to define proto and start implementing the business logic for your service end points.</p><p>gRPC gateway server is a best option when you deal with micro/mini (group) services where each module can use gRPC as internal api’s and only necessary api’s can be exposed to outside of the world for your client(s).</p><p>Also it’s the best alternative when you don’t have a gRPC client or a client that doesn’t support HTTP/2 versions.</p><p><a href="https://github.com/soorisoft/go-grpc-gateway-server">Git repo</a> for complete example.</p><p>Happy Coding!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87c2e77bc990" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cisco-fpie/go-micro-services-using-grpc-gateway-server-87c2e77bc990">Go micro services using gRPC &amp; gRPC Gateway servers</a> was originally published in <a href="https://medium.com/cisco-fpie">cisco-fpie</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transforming your data with ‘Data Build Tool’ (DBT)]]></title>
            <link>https://medium.com/cisco-fpie/transforming-your-data-with-data-build-tool-dbt-854dddc5f37f?source=rss----e03a79ee8c73---4</link>
            <guid isPermaLink="false">https://medium.com/p/854dddc5f37f</guid>
            <category><![CDATA[data-build-tool]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[data-warehouse]]></category>
            <category><![CDATA[data-product-creation]]></category>
            <dc:creator><![CDATA[Chidumga Izuzu]]></dc:creator>
            <pubDate>Fri, 21 Jan 2022 18:47:48 GMT</pubDate>
            <atom:updated>2022-01-21T18:47:48.248Z</atom:updated>
            <content:encoded><![CDATA[<p>More conversations have been on ETL ( Extract Transform and Load) processes in recent years. There are also several tools for the process, and one of them is DBT — a software developed as an in-house tool by the then consulting firm, <strong>Fishhouse analytics, </strong>to meet the needs of their clients. I recently spent a couple of days experimenting with dbt. I decided to put together an article that captures what DBT offers and how DBT fits in the overall data landscape.</p><p>Dbt is a transformation tool in the ELT pipeline that lets teams transform data following software engineering best practices such as modularity, portability, CI/CD, and documentation. Through native support for connectivity to <a href="http://snowflake.com/">Snowflake</a>, Amazon <a href="https://aws.amazon.com/redshift/">Redshift</a>, Google <a href="http://%20bigquery:%20Cloud%20Data%20Warehouse%20|%20Google%20Cloudcloud.google.com%20%E2%80%BA%20bigquery/">BigQuery</a>, and <a href="https://www.postgresql.org/">Postgre</a>SQL, dbt runs SQL queries against your database, warehouse, platform, or query engine to materialize your data as tables and views. It’s important to note that DBT does not extract or load your data to a warehouse; it focuses on transforming it after ingestion. It covers only the <strong>T</strong> of the<strong> ELT</strong> process.</p><p>Dbt adopts the ELT(Extract Load Transform) model over ETL (Extract Transform Load). This means that instead of the ETL approach, which requires data moving from the source to the staging area for transformation, we adopt the ELT approach, which transforms data directly in the warehouse. There is no need for data staging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISooagrRkgtr-sTbJ0NXKw.png" /></figure><p><strong>What Does DBT Offer?</strong></p><ol><li><strong>Repeatable codes</strong></li></ol><p>The exciting thing about dbt is that it allows for the reusability of SQL code. The benefit of this is a reduction of complex scripts. With dbt, all models are SELECT statements, which can be reused through YAML configuration files and Jinja language. Instead of building intermediary tables that would allow the reuse of codes, DBT uses macros (snippets of SQL codes) to avoid repeating code across multiple models. Macros are defined in .sql files in your macros directory and can be reused numerous times through referencing. Dbt allows you to combine SQL with Jinja, which brings programming aspects into SQL queries, allowing you to write if and for loops in SQL.</p><p>Essentially, with dbt, you build SQL models on top of source tables, which other models can reference using the <a href="https://docs.getdbt.com/reference/dbt-jinja-functions/ref"><strong>ref function</strong></a><strong>.</strong> Using the ref function ensures that the current model selects from the upstream tables and views. Dbt also knows the order in which to run these models, so there’s no need to define dependencies explicitly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*wKT4-IucRygbcH-WWDNtDg.png" /><figcaption>SQL without Jinja: The payment_method is repetitive and can be challenging to maintain</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*j_CI6_tXj4kQMfmdxpn8XQ.png" /><figcaption>Same SQL, but with Jinja: The repeated code above Is replaced with a for loop.</figcaption></figure><p>dbt comes in two versions: dbt core and dbt cloud. dbt Core includes a command-line interface (CLI) that enables users to execute dbt commands using a text editor. dbt Cloud is a web-based IDE that does everything the CLI does, with additional features such as lineage, orchestration, documentation, and an automated Git workflow.</p><p><strong>Automated Documentation and Directed acyclic graph (DAG):</strong></p><p>dbt allows you to generate documentation for your project. dbt goes through the project and the warehouse to create a file with information. This includes your actual code, a DAG, tests, column data types, and tables. You can add additional model details such as tests and descriptions in YAML for more comprehensive documentation. You can generate documentation by running ‘dbt docs generate,’ generating a catalog.json file in your target directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6qf0ogCwowiqRQ2SxoDjJA.png" /><figcaption>dbt goes through your project and your warehouse to generate documentation like this about your project</figcaption></figure><p>The DAG offers an overview of data sources involved in a particular transformation process and the data flow from source to target. DBT interpolates schemas to infer relationships between models and automatically updates the DAG based on references. This visualization can be helpful for less technical people who are not interested in the technological process but want an overview of how data flows throughout an organization. You can also include pre-and post-hooks in your models for effective database administration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ylLAe0JFlRqQELPlsJAvQw.png" /><figcaption><em>A DAG for a simple dbt project</em></figcaption></figure><p><strong>Automated Testing</strong></p><p>dbt comes with inbuilt tests such as:</p><ul><li>Unique: this checks if all the values in the columns are unique.</li><li>Accepted_values: this compares the content of a column against a list of accepted values.</li><li>Relationships: this checks if the values in a column exist in a different table.</li><li>Not_null: this checks if a column contains null values.</li></ul><p>You can also write custom quality test cases to check for specific business logic by combining Jinja and SQL. These tests can be configured by referencing them in the same YAML file used for a given model. If the data fails to operate under the set expectations in the YAML file, dbt flags the error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pLpKE1a7ofmaqlYXVyADvw.png" /><figcaption>An example of a schema file with descriptions and tests</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d73iOw33UFHldtjQ_gTx4w.png" /><figcaption>An example of a passing tests</figcaption></figure><p><strong>Deployment</strong></p><p>Users can publish public and private repositories using dbt’s built-in package manager, and other users can refer to these. dbt Cloud offers an automated git workflow. It connects with GitHub to automate your continuous integration pipelines. This means you don’t have to worry about orchestration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UCRpXwkp20eLuMKUKuSp4A.png" /><figcaption>Jobs are dbt commands (dbt run and dbt set) set to run on a schedule.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LpwLbjP2b_VkpShG2UlBZQ.png" /><figcaption>You can specify when and how dbt cloud should trigger this job</figcaption></figure><p><strong>Flexibility:</strong></p><p>DBT also offers maximum flexibility. If the project structure produced doesn’t fit your needs for some reason, it can be customized by editing the project configuration file (dbt_project.yml) to rearrange folders as you prefer.</p><p>dbt has <a href="https://docs.getdbt.com/docs/building-a-dbt-project/documentation">comprehensive documentation</a>, which offers step-by-step guidance on project installation and initialization, creating a profile, and running models. I tried out the DBT cloud with <a href="https://console.cloud.google.com/bigquery">BigQuery as an adapter</a>, but you can choose any accepted adapters.</p><p>I would recommend anyone working with the ELT approach to try out dbt. It is important to note that users must know how to write efficient SQL to maximize dbt. You can join the <a href="https://www.getdbt.com/community/">DBT community </a>or contribute to the project on their <a href="https://github.com/dbt-labs/dbt-core">GitHub page.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=854dddc5f37f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cisco-fpie/transforming-your-data-with-data-build-tool-dbt-854dddc5f37f">Transforming your data with ‘Data Build Tool’ (DBT)</a> was originally published in <a href="https://medium.com/cisco-fpie">cisco-fpie</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>