<?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 Léo Kling on Medium]]></title>
        <description><![CDATA[Stories by Léo Kling on Medium]]></description>
        <link>https://medium.com/@leokling?source=rss-f8f46b198edd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vhSUMxJqGM1hVMvQEENJ6Q.png</url>
            <title>Stories by Léo Kling on Medium</title>
            <link>https://medium.com/@leokling?source=rss-f8f46b198edd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 04:28:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leokling/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[The One GCP Metric to Rule Them All]]></title>
            <link>https://medium.com/google-cloud/the-one-gcp-metric-to-rule-them-all-203b88f1340d?source=rss-f8f46b198edd------2</link>
            <guid isPermaLink="false">https://medium.com/p/203b88f1340d</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[google-cloud-billing]]></category>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[kill-switch]]></category>
            <category><![CDATA[cloud-metrics]]></category>
            <dc:creator><![CDATA[Léo Kling]]></dc:creator>
            <pubDate>Mon, 04 May 2026 02:40:52 GMT</pubDate>
            <atom:updated>2026-05-04T02:40:52.317Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I’ll show you how to build a simple alerting system around a single Google Cloud metric that can help protect your project and your wallet.</p><p>This approach is ideal for small projects but it can easily be adapted to larger environments.</p><h3>Be proactive</h3><p>I’ll keep saying it, again and again.</p><p>Budget alerts are a must-have. Non-negotiable.</p><p><strong>But</strong></p><p>Cloud Monitoring alerts are just as important, <strong>if not more.</strong></p><p>There’s a common misconception that billing alerts alone are enough to keep your project safe. They’re useful but they are not sufficient on their own.</p><p>You should focus on protecting your project proactively rather than reacting once the damage is already done.</p><h3>Why This Metric Matters</h3><p>If you navigate to <a href="https://console.cloud.google.com/apis/dashboard"><strong>APIs &amp; Services</strong></a> in your GCP project, you’ll find one of the most underrated dashboards in the platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tgQVv4uq2He26Dp57arImA.png" /></figure><p>This page gives you a consolidated view of your project’s API usage. It’s incredibly powerful because you can quickly detect anomalies, unexpected spikes, or even abuse of your services.</p><p>What you’re looking at is called <strong>“Consumed API” metrics</strong>. Every request made to any GCP service is counted here, typically within less than 5 minutes.</p><h3>The Problem with Traditional Alerting</h3><p>You <em>could</em> create an alert for every single API your project uses.</p><p>But,</p><ul><li>It quickly becomes complex</li><li>It doesn’t scale well</li><li>Alerting costs may increase (especially as pricing evolves in 2026)</li></ul><p>This approach can work if you know your project extremely well and are comfortable absorbing the associated costs.</p><p>However, this post is aimed at beginners and anyone who needs a simple reliable starting point.</p><p>So instead, we’ll take an easier approach: <strong>aggregating everything into a single metric.</strong></p><h3>Building the Alerting Policy</h3><p>Go to:</p><p><strong>Cloud Monitoring → Alerting → Create Policy</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v1fkwwFNzu1SmPGZhRxzXw.png" /></figure><p>Then:</p><ol><li>Click <strong>“Select a metric”</strong></li><li>Navigate to:<br> <strong>Consumed API → API → Request Count</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7SO9gZZSzwrYvv-rwZeU6Q.png" /></figure><p>You’ll now see a graph of your API usage (usually set to the last hour).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aOCn8DT9ROcGdmiRv8iwQw.png" /></figure><h3>Aggregating the Data</h3><p>Instead of monitoring each API individually, we’ll combine them.</p><h4>Step 1: Aggregate over time</h4><ul><li>Set <strong>Rolling window</strong> to: 1 day</li><li>Set <strong>Rolling window function</strong> to: sum</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*_IwxibBoJpruobNjj6yeiA.png" /></figure><p>This gives you the total number of requests per service over a day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPNw6Ja9Yxip7T76rNmg8g.png" /></figure><p>From this point, you could create an alert to be notified whenever a single GCP API behaves suspiciously. You could also define one metric per service if you want more granular monitoring.</p><p>However, our goal here is different. We want a single high-level metric to monitor the entire project. To achieve that, we’ll take a more general approach and aggregate everything, ensuring we don’t miss any unusual activity.</p><h4>Step 2: Aggregate across services</h4><ul><li>Under <strong>Across time series</strong>, select: sum</li><li>Do not add a Time series group by, leave it blank</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*lIeI-k8i870VvFUSJjvzLA.png" /></figure><p>Now you have a <strong>single metric representing all API calls across your entire project</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TXAqnauFw5v2Rj-buw8sYw.png" /></figure><p>This is the key idea.</p><h3>Why This Works</h3><p>By aggregating everything:</p><ul><li>You reduce alerting complexity</li><li>You minimize cost (fewer alerting policies)</li><li>You get a high-level “health signal” for your project</li></ul><p>If something unusual happens, this metric will spike.</p><h3>Setting a Threshold</h3><p>Now define your alert condition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wAObsG7C-F0EzHj1G8zB9g.png" /></figure><p>Example:</p><ul><li>My sandbox project usually handles <strong>&lt; 2,000 requests/day</strong></li><li>I set a threshold at <strong>3,000 requests/day</strong></li></ul><p>If this threshold is exceeded, something is likely wrong:</p><ul><li>Misconfiguration</li><li>Abuse</li><li>Unexpected traffic</li></ul><p>Whatever happens, I’ll be notified.</p><h3>Notifications</h3><p>Choose how you want to be notified by configuring a <a href="https://docs.cloud.google.com/monitoring/support/notification-options">Notification Channel</a>.</p><p>For a simple setup, email is enough.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*d03pbiaxE1aSDSTbIrxWeg.png" /></figure><p>Make sure to:</p><ul><li>Give your alert a <strong>clear and meaningful name</strong></li><li>Double-check your notification channel</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*Nf2NgMFhySHsljb4PVVRZg.png" /></figure><p>Then click <strong>“Create Policy”</strong>.</p><h3>What You’ve Built</h3><p>You now have:</p><ul><li>A <strong>single, aggregated metric</strong></li><li>A <strong>cost-efficient alerting strategy</strong></li><li>A <strong>basic protection layer against unexpected usage</strong></li></ul><p>This is a simple but powerful safeguard for any GCP project.</p><p>Did an API key get leaked? Is Firestore being DDoS’d or Vertex AI Gemini being abused? You’ll know within 5 minutes</p><h3>Going Further</h3><p>You can extend this setup by:</p><ul><li>Creating multiple thresholds (warning vs critical)</li><li>Using different notification channels for escalation</li><li>Segmenting by environment (prod vs dev)</li></ul><p>If you want to go even further, I’ve also written a tutorial on how to build a <a href="https://medium.com/google-cloud/building-a-faster-gcp-kill-switch-leveraging-cloud-monitoring-instead-of-billing-data-a9e2eab2099b">Cloud Monitoring–based kill switch</a> that can shut things down quickly in case of abuse.</p><p>You can easily adapt that approach using this single aggregated metric, making it a simple yet highly effective safeguard for your project.</p><h3>Final Thoughts</h3><p>This setup is intentionally simple, and that’s exactly its strength.</p><p>That said, the alert is not adaptive, so it needs to be reviewed and adjusted regularly if needed.</p><p>I wouldn’t hesitate to define multiple alerts with different thresholds or time windows. In fact, it can also make sense to keep the threshold relatively high.</p><p>For example, allowing up to 10k requests per day can significantly reduce the risk of abuse while still leaving enough headroom for your project to operate normally.</p><p>Know that in cloud environments, <strong>paranoia is a skill.</strong></p><p>It’s better to have <strong>too much </strong>protection than <strong>not enough</strong>.</p><p>Start with one metric.<br>Make it reliable.<br>Then build from there.</p><p>Also, while writing this, I can’t help but think that GCP should add anomaly detection to this specific metric, similar to what they already do with Cloud Billing.</p><p>It would be incredibly useful to get notified when project usage suddenly spikes by 200% or more. What do you think ?</p><p>Anyways, thanks for you time and <strong>Happy Hacking ☁️</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=203b88f1340d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/the-one-gcp-metric-to-rule-them-all-203b88f1340d">The One GCP Metric to Rule Them All</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[How to Fix “Must Be Owner of Relation” When Using PostgreSQL Triggers in n8n]]></title>
            <link>https://medium.com/@leokling/how-to-fix-must-be-owner-of-relation-when-using-postgresql-triggers-in-n8n-fd114c9ce832?source=rss-f8f46b198edd------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd114c9ce832</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[n8n]]></category>
            <dc:creator><![CDATA[Léo Kling]]></dc:creator>
            <pubDate>Thu, 12 Mar 2026 17:01:01 GMT</pubDate>
            <atom:updated>2026-03-12T17:01:01.670Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, we tried to set up a simple n8n workflow using <strong>Postgres Triggers</strong>, like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*UD1Vx0ci67q3EoUy3WI8-w.png" /><figcaption>Postgres Triggers Node on n8n</figcaption></figure><p>Everything seemed to work fine but it was impossible to <strong>enable the workflow</strong> because of the following error message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*LxgBklH3Uyulszc2-MattQ.png" /><figcaption>n8n error when enabling the workflow</figcaption></figure><p>After several web searches, it appears that this has been a common issue for quite some time. Of course, you could grant the SQL user ownership of the table but this may not be appropriate in many situations.</p><p>So, if you <strong>do not want to set another user as the table/relation owner</strong>, the only way to bypass this limitation is to create the <strong>channel yourself</strong>, exactly the way n8n would do it anyway. Fortunately, it’s actually quite simple.</p><h3>Before you go</h3><p>In this example, I will show you how to create a trigger/channel for the user n8n_user, while being connected as an admin.</p><p>Before doing anything, decide the name of each object:</p><ul><li>Trigger Name</li><li>Function Name</li><li>Channel Name</li></ul><p>All of them should be <strong>clear and descriptive</strong>, so their purpose is immediately understandable. This helps avoid accidental deletion by someone who might otherwise consider them suspicious or unnecessary.</p><p>For this example, we will use the following naming:</p><ul><li><strong>Trigger Name</strong> → n8n_trigger_for_xxx</li><li><strong>Function Name</strong> → n8n_trigger_function_for_xxx</li><li><strong>Channel Name</strong> → n8n_channel_for_xxx</li><li><strong>Target Table (“relation”)</strong> → MY_TABLE</li><li><strong>SQL User</strong> → n8n_user</li></ul><h3>Create a Function</h3><pre>-- FUNCTION: public.n8n_trigger_function_for_xxx()<br><br>-- DROP FUNCTION IF EXISTS public.n8n_trigger_function_for_xxx();<br><br>CREATE OR REPLACE FUNCTION public.n8n_trigger_function_for_xxx()<br>    RETURNS trigger<br>    LANGUAGE &#39;plpgsql&#39;<br>    COST 100<br>    VOLATILE NOT LEAKPROOF<br>AS $BODY$<br> begin perform pg_notify(&#39;n8n_channel_for_xxx&#39;, row_to_json(new)::text); return null; end; <br>$BODY$;<br><br>ALTER FUNCTION public.n8n_trigger_function_for_xxx()<br>    OWNER TO n8n_user;</pre><h3>Create a Trigger</h3><p>Note that this trigger works only on <strong>INSERT</strong> operations.</p><pre>-- Trigger: n8n_trigger_for_xxx<br><br>-- DROP TRIGGER IF EXISTS n8n_trigger_for_xxx ON public.MY_TABLE;<br><br>CREATE OR REPLACE TRIGGER n8n_trigger_for_xxx<br>    AFTER INSERT -- Trigger after INSERT<br>    ON public.MY_TABLE<br>    FOR EACH ROW<br>    EXECUTE FUNCTION public.n8n_trigger_function_for_xxx();</pre><p>Triggers can be widely customized according to the <a href="https://www.postgresql.org/docs/current/sql-createtrigger.html">documentation</a>.</p><h3>Add Channel to n8n</h3><p>Go back to n8n, open the <strong>Postgres Trigger</strong> node, and select <strong>Advanced</strong> in the <strong>Listen For</strong> field. Then enter your <strong>Channel Name</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*7qxZtSpgE7P4yU5QPSma1A.png" /></figure><p>Click <strong>Execute Step</strong> to initialize the channel listening. You can also test it immediately.</p><h3>Check Channel</h3><pre>SELECT pid, query<br>FROM pg_stat_activity<br>WHERE query LIKE &#39;LISTEN%&#39;;</pre><p>You should now see it appear, which means it works!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/1*VOZqfhN_9o0pwz1A8OAzOw.png" /></figure><p>Hote this helps !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd114c9ce832" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fix Vertex AI 404 Model Not Found Error]]></title>
            <link>https://medium.com/google-cloud/fix-vertex-ai-404-model-not-found-error-166aec303d99?source=rss-f8f46b198edd------2</link>
            <guid isPermaLink="false">https://medium.com/p/166aec303d99</guid>
            <dc:creator><![CDATA[Léo Kling]]></dc:creator>
            <pubDate>Thu, 05 Mar 2026 01:20:42 GMT</pubDate>
            <atom:updated>2026-03-05T01:20:42.139Z</atom:updated>
            <content:encoded><![CDATA[<p>Getting a 404 Model Not Found error when calling Vertex AI or Gemini can be frustrating, especially when your code looks perfectly fine.</p><p>In most cases, the issue isn’t your implementation. The model may be unavailable in your region, deprecated, or your project might be missing the right permissions.</p><p>In this guide, we’ll quickly break down why this happens and how to fix it in minutes.</p><h3>Symptoms</h3><ol><li>Calling the Vertex AI or Gemini API results in a <strong>404 Not Found</strong> error.</li><li>The error message looks like this:</li></ol><pre>GoogleApiError: Publisher Model <br>`projects/[GCP_PROJECT]/locations/[GCP_LOCATION]/publishers/google/models/gemini-1.0-pro`<br>was not found or your project does not have access to it.</pre><p>Note: [GCP_PROJECT] and [GCP_LOCATION] vary depending on your configuration.</p><p>In this example, I’m using gemini-1.0-pro, but the same applies to any relevant model. I’ll explain why in a moment.</p><h3>Why It Happens and How to Fix It</h3><p>A 404 error usually means that the model you’re trying to use either <strong>doesn’t exist in that region</strong>, <strong>was deprecated</strong>, or <strong>your project doesn’t have access</strong>.</p><h3>Check the Official Models List</h3><p>Visit the <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/models">Google Models List</a>:</p><ul><li>Confirm the <strong>model ID</strong> you’re using (ex: gemini-2.5-pro).</li><li>Verify the <strong>supported regions</strong> for that model.</li><li>If you’re using an unavailable model or region, Vertex AI will return a 404.</li></ul><h3>Verify That the Model Isn’t Retired</h3><p>See the <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/learn/model-versions#expandable-1">Retired Models List</a>:</p><ul><li>If the model is listed here, it’s no longer accessible.</li><li>Update your code to use the latest supported version.</li></ul><h3>Check Permissions</h3><p>Make sure your account / service account has the proper IAM role:</p><ul><li>Required role: <strong>Vertex AI User</strong> (roles/aiplatform.user)</li><li>This is needed to <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart#console-experiences">run prompts in Vertex AI Studio</a>.</li></ul><p>Without this permission, your project won’t be able to access Vertex AI models even if they exist.</p><h3>Inspecting a Model Page</h3><p>Let’s look at a real example: <strong>Gemini 2.5 Pro</strong> (as of November 2, 2025).</p><ul><li><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/models/gemini/2-5-pro">Gemini 2.5 Pro Model Page</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/0*oaRsUos1fEb5HFZO.png" /></figure><p>Here you can see that the <strong>Model ID</strong> is gemini-2.5-pro. That’s exactly what you must use in your API calls / code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/0*ZYa9dkBmHgoDrGB4.png" /></figure><p>These are the <strong>supported regions</strong> for gemini-2.5-pro. If you try to call the model from an unsupported region, you’ll get a 404.</p><h3>TL;DR</h3><p>Here is the list of possible causes and fixes:</p><p>Cause : Wrong Model ID<br>Fix: Use a valid one from the <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/models">Official List</a></p><p>Cause: Model Retired<br>Fix: Stop using <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/learn/model-versions#expandable-1">Retired Models</a></p><p>Cause: Unsupported Region<br>Fix: Use a supported region</p><p>Cause: Missing Permissions<br>Fix: Add roles/aiplatform.user to your IAM setup</p><p>Last but not least, you should take a look at the page <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/migrate#which-model">Which Gemini model should I migrate to</a> to help you choose the upgraded model that best fits your needs.</p><p>By then, you should be good. 🫡</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=166aec303d99" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/fix-vertex-ai-404-model-not-found-error-166aec303d99">Fix Vertex AI 404 Model Not Found Error</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[Fix Unexpected Cloud Spanner Charges]]></title>
            <link>https://medium.com/google-cloud/fix-unexpected-cloud-spanner-charges-1eb31a5fdab7?source=rss-f8f46b198edd------2</link>
            <guid isPermaLink="false">https://medium.com/p/1eb31a5fdab7</guid>
            <category><![CDATA[google-spanner]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cloud-spanner]]></category>
            <category><![CDATA[cloud-cost-management]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Léo Kling]]></dc:creator>
            <pubDate>Fri, 27 Feb 2026 08:49:34 GMT</pubDate>
            <atom:updated>2026-02-27T08:49:34.339Z</atom:updated>
            <content:encoded><![CDATA[<p>With the rapid growth of AI services on Google Cloud, unexpected charges can sometimes appear on your billing report. If you’re seeing Cloud Spanner costs despite never creating an instance, the cause is likely an AI feature running behind the scenes. In this article, we’ll explain why this happens and how to stop it.</p><h3>Symptoms</h3><ol><li>You don’t have any Cloud Spanner instances.</li><li>You may not even have the Cloud Spanner API enabled.</li><li>Yet, your <strong>billing report looks like this</strong>:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Fjl1X_VRlI8L-56S.png" /></figure><h3>Why Are You Charged for Cloud Spanner?</h3><p>You’re likely using the <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/rag-engine/rag-overview">Vertex AI RAG Engine</a>.</p><p>As mentioned in the <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/rag-engine/rag-engine-billing">official billing documentation</a>:</p><blockquote><em>A RAG-managed database uses a Spanner instance as the backend.</em></blockquote><p>This means that even if you didn’t explicitly create a Cloud Spanner instance, <strong>Vertex AI RAG Engine automatically provisions and uses one</strong> under the hood.</p><p>The RAG Engine is automatically enabled when you create or manage a <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/rag-engine/manage-your-rag-corpus#corpus-management">corpus</a>.</p><h3>Before You Act</h3><p>Before you proceed, note that:</p><ul><li>Disabling your RAG Engine will delete <strong>all your corpora.</strong></li><li><strong>RAG Engines are region-specific.</strong> Deleting it from europe-west1 will not remove it from us-central1, and vice versa.</li></ul><h3>Disabling RAG Engine</h3><ol><li>Open GCP <a href="https://console.cloud.google.com/vertex-ai/rag/corpus">RAG Engine</a>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8gPplaFNMqhA3ktR.png" /></figure><p><em>You may see one or more corpora here, no need to delete them manually as they’ll be removed when you delete the RAG Engine.</em></p><ol><li>Click <strong>Configure RAG Engine</strong>.</li><li>Select <strong>Delete RAG Engine</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KQ7nLFDzgxekpHL1.png" /></figure><ol><li>Type delete to confirm and finalize the deletion.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/0*ISk7zI_XBdrAWfJi.png" /></figure><p>And that’s it! Allow 24–48 hours for the Billing Report to refresh, and your next Cloud Spanner charge should be significantly lower or possibly even nonexistent.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1eb31a5fdab7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/fix-unexpected-cloud-spanner-charges-1eb31a5fdab7">Fix Unexpected Cloud Spanner Charges</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[Fix White Camera Output in Google Meet on Linux Wayland]]></title>
            <link>https://medium.com/@leokling/fix-white-camera-output-in-google-meet-on-linux-wayland-7751a3a7d9bf?source=rss-f8f46b198edd------2</link>
            <guid isPermaLink="false">https://medium.com/p/7751a3a7d9bf</guid>
            <category><![CDATA[x11]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[wayland]]></category>
            <category><![CDATA[chrome]]></category>
            <dc:creator><![CDATA[Léo Kling]]></dc:creator>
            <pubDate>Thu, 26 Feb 2026 08:11:48 GMT</pubDate>
            <atom:updated>2026-02-26T08:11:48.874Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6iBmTw2b55T1K1OD.png" /><figcaption>White Camera on Google Meet :(</figcaption></figure><p>This guide presents a solution that resolved the issue on <strong>my system</strong>. However, white camera output in Google Meet on Wayland can stem from various causes, so other users may find different workarounds effective.</p><p>After switching from X11 to Wayland, I encountered a white camera feed in Google Meet on Chrome-based browsers. This guide shows how to resolve it. The fix has been tested on Brave Nightly and works across all Chromium-based browsers.</p><p>Per my understanding, the issue is related to NVIDIA under Wayland and not a bug in Chrome itself.</p><h3>Solution Overview</h3><p>This guide shows how to wrap your browser with a custom .desktop file that includes the necessary flag to fix the camera issue. By creating a wrapper, you preserve the configuration across browser updates. This method works with any Chrome-based browser, regardless of installation method (apt, snap, flatpak, etc.).</p><h3>Verify Your Display Server</h3><p>Check that you’re running Wayland:</p><pre>echo $XDG_SESSION_TYPE</pre><p>If the output is wayland, this guide applies to you.</p><h3>Locate Your Browser</h3><p>For this example, we’ll use Chromium:</p><pre>which chromium-browser</pre><p>Output:</p><pre>/usr/bin/chromium-browser</pre><h3>Create a Custom Desktop File</h3><p>Create a new .desktop file:</p><pre>touch ~/.local/share/applications/chromium-wayland.desktop</pre><p>Edit the file with the following content:</p><pre>[Desktop Entry]<br>Name=Chromium (Wayland)<br>Exec=/usr/bin/chromium-browser --disable-gpu-compositing %U<br>Terminal=false<br>Type=Application<br>Icon=chromium-browser<br>Categories=Network;WebBrowser;<br>StartupWMClass=Chromium-browser</pre><p>The --disable-gpu-compositing flag fixes the white camera issue.</p><p>You can change the Exec line by whatever method you want.</p><p>The StartupWMClass should match your browser’s window class name.</p><p>The browser will now appear as “Chromium (Wayland)” in your application menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/182/0*WOlijhQFDNPrJSfm.png" /></figure><h3>Flatpak</h3><p>If you installed your browser via Flatpak, flags should be passed by editing a flags configuration file:</p><pre>cd ~/.var/app/com.chromium.Chromium/config<br>nano chromium-flags.conf</pre><p>Note that the path may differ based on your browser. For example, for Brave, it would be:</p><pre>cd ~/.var/app/com.brave.Browser/config<br>nano brave-flags.conf</pre><p>Then add the following line:</p><pre>--disable-gpu-compositing</pre><h3>Testing</h3><p>Your camera should now display correctly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*piCUD-U6JnS_ykPn.png" /></figure><h3>Terminal Usage</h3><p>If launching from the terminal, add the same flag:</p><pre>chromium-browser --disable-gpu-compositing</pre><p>This silences GPU-related errors like:</p><pre>[32732:32732:0218/174012.509711:ERROR:gpu/command_buffer/service/shared_image/shared_image_manager.cc:259]<br>SharedImageManager::ProduceSkia:<br>Trying to produce a Skia representation from an incompatible backing: OzoneImageBacking</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7751a3a7d9bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Manage Multiple Git Configurations on a Single Machine]]></title>
            <link>https://medium.com/@leokling/how-to-manage-multiple-git-configurations-on-a-single-machine-80e4182f74b2?source=rss-f8f46b198edd------2</link>
            <guid isPermaLink="false">https://medium.com/p/80e4182f74b2</guid>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Léo Kling]]></dc:creator>
            <pubDate>Wed, 25 Feb 2026 19:44:21 GMT</pubDate>
            <atom:updated>2026-02-25T19:58:27.340Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rUlgvx2lPUVEF8I9g7hRmQ.png" /><figcaption>Separate Personal and Professional Git Configurations</figcaption></figure><p>Since I use the same computer for both personal and professional work, I need to separate my Git configuration. I use GitHub for my personal projects and GitLab for professional ones, so keeping things clean is essential.</p><p>This guide explains how to manage two Git environments on a single machine, so you no longer have to worry about which configuration is being used depending on the folder you’re working in. No more pushing to production with your personal account by mistake.</p><p>I’m assuming you’re working on a Linux environment.</p><h3>Update your global .gitconfig</h3><p>First, open (or create) your global Git configuration file:</p><pre>nano ~/.gitconfig</pre><p>Then add the following content:</p><pre>[includeIf &quot;gitdir:~/projects/professional/&quot;]<br>    path = ~/.gitconfig-professional<br><br>[includeIf &quot;gitdir:~/projects/personal/&quot;]<br>    path = ~/.gitconfig-personal</pre><p>You can change the parent folders to match your own structure. In this example, I’m using ~/projects/professional and ~/projects/personnal, but you can name them however you like.</p><p>With this configuration:</p><ul><li>Everything under ~/projects/professional will use the professional Git configuration.</li><li>Everything under ~/projects/personal will use the personal Git configuration.</li></ul><h3>Create the professional configuration</h3><p>Now create the professional config file:</p><pre>nano ~/.gitconfig-professional</pre><p>Add:</p><pre>[user]<br>    name = FirstName LastName<br>    email = your_pro_email@domain.com</pre><h3>Create the personal configuration</h3><p>Then create the personal config file:</p><pre>nano ~/.gitconfig-personal</pre><p>Add:</p><pre>[user]<br>    name = FirstName LastName<br>    email = your_personal_email@domain.com</pre><h3>That’s it</h3><p>Git will automatically return the correct email address based on the directory you’re in:</p><pre>cd ~/projects/personal<br>git config user.email # -&gt; Personal email<br><br>cd ~/projects/professional<br>git config user.email # -&gt; Professional email</pre><p>No more confusion. No more accidental pushes with the wrong account.</p><p>You can fully customize each environment to suit your needs and even add additional configurations if required.</p><p>For more details, you can refer to the <a href="https://git-scm.com/docs/git-config">Official Git Configuration</a> documentation. However, it can be quite verbose, so searching directly on Google for specific settings might save you time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80e4182f74b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Faster GCP Kill Switch: Leveraging Cloud Monitoring Instead of Billing Data]]></title>
            <link>https://medium.com/google-cloud/building-a-faster-gcp-kill-switch-leveraging-cloud-monitoring-instead-of-billing-data-a9e2eab2099b?source=rss-f8f46b198edd------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9e2eab2099b</guid>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[cloud-monitoring]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Léo Kling]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 17:22:08 GMT</pubDate>
            <atom:updated>2026-02-17T17:22:08.880Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In 10 years in IT and tech, I’ve had the opportunity to see what it’s like to work both with and without the cloud and let’s just say, I would never go back.</p><p>That said, people are still debating why GCP, and other providers, don’t offer a native kill switch. This has been a recurring topic for years. A quick look at the top posts on <a href="https://www.reddit.com/r/googlecloud/">r/googlecloud</a> shows that many of them focus on unexpected costs and money lost due to uncontrolled resource usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*sIbEVkEz2tkMSA6WZkxCJw.png" /><figcaption>Top r/googlecloud submissions as of February 2026</figcaption></figure><p>This article focuses on billing-oriented protection.<strong> By no means am I suggesting that this alone is sufficient to fully secure your project.</strong> The Cloud is a completely different paradigm compared to on-premise environments and it’s important to understand those differences.</p><p>In this article, I’ll explain how GCP billing works, why budget alerts are helpful but not sufficient, and how to overcome their limitations by leveraging Cloud Metrics.</p><p>This is primarily aimed at people who are learning about the Cloud. I assume, and hope, that experienced Cloud Engineers are already securing their projects with the appropriate services and best practices.</p><h3>Limit of GCP Budget Alert</h3><p>It has been years since Google published an <a href="https://docs.cloud.google.com/billing/docs/how-to/disable-billing-with-notifications">official guide on disabling billing through notifications</a>. The mechanism itself is relatively simple, and many people have done a great job simplifying its deployment.</p><p>What concerns me is that this approach is often presented as the right and sometimes the only way to protect yourself from a “Denial of Wallet” (<em>Billing Bomb</em>).</p><p>That assumption is not only <strong>incorrect</strong>, it’s <strong>dangerous</strong>.</p><p>I’m not sure everyone promoting this method fully realizes that Google clearly states throughout the documentation that Cloud Billing data and Budget Alerts are subject to delays.</p><p>Just take a look at <a href="https://docs.cloud.google.com/billing/docs/how-to/disable-billing-with-notifications#limitations">these lines</a> from the official GCP documentation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*MRCmYc7K8RkWS3Dq3g3RvQ.png" /><figcaption>Known limitation of Disabling Billing with Budget Alert</figcaption></figure><p>Here’s a <strong>very exaggerated</strong> graphic for you to understand:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KPbBd9Lb-8tr3TlFMZVghA.png" /><figcaption>A very exaggerated view of billing delay</figcaption></figure><p>From my experience, it’s rare but it does happen to have a significant delays before billing data is fully up to date. As stated in the documentation about <a href="https://docs.cloud.google.com/billing/docs/how-to/resolve-issues#missing-transactions">Missing Cloud Billing transactions or documents</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*PumUNzVPsBm6ERq44NYWdg.png" /><figcaption>Note about GCP billing delay</figcaption></figure><p>In a secure environment, budget alerts are a valuable addition, but experienced cloud engineers would not rely on them alone. Don’t get me wrong, they are mandatory, just not sufficient.</p><p>Here’s some example where Budget Alert were not sufficient:</p><ul><li><a href="https://www.reddit.com/r/googlecloud/comments/1l38nce/comment/mvyxkpi/">Example n°1</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/0*X3NdQvX_kwz_KW1n" /></figure><ul><li><a href="https://www.reddit.com/r/googlecloud/comments/1jz43y6/056_to_34315_in_minutes_google_gemini_api_just/">Example n°2</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/1*8jfPQR7Dhk2DNbLZV3RWrg.png" /></figure><p>Unfortunately, there are far more than just two examples.</p><p>My point here is to demonstrate that budget alerts are inherently limited due to reporting delays. In many cases, people simply don’t react quickly enough and/or they fail to protect their projects with the appropriate tools and safeguards.</p><p>Basing a Kill Switch on budget alerts is a smart approach as it can effectively stop spending when usage increases steadily and eventually reaches your defined budget. However, it won’t protect you against sudden, uncontrolled bursts of consumption.</p><h3>Firestore Document Writes Use Case</h3><p>From there, let’s imagine we’re working on a group project.</p><p>Suppose we have a Firestore database connected to our mobile application.</p><p>We’re a group of enthusiastic but not very security-conscious students, and we haven’t paid enough attention to properly securing our app.</p><p>By using App Check, we’re assuming that we’re safe.</p><p>Unfortunately, we’re not.</p><p>A malicious individual decided to target us, seemingly with nothing better to do. They automated our application to send thousands of requests per second, all of which were validated by App Check.</p><p>In total, 500 million write requests were executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*mlmeAKEjiVrTSZaqVlh-oQ.png" /><figcaption>500 million write requests to Firestore estimated cost according to the Cloud Pricing Calculator</figcaption></figure><p>Around $27,000 in charges were incurred for our project. A Kill Switch based on budget alerts might have mitigated the cost slightly, but when a burst is this sudden and severe, the damage is done before any alert can react.</p><p>Once again, <strong>securing your application before exposing it to the public is absolutely critical.</strong></p><h3>Dealing with the delay</h3><p>As we saw, Budget Alert are great for linear and controlled consumption. So a Kill Switch based on Budget Alert only may suffer the same problem linked to this delay. So, what to do with such delay ?</p><p>Here comes <a href="https://docs.cloud.google.com/monitoring/api/metrics_gcp">Cloud Metrics</a>.</p><p>To me, this is something terribly overlooked, especially by neophytes.</p><p>Metrics (Alerts) are just as important, if not more so, than Budget Alerts.</p><p><strong>Why would you monitor your project’s expenses but not its activities?</strong></p><p>That has always struck me as odd. Metrics represent the activities on your project, the very things driving costs. <strong>A surge in activity always leads to a surge in expenses.</strong></p><p>What’s even more frustrating is that most metrics <strong>take only 5 minutes to update</strong>.</p><p>So really, what’s more important, knowing that your project has already hit its budget, or preventing abnormal consumption that could make your budget explode?</p><p>The answer is simple: <strong>both are essential</strong>.</p><p>Monitoring expenses alone is not enough, monitoring activities is just as mandatory.</p><p>The downside is that Cloud Metrics aren’t as general as Budget Alerts. With a Budget Alert, you just set your budget and let it run. With Metrics, you need to dig into the details and specify exactly what you want to track.</p><p>The purpose of a “Kill Switch” is to stop your project’s spending immediately once the budget is reached, without considering the underlying cause. I think this is at the heart of the ongoing debate about GCP not having a kill switch.</p><p>It’s a grey area. Many people want the cloud to be responsive and flexible but should you really use such a powerful tool without understanding what’s happening under the hood?</p><p>As I said earlier, I won’t dwell too long on this debate, it’s not the focus here. Instead, let’s explore how you can <strong>fortify your billing strategy beyond the standard Budget Alert</strong>.</p><h3>Cloud Metrics as Prevention</h3><p>Let’s see what would have happened if we had used Cloud Metrics in addition to the Budget Alert. For this test, we expect around 1,000 documents to be written per day, with any higher number considered potentially suspicious.</p><p>Based on <a href="https://docs.cloud.google.com/monitoring/api/metrics_gcp_d_h#gcp-firestore">Firestore Metrics</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*S4Ap2KvY-UBz18pgklDH_A.png" /><figcaption>Firestore Document Write Metrics</figcaption></figure><p>You can see that this metric is updated every 240s (5 minutes).</p><p>Let’s create an <a href="https://docs.cloud.google.com/monitoring/alerts">Alert Policy</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P1yw1Bmw_9ThWHVYj9RVMA.png" /></figure><p>Let’s set the metric to <em>Firestore Instance — Document Writes.</em></p><p>Set the Rolling Window to 1 day and the Rolling Window Function to sum, since any day with more than 1,000 requests will be considered suspicious.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*MkeNEuwmCbS3BbUB1qbqSw.png" /></figure><p>Then we set the limit under <em>“Any time series violates the above threshold”</em> with a threshold value of 1,000. This means that if any time series exceeds 1,000 requests within a 1 day rolling window, the alarm will be triggered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*xwn-c3MH10BBv2Btv6AzmQ.png" /></figure><p>You will be asked to use a <a href="https://docs.cloud.google.com/monitoring/support/notification-options">Notification Channel</a>. I strongly recommend setting one up beforehand, as you won’t be able to know if anything happens without it. Also, note that you can choose multiple notification channels for the same policy (email, SMS, Slack, etc.).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*MSNYKRAIcv1SoEc2LEPFjQ.png" /></figure><p>And there it is, our custom monitoring metric for Firestore Document Writes!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m3KPAp12qBLSJ3YRQ7xxpg.png" /></figure><p>Let’s generate some activity using a Bash script to send 1,000 write requests. The script is scheduled to run at 8:05 PM:</p><pre>GCP_PROJECT_ID=YOUR_PROJECT_ID<br>FIRESTORE_TEST_DB=YOUR_FIRESTORE_DB<br>CLOUD_TOKEN=$(gcloud auth print-access-token)<br>TOTAL_DOCS=1000<br><br>echo &quot;Step 1/3: Creating $TOTAL_DOCS documents...&quot;<br>for i in $(seq 1 $TOTAL_DOCS); do<br>  curl -sS -X POST -H &quot;Authorization: Bearer $CLOUD_TOKEN&quot; \<br>       -H &quot;Content-Type: application/json&quot; \<br>       --data &quot;{\&quot;fields\&quot;: {\&quot;val\&quot;: {\&quot;integerValue\&quot;: \&quot;$i\&quot;}}}&quot; \<br>       &quot;https://firestore.googleapis.com/v1/projects/${GCP_PROJECT_ID}/databases/${FIRESTORE_TEST_DB}/documents/${FIRESTORE_TEST_DB}?documentId=doc_$i&quot; \<br>       -o /dev/null &amp;<br>  if [[ $((i % BATCH_SIZE)) -eq 0 ]]; then<br>    wait<br>    percent=$(( i * 100 / TOTAL_DOCS ))<br>    printf &quot;\r[CREATE] Progress: [%-20s] %d%% (%d/%d)&quot; &quot;$(printf &#39;#%.0s&#39; $(seq 1 $((i/50))))&quot; &quot;$percent&quot; &quot;$i&quot; &quot;$TOTAL_DOCS&quot;<br>  fi<br>done<br>wait<br>echo &quot;\nCreation completed.\n&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*6W3SAE4ZIOYgrwjpywfeaQ.png" /><figcaption>Script Result (ignore the color)</figcaption></figure><p>At 8:10pm, the Alert Policy looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ITZD0e2C2KcrzybLEURtBg.png" /><figcaption>Cloud Monitoring Result after 5 minutes</figcaption></figure><p>It only took 5 minutes for the metric to appear in Cloud Metrics.</p><p>Since the alert only triggers when the threshold is exceeded, I added more documents writes at 8:33 PM. Here’s what I observed 5 minutes later:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TsCt8C-z69sp34bnY912Ew.png" /></figure><p>Quickly, my email, set up in the Notification Channel, alerted me that my Firestore write activity had exceeded expectations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*eEK7oMVkKVSZ_a9vfk52Cw.png" /></figure><p>Here, we see that Cloud Metrics are much faster than Budget Alert / Billing API but there are some downsides to this approach:</p><ul><li>It’s not general-purpose, you need to decide in advance what to monitor.</li><li>Relying solely on metrics to trigger a Kill Switch can be too drastic.</li><li>If your project is compromised in an area that isn’t being monitored, it will go unnoticed.</li></ul><p>That said, being non-generalist may not be a real downside. You might have different projects for different purposes, so you’re not managing a massive number of services simultaneously. Segregation is key.</p><p>Regarding the second and third points, is that really an issue? I understand the appeal of a generalist approach, but it’s not rigorous to rely solely on that.</p><p>You wouldn’t expect to have a bike accident only because of a frontal collision. The road can split, conditions can change, and you stay cautious about every potential risk you’re exposed to. It’s pretty much the same here.</p><h3>Cloud Metrics based Kill Switch</h3><p>We will reuse the Budget Alert implementation pattern, adapting it to trigger based on <strong>Cloud Monitoring metrics</strong> instead of budget thresholds.</p><p><strong>Architecture overview:</strong><br>Alert Policy → Pub/Sub → Eventarc → Cloud Run (Kill Switch)</p><p>We will proceed with the following steps:</p><ol><li>Create a Pub/Sub topic named alert-policy-topic</li><li>Grant the default Notification Channel service account the <strong>Pub/Sub Publisher</strong> role on this topic</li></ol><p>Below is an environment-agnostic script that gathers all required information and provisions the necessary resources automatically:</p><pre># Get the project info<br>PROJECT_NUMBER=$(gcloud projects describe $(gcloud config get-value project) --format=&#39;value(projectNumber)&#39;)<br>PROJECT_ID=$(gcloud config get-value project)<br>TOPIC_NAME=&quot;alert-policy-topic&quot;<br><br># Enable required APIs<br>gcloud services enable monitoring.googleapis.com<br>gcloud services enable pubsub.googleapis.com<br><br># Create the topic<br>gcloud pubsub topics create ${TOPIC_NAME}<br><br># Add IAM policy binding<br>gcloud pubsub topics add-iam-policy-binding ${TOPIC_NAME} \<br>    --member=&quot;serviceAccount:service-${PROJECT_NUMBER}@gcp-sa-monitoring-notification.iam.gserviceaccount.com&quot; \<br>    --role=&quot;roles/pubsub.publisher&quot;<br><br># Create monitoring channel<br>gcloud alpha monitoring channels create \<br>    --display-name=&quot;Alert Policy Channel&quot; \<br>    --type=pubsub \<br>    --channel-labels=topic=projects/${PROJECT_ID}/topics/${TOPIC_NAME}</pre><p>We will need Eventarc and all the required Cloud Run and Cloud Functions components to enable communication across the entire architecture.</p><p>First, we need to enable a couple more APIs:</p><pre>gcloud services enable artifactregistry.googleapis.com<br>gcloud services enable cloudbuild.googleapis.com<br>gcloud services enable run.googleapis.com<br>gcloud services enable cloudfunctions.googleapis.com</pre><p>Next, we will start by creating a mock Kill Switch Cloud Function. This function will allow us to inspect the payload received in the POST request triggered by Eventarc from Pub/Sub.</p><p>Create main.py</p><pre>import functions_framework<br>from flask import Request<br>import base64<br>import json<br><br>@functions_framework.http<br>def show_post_body(request: Request):<br>    &quot;&quot;&quot;A simple HTTP Cloud Function that prints the request body and headers.&quot;&quot;&quot;<br>    try:<br>        body_json = request.get_json(silent=True)<br>        if body_json and &quot;message&quot; in body_json:<br>            encoded_data = body_json[&quot;message&quot;].get(&quot;data&quot;)<br>            if encoded_data:<br>                decoded_data = base64.b64decode(encoded_data).decode(&#39;utf-8&#39;)<br>                incident_json = json.loads(decoded_data)<br>                print(f&quot;Decoded Incident: {json.dumps(incident_json, indent=2)}&quot;)<br>    except Exception as e:<br>        print(f&quot;Error decoding base64: {e}&quot;)<br>    <br>    return &quot;OK&quot;, 200</pre><p>Create requierements.txt</p><pre>functions-framework==3.10.0<br>Flask==3.1.2</pre><p>Then run:</p><pre>gcloud functions deploy kill-switch \<br>    --gen2 \<br>    --runtime python314 \<br>    --region us-central1 \<br>    --trigger-http \<br>    --no-allow-unauthenticated \<br>    --entry-point show_post_body \<br>    --source .</pre><p>From there, the architecture is almost completed</p><p>Alert Policy → Pub/Sub → xxx → Cloud Run (Kill Switch)</p><p>Where xxx is EventArc missing. Let’s add it:</p><pre># Project Info<br>PROJECT_NUMBER=$(gcloud projects describe $(gcloud config get-value project) --format=&#39;value(projectNumber)&#39;)<br>PROJECT_ID=$(gcloud config get-value project)<br><br># Enable required APIs<br>gcloud services enable eventarc.googleapis.com<br><br># Add Pub/Sub default SA Token Creatore<br>gcloud projects add-iam-policy-binding ${PROJECT_ID} \<br>    --member=&quot;serviceAccount:@service-${PROJECT_NUMBER}@gcp-sa-pubsub.iam.gserviceaccount.com&quot; \<br>    --role=&quot;roles/iam.serviceAccountTokenCreator&quot;<br><br># Dedicated Serivce Account for Eventarc to Cloud Run<br>gcloud iam service-accounts create function-invoker \<br>    --display-name=&quot;Eventarc to Cloud Run Invoker&quot;<br><br># role Invoker<br>gcloud functions add-invoker-policy-binding kill-switch \<br>    --member=&quot;serviceAccount:function-invoker@${PROJECT_ID}.iam.gserviceaccount.com&quot; \<br>    --project=${PROJECT_ID}<br><br># EventArc (PubSub =&gt; Event Arc =&gt; Cloud Function)<br>gcloud eventarc triggers create pubsub-to-function \<br>    --service-account=&quot;function-invoker@${PROJECT_ID}.iam.gserviceaccount.com&quot; \<br>    --location=us-central1 \<br>    --transport-topic=&quot;projects/${PROJECT_ID}/topics/${TOPIC_NAME}&quot; \<br>    --destination-run-service=kill-switch \<br>    --destination-run-region=us-central1 \<br>    --event-filters=&quot;type=google.cloud.pubsub.topic.v1.messagePublished&quot;</pre><p>Now, any messages published to the Pub/Sub topic configured for the Alert Policies will be forwarded to our Cloud Function.</p><p>As shown earlier in this article, I will create and trigger an Alert Policy based on the Firestore Document Writes metric. I’m running the script at 4:55pm.</p><p>As planned, the policy is violated 5 minutes later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*Ff1xFGgGvPL7D1lxjvFSRQ.png" /></figure><p>The Alert Policy takes a brief moment to register a violation before sending the message to Pub/Sub, which is subsequently forwarded to our Cloud Function via EventArc.</p><p>Here’s a decoded body of what the Cloud Function receives:</p><pre>Decoded Incident: {<br>  &quot;incident&quot;: {<br>    &quot;condition&quot;: {<br>      &quot;conditionThreshold&quot;: {<br>        &quot;aggregations&quot;: [<br>          {<br>            &quot;alignmentPeriod&quot;: &quot;86400s&quot;,<br>            &quot;perSeriesAligner&quot;: &quot;ALIGN_SUM&quot;<br>          }<br>        ],<br>        &quot;comparison&quot;: &quot;COMPARISON_GT&quot;,<br>        &quot;duration&quot;: &quot;0s&quot;,<br>        &quot;filter&quot;: &quot;resource.type = \&quot;firestore_instance\&quot; AND metric.type = \&quot;firestore.googleapis.com/document/write_count\&quot;&quot;,<br>        &quot;thresholdValue&quot;: 1000,<br>        &quot;trigger&quot;: {<br>          &quot;count&quot;: 1<br>        }<br>      },<br>      &quot;displayName&quot;: &quot;Firestore Instance - Document Writes&quot;,<br>      &quot;name&quot;: &quot;projects/test-notification-487215/alertPolicies/11229261735614898435/conditions/15534646543678555502&quot;<br>    },<br>    &quot;condition_name&quot;: &quot;Firestore Instance - Document Writes&quot;,<br>    &quot;documentation&quot;: {<br>      &quot;content&quot;: &quot;&quot;,<br>      &quot;mime_type&quot;: &quot;&quot;,<br>      &quot;subject&quot;: &quot;[ALERT - No severity] Test&quot;<br>    },<br>    &quot;ended_at&quot;: null,<br>    &quot;incident_id&quot;: &quot;0.o4712c97khg3&quot;,<br>    &quot;metadata&quot;: {<br>      &quot;system_labels&quot;: {},<br>      &quot;user_labels&quot;: {}<br>    },<br>    &quot;metric&quot;: {<br>      &quot;displayName&quot;: &quot;Document Writes&quot;,<br>      &quot;labels&quot;: {<br>        &quot;op&quot;: &quot;CREATE&quot;<br>      },<br>      &quot;type&quot;: &quot;firestore.googleapis.com/document/write_count&quot;<br>    },<br>    &quot;observed_value&quot;: &quot;3314.000&quot;,<br>    &quot;policy_name&quot;: &quot;Firestore write alert policy&quot;,<br>    &quot;resource&quot;: {<br>      &quot;labels&quot;: {<br>        &quot;project_id&quot;: &quot;test-notification-487215&quot;<br>      },<br>      &quot;type&quot;: &quot;firestore_instance&quot;<br>    },<br>    &quot;resource_id&quot;: &quot;&quot;,<br>    &quot;resource_name&quot;: &quot;test-notification-487215 Firestore Instance labels {project_id=test-notification-487215}&quot;,<br>    &quot;resource_type_display_name&quot;: &quot;Firestore Instance&quot;,<br>    &quot;scoping_project_id&quot;: &quot;test-notification-487215&quot;,<br>    &quot;scoping_project_number&quot;: 191841326616,<br>    &quot;severity&quot;: &quot;No severity&quot;,<br>    &quot;started_at&quot;: 1770912035,<br>    &quot;state&quot;: &quot;open&quot;,<br>    &quot;summary&quot;: &quot;Document Writes for test-notification-487215 Firestore Instance labels {project_id=test-notification-487215} with metric labels {op=CREATE} is above the threshold of 1000.000 with a value of 3314.000.&quot;,<br>    &quot;threshold_value&quot;: &quot;1000&quot;,<br>    &quot;url&quot;: &quot;https://console.cloud.google.com/monitoring/alerting/alerts/0.o4712c97khg3?channelType=cloud-pubsub&amp;project=test-notification-487215&quot;<br>  },<br>  &quot;version&quot;: &quot;1.2&quot;<br>}</pre><p>Let’s rewrite the Cloud Function to automatically terminate the project whenever any Alert Policy connected to our Notification Channel hits its threshold.</p><p>First, here’s the adapted requierements.txt</p><pre>functions-framework==3.10.0<br>google-cloud-billing==1.18.0<br>Flask==3.1.2</pre><p>The new main.py including the Kill Switch (disable billing):</p><pre>&quot;&quot;&quot;Cloud Function to disable billing for a GCP project.&quot;&quot;&quot;<br><br>import base64<br>import json<br>import logging<br>import os<br><br>import functions_framework<br>from flask import Request<br>from google.cloud import billing_v1<br>from google.api_core import exceptions<br><br># Constants<br>PROJECT_ID = os.getenv(&quot;PROJECT_ID&quot;)<br>if PROJECT_ID is None:<br>    raise ValueError(&quot;PROJECT_ID environment variable is not set.&quot;)<br><br>APP_LOGGER = logging.getLogger(__name__)<br><br><br>@functions_framework.http<br>def kill_switch(request: Request) -&gt; tuple[str, int]:<br>    &quot;&quot;&quot;A simple HTTP Cloud Function that processes incident data and triggers billing disable.&quot;&quot;&quot;<br>    try:<br>        body_json = request.get_json(silent=True)<br>        if body_json and &quot;message&quot; in body_json:<br>            encoded_data = body_json[&quot;message&quot;].get(&quot;data&quot;)<br>            if encoded_data:<br>                decoded_data = base64.b64decode(encoded_data).decode(&quot;utf-8&quot;)<br>                incident_json = json.loads(decoded_data)<br>                APP_LOGGER.debug(<br>                    &quot;Decoded Incident: %s&quot;, json.dumps(incident_json, indent=2)<br>                )<br><br>                # Validate that it&#39;s a proper incident structure<br>                if &quot;incident&quot; in incident_json and incident_json.get(&quot;version&quot;):<br>                    incident = incident_json[&quot;incident&quot;]<br>                    APP_LOGGER.info(<br>                        &quot;Valid incident received: %s&quot;, incident.get(&quot;incident_id&quot;)<br>                    )<br><br>                    # Trigger kill switch<br>                    billing_manager = BillingManager()<br>                    billing_manager.disable_billing_for_the_project()<br><br>                    return &quot;Billing disabled&quot;, 200<br>                else:<br>                    APP_LOGGER.warning(&quot;Invalid incident structure received&quot;)<br>                    return &quot;Invalid incident format&quot;, 400<br>    except Exception as e:<br>        APP_LOGGER.error(&quot;Error processing request: %s&quot;, str(e))<br>        return &quot;Error&quot;, 500<br><br>    return &quot;No incident data&quot;, 400<br><br><br>class BillingManager:<br>    &quot;&quot;&quot;Manages billing operations for GCP projects.&quot;&quot;&quot;<br><br>    def __init__(self) -&gt; None:<br>        &quot;&quot;&quot;Initialize the BillingManager.&quot;&quot;&quot;<br>        self.billing_client = billing_v1.CloudBillingClient()<br><br>    def disable_billing_for_the_project(self) -&gt; None:<br>        &quot;&quot;&quot;Disable billing for a project by removing its billing account.<br><br>        Based on: https://docs.cloud.google.com/billing/docs/how-to/disable-billing-with-notifications#create-cloud-run-function<br>        &quot;&quot;&quot;<br>        resource_name = f&quot;projects/{PROJECT_ID}&quot;<br><br>        project_billing_info = billing_v1.ProjectBillingInfo(<br>            billing_account_name=&quot;&quot;  # No Billing Account<br>        )<br><br>        APP_LOGGER.debug(&quot;Project Billing Info to update: %s&quot;, project_billing_info)<br><br>        request = billing_v1.UpdateProjectBillingInfoRequest(<br>            name=resource_name, project_billing_info=project_billing_info<br>        )<br><br>        try:<br>            response = self.billing_client.update_project_billing_info(request=request)<br>            APP_LOGGER.info(&quot;Disable billing response: %s&quot;, response)<br>            APP_LOGGER.critical(&quot;Billing disabled for project %s.&quot;, PROJECT_ID)<br>        except exceptions.PermissionDenied:<br>            APP_LOGGER.error(&quot;Failed to disable billing, check permissions.&quot;)</pre><p>Then run these commands:</p><pre>PROJECT_ID=$(gcloud config get-value project)<br><br># Add Billing Permissions<br>gcloud projects add-iam-policy-binding &quot;${PROJECT_ID}&quot; \<br>    --member &quot;serviceAccount:function-invoker@${PROJECT_ID}.iam.gserviceaccount.com&quot; \<br>    --role &quot;roles/billing.projectManager&quot; \<br>    --project=${PROJECT_ID}<br><br># Deploy main.py as Google Cloud Function<br>gcloud functions deploy kill-switch \<br>    --gen2 \<br>    --runtime python314 \<br>    --region us-central1 \<br>    --trigger-http \<br>    --no-allow-unauthenticated \<br>    --entry-point kill_switch \<br>    --source . \<br>    --set-env-vars &quot;PROJECT_ID=${PROJECT_ID}&quot; \<br>    --service-account &quot;function-invoker@${PROJECT_ID}.iam.gserviceaccount.com&quot;<br><br># Ensure role Invoker<br>gcloud functions add-invoker-policy-binding kill-switch \<br>    --member=&quot;serviceAccount:function-invoker@${PROJECT_ID}.iam.gserviceaccount.com&quot; \<br>    --project=${PROJECT_ID}</pre><p><strong>Be careful now! Every Alert Policy you create and link to the Pub/Sub Notification Channel will trigger as soon as the threshold is reached, causing the Pub/Sub to immediately invoke EventArc and activate the KillSwitch!</strong></p><p>Running another test with a Firestore document write around 7:55 PM, the Kill Switch was triggered in just 5 minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*PgH3zD6Pc1T6CJmGMDEgpQ.png" /></figure><p>That’s all folks!</p><p>The complete process and all related files are available in <a href="https://github.com/leo-kling/gcp-metrics-based-kill-switch">this repository</a>.</p><p>Which you can clone on your computer using:</p><pre>git clone https://github.com/leo-kling/gcp-metrics-based-kill-switch.git</pre><h3><strong>Conclusion</strong></h3><ul><li>Budget Alerts are great but not enough on their own.</li><li>Alert Policies are useful but also not sufficient.</li><li>Together, these two mechanisms cover a lot,<strong> yet they still don’t solve everything.</strong></li><li>Remember: <strong>Activities = Expenses</strong>.</li><li>It’s your responsibility to use the <strong>Cloud Billing Calculator</strong> to plan for your activities and expenses.</li><li>A <strong>Kill Switch</strong> isn’t the ultimate solution but that’s perfectly fine in a non-production environment. After all, you have to start somewhere.</li><li><strong>Know your project: </strong>Monitor as much a possible.</li><li>Use <strong>Notification Channels, </strong>they’re inexpensive and powerful!</li></ul><p><strong>A final, personal note:</strong></p><p>What I like about this approach (using Budgets + Alert Policies) is that, when properly set up, it adds multiple layers of protection against unpleasant surprises.</p><p>If your application already has basic security measures in place, you should be in good shape. That said, no competent cloud engineer would ever claim that security exempts you from monitoring, or vice versa.</p><p>In the absence of a native kill switch in GCP, the cloud can be inherently risky without adequate training. Perhaps it isn’t offered because Google expects users to start with a proper <a href="https://cloud.google.com/learn">learning journey in the Cloud</a>? I don’t know.</p><p>Until then, you should always rely on the most robust Kill Switch possible until you fully understand how to secure your application.</p><p>Better to end up with a <strong>404 Not Found</strong> than with a <strong>Costly Sorry</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9e2eab2099b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/building-a-faster-gcp-kill-switch-leveraging-cloud-monitoring-instead-of-billing-data-a9e2eab2099b">Building a Faster GCP Kill Switch: Leveraging Cloud Monitoring Instead of Billing Data</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>