<p>We have a metric <code>container_memory_rss</code> from cadvisor and a metric <code>kube_pod_container_resource_requests_memory_bytes</code> from Kubernetes itself.</p>

<p>Is it possible to join the metrics against one another so that we can directly compare the ratio of both metrics? More specifically I'd like to basically 'join' the following metrics:</p>

<pre><code>sum(kube_pod_container_resource_requests_memory_bytes) by (pod, namespace)
sum(container_memory_rss) by (container_label_io_kubernetes_pod_name, container_label_io_kubernetes_pod_namespace)
</code></pre>

<p>The 'join' would be on pod name and namespace. </p>

<p>Can PromQL do this, given that the label names vary?</p>

<p>You can use the <a href="https://prometheus.io/docs/prometheus/latest/querying/functions/#label_replace" rel="nofollow noreferrer">label_replace</a> function to modify labels on one side of the expression such that they match:</p>

<pre><code>  sum by (pod_name, namespace) (container_memory_rss) 
/ 
  sum by (pod_name, namespace) (
    label_replace(
      kube_pod_container_resource_requests_memory_bytes, 
      "pod_name", "$1", "pod", "(.*)"
    )
  ) 
</code></pre>
