<p>I want to use the Custom log metrics on GKE HPA. Metrics are able to view on metrics explorer but unable to use it on HPA . We have installed Custom metrics adapter and We are able to use other custom metrics like <code>kubernetes.io|pod|network|received_bytes_count</code> successfully for scaling. Below image shows the Metrics explorer graph for custom metric that i want to use on HPA</p>
<p>This metric was created from application logs</p>
<p><a href="https://i.stack.imgur.com/dluKC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dluKC.png" alt="enter image description here" /></a></p>
<p>Used following HPA yaml to use that metric</p>
<pre><code>apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name:   &quot;similar-products-rts-hpa&quot;
  namespace: relevancy
spec:
  behavior:
    scaleUp:
      stabilizationWindowSeconds: 120
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: similar-products
  minReplicas: 3
  maxReplicas: 6
  metrics:
    - type: Pods
      pods:
        metric:
          name: &quot;logging.googleapis.com|user|Similar_Products(RTS)_Inbound_Request_Count&quot;
        target:
          type: AverageValue
          averageValue: 25
</code></pre>
<p>Please find the error below</p>
<pre><code>The HPA was unable to compute the replica count: unable to get metric logging.googleapis.com|user|Similar_Products(RTS)_Inbound_Request_Count: unable to fetch metrics from custom metrics API: googleapi: Error 400: The supplied filter does not specify a valid combination of metric and monitored resource descriptors. The query will not return any time series., badRequest
</code></pre>

sankar
<p>Unfortunately, <a href="https://github.com/kubernetes/kubernetes/issues/72996" rel="nofollow noreferrer">upper case letters in metric names are not supported</a> as HPA treats metrics as pseudo resources which means they are not case sensitive.  I also believe that parentheses are invalid characters as well for metric names.</p>
<p>Any chance you can change your metric name to lowercase and remove the parentheses?  Maybe something like <code>similar_products_rts_inbound_request_count</code>?</p>
<p>EDIT:
The other issue I just noticed is that the metric is a container metric and not a pod metric.  Prior to <a href="https://github.com/GoogleCloudPlatform/k8s-stackdriver/pull/434" rel="nofollow noreferrer">this change</a>, it was necessary to modify the custom metrics adapter deployment to support container metrics.  You can either update your deployment with the current <a href="https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-stackdriver/master/custom-metrics-stackdriver-adapter/deploy/production/adapter_new_resource_model.yaml" rel="nofollow noreferrer">manifest</a>,or you can modify your current deployment by adding <code>--fallback-for-container-metrics=true</code>:</p>
<pre><code>spec:
      serviceAccountName: custom-metrics-stackdriver-adapter
      containers:
      - image: gcr.io/gke-release/custom-metrics-stackdriver-adapter:v0.12.0-gke.0
        imagePullPolicy: Always
        name: pod-custom-metrics-stackdriver-adapter
        command:
        - /adapter
        - --use-new-resource-model=true
        - --fallback-for-container-metrics=true
        resources:
          limits:
            cpu: 250m
            memory: 200Mi
          requests:
            cpu: 250m
            memory: 200Mi 
</code></pre>
