<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Log Explorer &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/log-explorer/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Tue, 01 Aug 2023 22:30:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>Log Explorer &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>GCP BigQuery: Finding Expensive Queries</title>
		<link>https://myshittycode.com/2023/07/28/gcp-bigquery-finding-expensive-queries/</link>
					<comments>https://myshittycode.com/2023/07/28/gcp-bigquery-finding-expensive-queries/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Fri, 28 Jul 2023 17:59:53 +0000</pubDate>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Google BigQuery]]></category>
		<category><![CDATA[Google Cloud Platform]]></category>
		<category><![CDATA[Log Explorer]]></category>
		<guid isPermaLink="false">https://myshittycode.com/?p=2296</guid>

					<description><![CDATA[<p>Problem This post applies to you if: Solution The GCP billing report can tell us the cost breakdown of the services used over time, but it cannot tell us why it costs this much. To get the whys, we need to pull additional data to paint a fuller picture. Filtering the Logs There are several [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2023/07/28/gcp-bigquery-finding-expensive-queries/">GCP BigQuery: Finding Expensive Queries</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-rank-math-toc-block" id="rank-math-toc"><h2>Table of Contents</h2><nav><ul><li><a href="#problem">Problem</a></li><li><a href="#solution">Solution</a><ul><li><a href="#filtering-the-logs">Filtering the Logs</a></li><li><a href="#making-metrics-easier-to-read">Making Metrics Easier to Read</a></li><li><a href="#inspecting-executed-query">Inspecting Executed Query</a></li></ul></li></ul></nav></div>



<h2 class="wp-block-heading" id="problem">Problem</h2>



<p>This post applies to you if:</p>



<ul class="wp-block-list">
<li>You have an application that performs CRUD operations against GCP BigQuery.</li>



<li>When you open up your <a href="https://cloud.google.com/billing/docs/how-to/reports" target="_blank" rel="noopener">project billing report</a> every month, you notice the BigQuery service is consistently one of the biggest spenders.</li>



<li>You have no idea why the BigQuery cost is so high.</li>



<li>You cannot explain the rising cost to your boss other than saying, <em>&#8220;The database is called BigQuery, so the query must be big!&#8221;</em>.</li>
</ul>



<h2 class="wp-block-heading" id="solution">Solution</h2>



<p>The GCP billing report can tell us the cost breakdown of the services used over time, but it cannot tell us why it costs this much. To get the whys, we need to pull additional data to paint a fuller picture. </p>



<h3 class="wp-block-heading" id="filtering-the-logs">Filtering the Logs</h3>



<p>There are several ways to find out what queries are hitting your BigQuery tables/views and how many bytes are billed. In this post, we will use Log Explorer because it takes the least work to get the bird&#8217;s-eye view. </p>



<p>In the Log Explorer query box, enter the following:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
resource.type=&quot;bigquery_resource&quot;
protoPayload.methodName=&quot;jobservice.jobcompleted&quot;
protoPayload.serviceData.jobCompletedEvent.job.jobStatistics.totalBilledBytes:*
</pre></div>


<p>The first 2 lines filter all the BigQuery completed jobs. The third line filter jobs that cost money.</p>



<p>When running the above query, the result looks like the following:</p>



<figure class="wp-block-image aligncenter size-large is-resized"><img fetchpriority="high" decoding="async" src="https://myshittycode.com/wp-content/uploads/2023/07/1-log-explorer-query-1024x632.png?x45560" alt="" class="wp-image-2303" width="768" height="474" srcset="https://myshittycode.com/wp-content/uploads/2023/07/1-log-explorer-query-1024x632.png 1024w, https://myshittycode.com/wp-content/uploads/2023/07/1-log-explorer-query-300x185.png 300w, https://myshittycode.com/wp-content/uploads/2023/07/1-log-explorer-query-768x474.png 768w, https://myshittycode.com/wp-content/uploads/2023/07/1-log-explorer-query-1536x948.png 1536w, https://myshittycode.com/wp-content/uploads/2023/07/1-log-explorer-query.png 1750w" sizes="(max-width: 768px) 100vw, 768px" /></figure>



<h3 class="wp-block-heading" id="making-metrics-easier-to-read">Making Metrics Easier to Read</h3>



<p>From this view, it&#8217;s difficult to see the total bytes billed for each completed job by default, and it&#8217;s easier to scan for these values by bubbling them up. To do this:</p>



<ul class="wp-block-list">
<li>Click on any result item, and expand the payload.</li>



<li>Under <strong>jobStatistics</strong>, locate <strong>totalBilledBytes</strong>.</li>



<li>Select the value, and select <strong>Add field to summary line</strong>.</li>
</ul>



<figure class="wp-block-image aligncenter size-large is-resized"><img decoding="async" src="https://myshittycode.com/wp-content/uploads/2023/07/2-field-summary-line-793x1024.png?x45560" alt="" class="wp-image-2304" width="595" height="768" srcset="https://myshittycode.com/wp-content/uploads/2023/07/2-field-summary-line-793x1024.png 793w, https://myshittycode.com/wp-content/uploads/2023/07/2-field-summary-line-232x300.png 232w, https://myshittycode.com/wp-content/uploads/2023/07/2-field-summary-line-768x992.png 768w, https://myshittycode.com/wp-content/uploads/2023/07/2-field-summary-line.png 822w" sizes="(max-width: 595px) 100vw, 595px" /></figure>



<p>Now, the log result displays the total bytes billed in green, where you can scan for any large numbers that interest you.</p>



<figure class="wp-block-image aligncenter size-large is-resized"><img decoding="async" src="https://myshittycode.com/wp-content/uploads/2023/07/3-field-summary-1024x564.png?x45560" alt="" class="wp-image-2305" width="768" height="423" srcset="https://myshittycode.com/wp-content/uploads/2023/07/3-field-summary-1024x564.png 1024w, https://myshittycode.com/wp-content/uploads/2023/07/3-field-summary-300x165.png 300w, https://myshittycode.com/wp-content/uploads/2023/07/3-field-summary-768x423.png 768w, https://myshittycode.com/wp-content/uploads/2023/07/3-field-summary-1536x847.png 1536w, https://myshittycode.com/wp-content/uploads/2023/07/3-field-summary.png 1952w" sizes="(max-width: 768px) 100vw, 768px" /></figure>



<h3 class="wp-block-heading" id="inspecting-executed-query">Inspecting Executed Query</h3>



<p>From here, you can jump into the payload in question and search for the executed query:</p>



<figure class="wp-block-image aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://myshittycode.com/wp-content/uploads/2023/07/4-detailed-query-1024x514.png?x45560" alt="" class="wp-image-2306" width="768" height="386" srcset="https://myshittycode.com/wp-content/uploads/2023/07/4-detailed-query-1024x514.png 1024w, https://myshittycode.com/wp-content/uploads/2023/07/4-detailed-query-300x151.png 300w, https://myshittycode.com/wp-content/uploads/2023/07/4-detailed-query-768x386.png 768w, https://myshittycode.com/wp-content/uploads/2023/07/4-detailed-query.png 1370w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure>



<p>This approach is also great for detecting patterns in the logs. If the logs show the same total bytes billed every X minutes, it is almost likely executed by a scheduled process instead of interactively by the end users. Then, ask yourself, &#8220;If the query is returning the same 100 GB of data every 10 minutes, is this the most effective solution? Or can the result be stored in L2 cache (ex: Redis, etc.)?&#8221;.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2023/07/28/gcp-bigquery-finding-expensive-queries/">GCP BigQuery: Finding Expensive Queries</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2023/07/28/gcp-bigquery-finding-expensive-queries/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2296</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching using Disk

Served from: myshittycode.com @ 2026-02-18 23:31:27 by W3 Total Cache
-->