title: Divide two metrics in Google Cloud Monitoring / MQL
body: <p>How do I compute the difference and ratio between two Stackdriver metrics in MQL?</p>
  <p>There are two parts two this question, but I am grateful if you can help me with one:</p>
  <ol>
  <li>Compute the difference between the two time series</li>
  <li>Compute the ratio between the two time series. Addon if possible: The case that the denominator is null should be handled gracefully.</li>
  </ol>
  <p>I got so far, but it does not yield the expected result (the resulting time series is always zero):</p>
  <pre><code>fetch global
  | { t_0:
        metric 'custom.googleapis.com/http/server/requests/count'
        | filter
          (metric.service == 'service-a' &amp;&amp; metric.uri =~ '/api/started')
        | align next_older(1m);
      t_1:
        metric 'custom.googleapis.com/http/server/requests/count'
        | filter
          (metric.service == 'service-a' &amp;&amp; metric.uri =~ '/api/completed')
        | align next_older(1m)
    }
  | outer_join 0
  | div
  </code></pre>
  <p>Obviously, the code has been anonymized. What I want to accomplish is to track whether there is a difference between processes that have been started vs completed.</p>
  <p><strong>EDIT / ADDITIONAL INFO 2021-11-18</strong></p>
  <p>I used the <a href="https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/query" rel="nofollow noreferrer">projects.timeSeries v3 API</a> for further debugging. Apparently the outer_join operation assumes that the labels between the two timeseries are the same, which is not the case in my example.</p>
  <p><strong>Does anybody know, how to delete the labels, so I can perform the join and aggregation?</strong></p>
  <p><strong>EDIT / ADDITIONAL INFO 2021-11-19</strong></p>
  <p>The aggregation now works as I managed to delete the labels using the <code>map drop[...]</code> maplet.</p>
  <p>The challenge was indeed the labels as these labels are generated by the Spring Boot implementation of Micrometer. Since the labels are distinct between these two metrics the join operation was always empty for <code>join</code>, or only the second timeseries for <code>outer_join</code>.</p>