<p>I would like to scale my deployment based on a custom logging metric, but I'm not able to make that work, I created already the custom metric and I'm also able to see it in the metric explorer but for some reason the stackdriver adapter is not able to get the metric values.</p>
<p><a href="https://i.stack.imgur.com/HVEUM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HVEUM.png" alt="Custom logging metric" /></a></p>
<p><a href="https://i.stack.imgur.com/MZYVm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MZYVm.png" alt="Custom metric in the metric explorer" /></a></p>
<p><a href="https://i.stack.imgur.com/wOcF4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wOcF4.png" alt="Custom metric name in metric explorer" /></a></p>
<p>This is my hpa.yaml</p>
<pre><code>apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: nginx-hpa
spec:
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - external:
      metricName: logging.googleapis.com|user|http_request_custom
      targetValue: &quot;20&quot;
    type: External
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx
</code></pre>
<p>But i'm always getting the following error:</p>
<pre><code>&quot;unable to get external metric default/logging.googleapis.com|user|http_request_custom/nil: unable to fetch metrics from external metrics API: the server could not find the requested resource (get logging.googleapis.com|user|http_request_custom.external.metrics.k8s.io)&quot;
</code></pre>
<p>Should i do something different?? any idea?</p>

Pablo Portillo
<p>Not sure you have created the service account and granted access to the adapter however there is two models of custom metrics adapter. Legacy adapter and new resource version.</p>
<p>If adapter is up and running did you check the logs of POD ?</p>
<p>New resource model to install :</p>
<pre><code>kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-stackdriver/master/custom-metrics-stackdriver-adapter/deploy/production/adapter_new_resource_model.yaml
</code></pre>
<p>ref yaml you can use this way further metrics</p>
<pre><code>apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: pubsub
spec:
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - external:
      metric:
       name: pubsub.googleapis.com|subscription|num_undelivered_messages
       selector:
         matchLabels:
           resource.labels.subscription_id: echo-read
      target:
        type: AverageValue
        averageValue: 2
    type: External
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: pubsub
</code></pre>
<p>Ref : <a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/autoscaling-metrics#pubsub_4" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/tutorials/autoscaling-metrics#pubsub_4</a></p>
