<?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[Stories by Waheed Brown on Medium]]></title>
        <description><![CDATA[Stories by Waheed Brown on Medium]]></description>
        <link>https://medium.com/@waheedbrown?source=rss-2f9d64752ffd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FLUIp4XLEB0yxKuw</url>
            <title>Stories by Waheed Brown on Medium</title>
            <link>https://medium.com/@waheedbrown?source=rss-2f9d64752ffd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 21:55:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@waheedbrown/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SRE Best Practices, For People in a Hurry]]></title>
            <link>https://medium.com/@waheedbrown/sre-best-practices-for-people-in-a-hurry-c49f89786b51?source=rss-2f9d64752ffd------2</link>
            <guid isPermaLink="false">https://medium.com/p/c49f89786b51</guid>
            <category><![CDATA[site-reliability]]></category>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[site-reliability-engineer]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Waheed Brown]]></dc:creator>
            <pubDate>Tue, 12 Nov 2019 23:53:38 GMT</pubDate>
            <atom:updated>2019-11-12T23:53:38.742Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DnLWdlpVKNpVH8IdsQ0wMQ.jpeg" /><figcaption>SREs are always short on time, so here is a cheat sheet to keep you live and running</figcaption></figure><p>Google’s <a href="https://landing.google.com/sre/books/">Site Reliability Engineering (SRE) handbook</a> is a comprehensive collection of best practices. This frequently makes for verbose and dry reading, more of a reference than an instruction manual. As well the industry moves fast, with the pre-2017 content of book in need of some updates.</p><blockquote><a href="https://landing.google.com/sre/books/">Google SRE Books</a> (link to the SRE Handbook and Workbook)</blockquote><p>Below is a list of 20 SRE best practices, gleaned from the SRE handbook and updated with the past year’s experiences. Sourcing both developers and customer facing engineers, I compiled this list and field tested it. A major Google Cloud customer gave positive feedback and gratefully acknowledged this list as an <strong>actionable version</strong> of the SRE handbook.</p><blockquote>Land the plane first, find the failure second<br>(Google SRE mantra)</blockquote><p><strong>1. Use GKE<br></strong>Use <a href="https://cloud.google.com/kubernetes-engine/">Google Kubernetes Engine</a> (GKE) or <a href="https://cloud.google.com/gke-on-prem/">GKE On-Prem</a><br>Leverage Google’s container management system</p><p><strong>2. Use HTTP Load Balancer<br></strong>Leverage Google’s Front End for <a href="https://cloud.google.com/load-balancing/">load balancing</a> and DDoS defense</p><p><strong>3. Don’t use static IPs<br></strong>Decouple resources from IP addresses to leverage Google Cloud Platform (GCP) networking</p><p><strong>4. Leverage GCS<br></strong><a href="https://cloud.google.com/storage/">Google Cloud Storage</a> (GCS) is a cheap distributed file system*<br>*NOTE: It’s actually blob storage, but <a href="https://cloud.google.com/storage/docs/gsutil">gsutil</a> makes it very powerful</p><blockquote><strong>Database dumps to GCS buckets</strong> make for convenient trust points</blockquote><p><strong>5. Use Stackdriver<br></strong>Use Stackdriver <a href="https://cloud.google.com/monitoring/agent/">monitoring agents</a> for more granular <a href="https://cloud.google.com/monitoring/alerts/">Stackdriver alerts</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*ZHm0a2fMoCSICZO0TFQ_3A.png" /><figcaption>Monitoring (through Stackdriver alerts) is the foundation of the SRE Pyramid</figcaption></figure><p><strong>6. Use non-human intervention<br></strong>Stackdriver allows <a href="https://cloud.google.com/functions/docs/calling/logging">Second-party triggers</a> (a.k.a. Cloud Functions)<br>Triggers are better than an alert email</p><blockquote>“Why do people always forget that <strong>you need to add a little jitter</strong>?”<br>(Ade Oshineye, Google Developer Advocate)</blockquote><p><strong>7. Distribute data sources<br></strong>Distribute data sources globally (near the biggest body of users)</p><p><strong>8. Leverage Google Cloud CDN<br></strong>Leverage Google Cloud’s <a href="https://cloud.google.com/cdn/">Content Delivery Network</a> (CDN)<br>Google Cloud CDN can cache read-only content near end users</p><p><strong>9. Use Labels and Network Tags<br></strong><a href="https://cloud.google.com/resource-manager/docs/creating-managing-labels">Label</a> every GCP resource for efficient Stackdriver monitoring<br><a href="https://cloud.google.com/vpc/docs/add-remove-network-tags">Network Tag</a> every subnet and attached network device for efficient firewalls</p><p><strong>10. Version your GCP config<br></strong>Version your GCP config (Terraform)<br>Bundle the config with the required version of apps</p><p><strong>11. GCP resource provisioning<br></strong>Quality of service (percentage uptime)should determine provisioning<br>GCP resource provisioning is primarily virtual machine CPU and memory size</p><p><strong>12. Delineate levels of service<br></strong>Delineate levels of service (example: different virtual machine tiers)</p><blockquote>“If at first you don’t succeed, <strong>back of exponentially</strong>”<br>(Dan Sadler, Google)</blockquote><p><strong>13. Use error budgets<br></strong>Determine your own error budget for each of your services<br>Service Level Objectives (SLOs) are the minimum required percentage uptime</p><p><strong>Error Budget</strong></p><ul><li>Data driven, <strong>quantifiable metric</strong> for determining <strong>risk </strong>versus <strong>effort</strong></li><li>SLOs are the data sources of error budgets</li><li>New releases can be pushed as long as there is remaining error budget</li><li>Encourages developer teams to self-police</li></ul><p><strong>Error Budget Example</strong></p><p>SLO = 99.99%<br>Existing errors = 0.005% loss of service this quarter<br>Error budget = 1 - SLO - Existing errors<br>= 1 - 99.99% - 0.006%<br>= 0.004%</p><p><strong>14. Singular human intervention<br></strong>Monitoring and error response should only require human intervention once<br>The second time the same error occurs, the response should be automated</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*_M5OQXi_1h5XJLnBGpqc4Q.png" /><figcaption>Human Intervention — Make the system work as well as it can under the circumstances</figcaption></figure><p><strong>15. Modularized infrastructure<br></strong>Use Terraform environments to modularize your infrastructure</p><p><strong>16. White Box Monitoring and Black Box Monitoring<br></strong>Use <a href="https://cloud.google.com/functions/docs/calling/logging">Stackdriver</a> for white box monitoring <br>Use Google Compute Engine (GCE) <a href="https://cloud.google.com/load-balancing/docs/health-checks">health checks</a> for black box monitoring</p><p><strong>17. Use gsutil<br></strong>Use <a href="https://cloud.google.com/storage/docs/gsutil/commands/cp">gsutil cp</a> to move data around<br>gsutil has built in checksum data validation<br>In-cloud file transfers (never leave cloud provider) are fast and secure<br>Parallelized file uploads/downloads make large transfers more efficient</p><p><strong>18. Monitor for out-of-band data transactions<br></strong><a href="https://cloud.google.com/spanner/docs/import-export-csv">Spanner backup/recovery Dataflow jobs</a> can be out-of-band monitored</p><p><strong>19. Consider Hybrid Cloud<br></strong>Employ a hybrid cloud architecture, where you can failover to on-premises<br>This includes <a href="https://cloud.google.com/gke-on-prem/">GKE On-Prem</a>, <a href="https://www.elastifile.com/">Elastifile</a>, Cloud SQL with <a href="https://cloud.google.com/sql/docs/mysql/replication/configure-external-replica">on-premises replication</a></p><p><strong>20. Set CNAME caching correctly<br></strong>Set CNAME caching time to the maximum amount of allowed downtime<br>This will be the max failover time for CNAME cutover<br>This is the last line of defense if you can’t do GCP HTTP Load Balancer cutover</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c49f89786b51" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging Serverless Functions]]></title>
            <link>https://medium.com/google-cloud/debugging-serverless-functions-53f99a7f3cb2?source=rss-2f9d64752ffd------2</link>
            <guid isPermaLink="false">https://medium.com/p/53f99a7f3cb2</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cloud-functions]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[stackdriver]]></category>
            <dc:creator><![CDATA[Waheed Brown]]></dc:creator>
            <pubDate>Sat, 09 Nov 2019 11:51:01 GMT</pubDate>
            <atom:updated>2019-11-20T00:03:13.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1J_sL18JGH-2_jg1DZ_90w.jpeg" /><figcaption>With serverless computing, the real labor is in effective debugging</figcaption></figure><p>…continued from <a href="https://medium.com/google-cloud/serverless-computing-made-easy-40e534ae410e">Serverless Computing Made Easy</a></p><p>Google Cloud Functions are a powerful way to implement serverless computing. Fully wielding this tool requires a reliable means of debugging code. In this blog post we work with a Python 3 Cloud Function, and walk through a reliable method for troubleshooting.</p><p>The example code for the below debugging exercises is available <a href="https://github.com/waheedbrown/serverless">here on Github</a>. This is the same repository used in the <a href="https://medium.com/google-cloud/serverless-computing-made-easy-40e534ae410e">previous blog post</a>. Also, it is assumed that you followed the installation steps, either from the blog post or the repo readme file. The Google Cloud Platform (GCP) resources created during installation will be referenced by the testing Cloud Function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*68NJK_JenlaPakXJYcXdYg.png" /><figcaption>Source code and debugging setup instructions are available on Github (<a href="https://github.com/waheedbrown/serverless">click here</a>)</figcaption></figure><p>Referring to the repo readme file, the debugging installation instructions are as follows:</p><p>1. Clone this repo to your workspace</p><p>2. Navigate to the debugging folder</p><p>3. Edit the prepare_log.sh script, adding in your Google Cloud Platform (GCP) specific values for project ID, zone, region and virtual machine (VM) instance ID</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*VeBiKEyape9wC8t3c4V9MQ.png" /><figcaption>Add your GCP values in prepare_log.sh, INSTANCE_ID is on the VM details page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*VHEzCiIPHjgqGTJhg4S4zQ.png" /><figcaption>The VM instance ID is a unique numerical identifier used in Stackdriver logs</figcaption></figure><p>The script using the sed command to swap in the variable values. A cleaner method would be to use <a href="https://unix.stackexchange.com/questions/294835/replace-environment-variables-in-a-file-with-their-actual-values">envsubst</a>, but I could not get this to work in my Ubuntu environment. It is worth trying, if you feel like writing your own log preparation script.</p><p>An important piece of enrichment is how the sample log data in <a href="https://github.com/waheedbrown/serverless/blob/master/debugging/sample_log.json">sample_log.json</a> was created. The process is to download an existing Stackdriver log that triggers your production Cloud Function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*8O-tsWgluOljGS8PS6WlBw.png" /><figcaption>Filter for the logs you want; a sample filter is provided in the Github repo, advanced_filter_static_ip_event.txt</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*Z8faMZQBrprZa66YmDl9tQ.png" /><figcaption>Either “View in new tab” or “Download” to view the raw JSON text of the desired Stackdriver log entries</figcaption></figure><p>The next step in preparing your own testing logs is to remove the leading and trailing square brackets, “[“ and “]“. Finally, you need to minify the JSON, removing all new line characters. The Cloud Function tester breaks when new line characters are included. Please see debugging/sample_log.json in the Github repo, for an example of a clean sample log file (with shell variables present though).</p><p>4. Run prepare_log.sh, which will produce a file called prepared_log.json</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*ZW-53lWPMKQjHtTG9I8Zxw.png" /><figcaption>Cloud Shell was used to clone the repo and create prepared_log.json, which his the GCP specific values</figcaption></figure><p>5. In the GCP console, create a Python 3 Cloud Function, the “Trigger” will be “Cloud Pub/Sub” and the “Topic” will be the one created in the above Installation steps; for “Source code” select “Inline editor” and for “Runtime” select “Python 3.x”</p><p>6. Copy-paste the contents of debugger/main.py into the “main.py” field</p><p><strong>NOTE:</strong> Your terminal may line break prepared_log.json when you try to copy its content. If the Cloud Function “Testing” tab gives you errors, this is likely the reason. You will have to make the JSON text a single continuous string, with no line breaks, in order for the “Testing” tab to accept it.</p><p>7. Continue creating the Cloud Function, naming it and the “Function to execute” as test_migrate_vm</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*dTqRUeOACrOpiRVqwSSudA.png" /><figcaption>It is crucial that the Python def name match the “Function to execute” name</figcaption></figure><p>Notice lines 5, 12 and 13 in the Python code, also available in the Github repo as debugging/main.py. In line 5, we have to rename the defined function (and likewise the “Function to execute”. We do not want the testing Cloud Function to have a naming conflict with the production one.</p><p>Line 12 expects the Stackdriver log line directly from the Stackdriver logging sink. Stackdriver logs published to sink (or Pub/Sub topic) are Base64 encoded. However, our test data is plain text, and Python considers it to be a simple collection. Notice how the testing data is encased in curly braces, “{“ and “}”, with comma separated key-value string pairs. This makes the elements easy to reference, like in line 14.</p><p>8. Once the Cloud Function is created, navigate to the “Testing” sub-tab</p><p>9. Copy paste the contents of prepared_log.sh into the “Triggering event” text box</p><p>10. Click the “Test the function” button</p><p>11. On correct execution, the “Output” should be “OK” and logs should be generated</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*3Xlh0AV7yQRo8Ix5zS7bZA.png" /><figcaption>If the function ingested the test data and executed correctly then it outputs “OK”</figcaption></figure><p>12. The print statement at the end of the Python code will output to Stackdriver log. Print statements that you add, like print(“test_string”), are also output to Stackdriver. On the Stackdriver Logging page, make sure to select the “Cloud Function” filter dropdown resource, and then the Cloud Function name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLIFCXkisJJcYrdys4MWNQ.png" /><figcaption>In Stackdriver Logging, the “Cloud Function” filter dropdown resource takes you to the output</figcaption></figure><p>Hopefully the above debugging methodology will help you troubleshoot your own Cloud Functions. Remember, the key is leaning on Stackdriver to provide you with test data input, and to capture your Cloud Function output. As well print statements can be used for debugging, with their output also captured in Stackdriver.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53f99a7f3cb2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/debugging-serverless-functions-53f99a7f3cb2">Debugging Serverless Functions</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless Computing Made Easy]]></title>
            <link>https://medium.com/google-cloud/serverless-computing-made-easy-40e534ae410e?source=rss-2f9d64752ffd------2</link>
            <guid isPermaLink="false">https://medium.com/p/40e534ae410e</guid>
            <category><![CDATA[cloud-functions]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[stackdriver]]></category>
            <category><![CDATA[monitoring]]></category>
            <dc:creator><![CDATA[Waheed Brown]]></dc:creator>
            <pubDate>Fri, 08 Nov 2019 11:51:01 GMT</pubDate>
            <atom:updated>2019-11-19T23:50:05.382Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ckdxbfVw24k4717w7kaVKQ.jpeg" /><figcaption>Google Cloud Platform Cloud Functions are a convenient way to go serverless</figcaption></figure><p>The Google Cloud Platform (GCP) has a powerful serverless computing feature. Cloud Functions not only allow functional programming on-demand, they can server as cloud-wide event handlers.</p><p>Narrowing our discussion down to a common use-case, we can trigger Cloud Functions from events logged in Stackdriver. In this case, we will use an event which we can easily control; attaching an external IP to a virtual machine. When a static IP change is detected, the affected VM is migrated within the GCP environment. The practical purpose of this is to repair a VM that is failing to register its new static IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QKv4Tay4PBMKpc1wE3_srg.png" /><figcaption>Attaching static external IPs to a VM creates a Stackdriver logging event</figcaption></figure><p>The source code for this blog post is available <a href="https://github.com/waheedbrown/serverless">here on Github</a>. An install script is provided (<a href="https://github.com/waheedbrown/serverless/blob/master/gcloud_script.sh">gcloud_script.sh</a>), along with instructions in the README file. The install script will configure all of the necessary GCP resources for readers to follow along. Please be aware of the Linux shell scripting variables at the beginning of the install script. You need to at least PROJECT_ID to your own GCP project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*CcCt1bjtq3d6u7SnQji0uA.png" /><figcaption>Source code available on Github (<a href="https://github.com/waheedbrown/serverless">click here</a>)</figcaption></figure><p>Looking through the installation script, there are a series of gcloud commands. The application of these commands are useful in general, for a GCP toolkit. Of specific interest are the commands that create the logging sink and the GCP Cloud function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*uXCd_L7IzZOUgScHty5ohw.png" /><figcaption>The logging sink connects Stackdriver to Pub/Sub</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*hCum18QoNigdDIuQ3ivw1Q.png" /><figcaption>The Cloud Function is triggered by the Pub/Sub topic, written to by the logging sink</figcaption></figure><p>The logging sink is what actually wires everything up for the Cloud Function. A Stackdriver log filter captures matching logging entries, in real time. These entries are then captured by the logging sink, which then publishes to the Pub/Sub topic. A deep discussion on Pub/Sub is beyond the scope of this blog post, which is why an installation script is provided. Likewise, the install script creates the Cloud Function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*SbixjaNCqSDpo4zUNup1Wg.png" /><figcaption>The Stackdriver logging sink’s destination is a Pub/Sub topic, visible in the GCP console</figcaption></figure><p>The Cloud Function is a snippet of code that exists on a temporarily available VM resource. This is not a VM that a human user controls, nor is it visible in the GCP console. What is visible is the special Google Cloud App Engine service account that executes the Cloud Function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WqeAaxyjB-nycwHul0Q0gg.png" /><figcaption>The App Engine service account executes Cloud Functions on the user’s behalf</figcaption></figure><p>The body of the Cloud Function is contained in main.py in the Github repository. This name is important as gcloud looks for that specific name, when creating the Cloud Function itself. gcloud also uploads main.py into the Cloud Function workspace in your GCP project. This function is then given the name you assigned it. Although the mechanics of Cloud Function creation are beyond the scope of this article, what is important is the creation syntax. Using the syntax in the install script is a reliable way of creating Cloud Functions. Other methods exist, but they often provide non-descriptive errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*Me4qjh1V26tnBJswiB85uQ.png" /><figcaption>main.py contains the Cloud Function body, in this case written in Python</figcaption></figure><p>Taking a closer look at the Cloud Function body, the most important step is line 8. Here the Cloud Function authenticates against Google Cloud. Since the App Engine service account already has the necessary permissions, this step is parsimonious. By comparison, if we were writing a script to execute outside of a Cloud Function, authentication would require more labor.</p><p>Line 11 accounts for Stackdriver logs being base64 encoded. Line 12 then accounts for Stackdriver logs being kept in JSON format. Lines 15 to 17 access various elements in the JSON tree, with each set of braces representing tree depth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*Vx-RhhF2PeKh6bI9jzvmUA.png" /><figcaption>On the Stackdriver Logging page in Cloud console, click the little triangle and go to advanced filter mode</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*NroAh5kW1hLoobAV_xTcTg.png" /><figcaption>Enter the advanced log filter from the gcloud_script.sh installation file (remove the wrapping quotes)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*HqN4V-_-eI_NDMZXctfUYg.png" /><figcaption>With resource being the JSON root node, labels and project_id are one and two levels deep</figcaption></figure><p>Line 20 in the Cloud Function is what triggers the VM migration.</p><p>Understanding all of this, a static IP can be attached to a VM to trigger the Cloud Function. Two static IPs were created by the gcloud_script.sh installation script, static-ip-1 and static-ip-2. Assigning either to one of the script-created VMs will trigger the Cloud Function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QKv4Tay4PBMKpc1wE3_srg.png" /><figcaption>In the VPC network, External IP addresses section of the GCP console, a static IP can be manually assigned to a VM</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*pDD-RtwpaMVPab5wXnr6Ow.png" /><figcaption>Cloud Function invoked, as shown as a spike on the invocation graph</figcaption></figure><p>Finally, the Cloud Function itself creates a Stackdriver event. This is useful for confirming that the Cloud Function actually worked. A log entry containing “GCE_OPERATION_DONE”, for the App Engine service account will provide this confirmation. For convenience, the Stackdriver logging filters used in this blog post are also in the Github repository.</p><p><strong>NOTE:</strong> There is occasionally a lag between Cloud Function execution and its logging in Stackdriver. If you suspect there’s a legitimate bug, scroll down for a link to the debugging article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*5mkDihNMOdis9hP_PNP_hQ.png" /></figure><p>The next article covers <a href="https://medium.com/google-cloud/debugging-serverless-functions-53f99a7f3cb2">debugging serverless functions</a>, which will empower you to go serverless with confidence.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40e534ae410e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/serverless-computing-made-easy-40e534ae410e">Serverless Computing Made Easy</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Caching Part 2: Google Cloud CDN and Apache]]></title>
            <link>https://medium.com/google-cloud/advanced-caching-part-2-google-cloud-cdn-and-apache-fccf4ca84a9f?source=rss-2f9d64752ffd------2</link>
            <guid isPermaLink="false">https://medium.com/p/fccf4ca84a9f</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[apache]]></category>
            <dc:creator><![CDATA[Waheed Brown]]></dc:creator>
            <pubDate>Wed, 21 Aug 2019 02:13:11 GMT</pubDate>
            <atom:updated>2019-08-21T02:13:11.965Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-FOFFcNLhvPxCq_vPATg5Q.jpeg" /><figcaption>If Google Cloud CDN and Varnish Cache are not enough, then it’s time to DIY</figcaption></figure><p>In part 1, Google Cloud CDN and Varnish, we learned to cache dynamic responses. Here in part 2, we remove Varnish from the picture completely and do it all ourselves. Assuming Google Cloud CDN is up and running, we can use Apache to modify the HTML response before it gets cached.</p><p><strong>1. Apache Module mod_substitute<br></strong>Enable Apache Module <a href="http://httpd.apache.org/docs/2.4/mod/mod_substitute.html">mod_substitute</a> on a Google Compute Engine (GCE) virtual machine (VM)</p><p><em>sudo a2enmod substitute<br>sudo service apache2 restart</em></p><p>NOTE: The above terminal commands are for Ubuntu Linux</p><p><strong>2. Add the desired JavaScript code in a .js file</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*2MN5fBsPnY7vQwU_TDGRpQ.png" /><figcaption>Make a .js file to hold your desired JavaScript code (run on the end users web browser)</figcaption></figure><p><strong>3. Use Apache Substitute to Insert a &lt;script&gt; Tag<br></strong>Apache’s mod_substitute module allows you to write markup rules</p><p><em>vim /etc/apache2/ports.conf</em></p><p>In the ports.conf file, these markup commands let you leverage the Linux substitute command, “s”</p><p>Put the JavaScript file from step 2 inside the script tags</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*IwTWl2emy9uDfYppexBMqQ.png" /><figcaption>Use the Linux substitute command, “s”, to insert a JavaScript file into the HTML response</figcaption></figure><p><strong>4. Make Rules for Different Directories and Files</strong><br>Notice that the above substitution in the &lt;Location&gt; tag<br>The substitution is for all web pages in the web server’s root directory<br>Use additional &lt;Location&gt; tags for specific web directories and files</p><p><strong>5. Response Body Modification Works!</strong><br>The &lt;head&gt; tag in the HTML response was modified by Apache<br>It now includes a &lt;script&gt; tag referencing your JavaScript file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qpg4GF-ybN8wqj0r0VA8GQ.png" /><figcaption>The &lt;head&gt; tag was updated and this modified HTML response will be cached by Google Cloud CDN</figcaption></figure><p>This is a great way to populate dynamic content in a cached web page*</p><p><strong>*NOTE:</strong> Make sure to match your content’s <a href="https://cloud.google.com/cdn/docs/best-practices#setting_the_expiration_for_time-sensitive_content">expiration times</a> with the life cycle of your .js file changes</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fccf4ca84a9f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/advanced-caching-part-2-google-cloud-cdn-and-apache-fccf4ca84a9f">Advanced Caching Part 2: Google Cloud CDN and Apache</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Caching Part 1: Google Cloud CDN and Varnish]]></title>
            <link>https://medium.com/google-cloud/advanced-caching-part-1-google-cloud-cdn-and-varnish-e63d79252367?source=rss-2f9d64752ffd------2</link>
            <guid isPermaLink="false">https://medium.com/p/e63d79252367</guid>
            <category><![CDATA[varnish]]></category>
            <category><![CDATA[reverse-proxy]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[cdn]]></category>
            <dc:creator><![CDATA[Waheed Brown]]></dc:creator>
            <pubDate>Mon, 19 Aug 2019 18:46:02 GMT</pubDate>
            <atom:updated>2019-09-03T19:43:22.109Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oTMExIh5is_3JByFxNeB-g.jpeg" /><figcaption>Google Cloud CDN and Varnish Cache can accelerate your end user experience</figcaption></figure><p><a href="https://cloud.google.com/cdn/">Google Cloud CDN</a> is a lightweight content delivery network solution. It offsets the load from your backend. And of course, it dramatically decreases HTTP response time for your end users. When this is not enough, there is <a href="https://varnish-cache.org/">Varnish Cache</a>.</p><p>This blogpost walks you through implementing Varnish’s advanced caching rules in Google Cloud. This can be done behind the Google Cloud CDN, or completely on its own. It addresses the need of editing the HTML response body, so that the pseudo-dynamic content can be cached.</p><p>Varnish Cache closes the CDN gap with Google Cloud. Varnish allows you to set caching rules declaratively. This is done using a feature called <a href="https://varnish-cache.org/docs/5.2/users-guide/esi.html">Edge Side Includes</a> (ESIs).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*IfE1O9jlk_NDZzbFttPiqA.png" /><figcaption>Edge Side Includes (ESIs) allow editing the HTML response directly on the Varnish cache server</figcaption></figure><p><strong>1. Google Cloud Marketplace<br></strong>Login to your Google Cloud Platform (GCP) console and navigate to the Marketplace</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*g37CTCjvo3GwCstWqwlzbg.png" /><figcaption>Trusted VM images of popular services are in the Google Cloud Marketplace</figcaption></figure><p><strong>2. Select a Varnish Image<br></strong>Select a Varnish Cache image*, to be installed on a Google Compute Engine (GCE) virtual machine (VM)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*KGZpLJoVQAndEAfo2opl8Q.png" /><figcaption>Varnish Cache is a reverse proxy with advanced caching of HTML (and other) responses</figcaption></figure><p><strong>3. Deploy the Image<br></strong>Launching will navigate you to the GCE section of the GCP console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*HYRT5KOF7ClaztZEV4Pj0Q.png" /><figcaption>VM images can be launch directly from the Marketplace onto a GCE instance</figcaption></figure><p><strong>4. Select Machine Type<br></strong>Depending on your use case, you may want to select powerful VM<br>Alternatively, consider manually deploying Varnish in a Google Kubernetes Engine (GKE) cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*FRgs8WAWumrX0vX7QimuuA.png" /><figcaption>For development purposes a single 2-CPU machine was sufficient</figcaption></figure><p><strong>5. The Image Deploys Seamlessly</strong></p><p>The GCP Marketplace image graciously configures the VM and networking ports for you</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0NfRTQ3BZiuNoX6mMWj6BQ.png" /><figcaption>The Varnish image is technically a container, under the hood</figcaption></figure><p><strong>6. Edge Side Includes </strong>(<a href="http://book.varnish-software.com/4.0/chapters/Content_Composition.html#edge-side-includes">link</a>)<strong><br></strong>ESIs allow you to inject content into the response body<br>On the Varnish machine, create web file that has the &lt;esi&gt; tag<br>Here we put PHP in the HTML file, to demonstrate scripting apart from ESI</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*nTch4WVkfz5ydrI5grqj7w.png" /><figcaption>The &lt;esi&gt; tag references a separate HTML file</figcaption></figure><p>Next we create a second web file, which the above &lt;esi&gt; tag references<br>This second file contains JavaScript, which will run in the end user’s browser</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*pf5L6A7J0AGtTVyESXoFcw.png" /><figcaption>The HTML file contains JavaScript to dynamically populate the response</figcaption></figure><p><strong>7. ESI Works in Google Cloud!<br></strong>In the below HTTP response, the PHP code runs on the server<br><strong>However</strong>, the Varnish &lt;esi&gt; tag inserted the JavaScript as desired<br>This HTTP response is thus cached by Varnish<br>Effectively this is caching of a pseudo-dynamic web page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*S9IPeBOm34JgqAyNY6tK1w.png" /><figcaption>Varnish’s ESI service builds the response body, inserting JavaScript, hence caching a pseudo-dynamic response</figcaption></figure><p><strong>Google Cloud CDN Best Practices </strong>(<a href="https://cloud.google.com/cdn/docs/best-practices">link</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*XkJpQdHJgjZDYBOP7AOorg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e63d79252367" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/advanced-caching-part-1-google-cloud-cdn-and-varnish-e63d79252367">Advanced Caching Part 1: Google Cloud CDN and Varnish</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>