You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/09/06 07:17:56 UTC

[GitHub] [apisix-ingress-controller] Sindweller opened a new issue #665: request help: how to set the label of apisix_bad_status_code metric?

Sindweller opened a new issue #665:
URL: https://github.com/apache/apisix-ingress-controller/issues/665


   ### Issue description
   I'm tring to expose the metric `apisix_bad_status_code` which is defined in `prometheus.go`:
   ```
   apisixCodes: prometheus.NewGaugeVec(
   	prometheus.GaugeOpts{
   		Name:        "apisix_bad_status_codes",
   		Namespace:   _namespace,
   		Help:        "Bad status codes of requests to APISIX",
   		ConstLabels: constLabels,
   	},
   	[]string{"resource", "status_code"},
   ),
   ```
   And I got trouble on setting up the label.
   Take `consumer.go` and `List()` as an example, it's easy to set the `resource` label as `consumer` here, but how to get the bad `resp.StatusCode` since the return value is `err`? It may includes other type of error except bad status code.
   ```
   consumerItems, err := r.cluster.listResource(ctx, r.url)
   ```
   Similarly, I can set the `status_code` label here in `cluster.go` - `listResource()`, but I don't know how to get the resource type:
   ```
   func (c *cluster) listResource(ctx context.Context, url string) (*listResponse, error) {
   	req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
   	if err != nil {
   		return nil, err
   	}
   	resp, err := c.do(req)
   	if err != nil {
   		return nil, err
   	}
   	defer drainBody(resp.Body, url)
   	if resp.StatusCode != http.StatusOK {
   		err = multierr.Append(err, fmt.Errorf("unexpected status code %d", resp.StatusCode))
                    // I can set status code label here:
                    // c.metricsCollector.RecordAPISIXCode(resp.StatusCode, "resource")
                    // but I don't know how to get the resource type.
   		err = multierr.Append(err, fmt.Errorf("error message: %s", readBody(resp.Body, url)))
   		return nil, err
   	}
           // ...
   }
   ```
   So where should I call `metricsCollector.RecordAPISIXCode` and how to set both the `resource` and `bad status code` label?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] Sindweller closed issue #665: request help: how to set the label of apisix_bad_status_code metric?

Posted by GitBox <gi...@apache.org>.
Sindweller closed issue #665:
URL: https://github.com/apache/apisix-ingress-controller/issues/665


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tokers commented on issue #665: request help: how to set the label of apisix_bad_status_code metric?

Posted by GitBox <gi...@apache.org>.
tokers commented on issue #665:
URL: https://github.com/apache/apisix-ingress-controller/issues/665#issuecomment-913563293


   @Sindweller Feel free to change the method prototype, just adding another parameter to solve this problem.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org