smi-spec icon indicating copy to clipboard operation
smi-spec copied to clipboard

Metrics spec mentions pods as entity to work with

Open abonas opened this issue 5 years ago • 2 comments

The specification https://github.com/deislabs/smi-spec/blob/master/traffic-metrics.md#specification

seems to talk about possibility to define metrics on specific pods. Isn't this a bit "anti k8s" working with specific pods that can be down and redeployed elsewhere (with a different identifier) any moment? what about scaling? how can someone define metrics on future scaled instances?

abonas avatar May 22 '19 12:05 abonas

Happy to be corrected, but here's how I understand it:

TrafficMetrics isn't necessarily something that gets "defined" by the user per-se. I believe it's the API/object that exposed by the metrics API. For the pod-specific ones you're referring to, it's showing the metrics it keeps with fidelity down to the level of pod but you don't have to look at that level if that's not interesting to you.

Let's look at an example.

Let's say you install the smi-metrics example from: https://github.com/deislabs/smi-metrics (note, you will want a prometheus instances with metrics available somewhere... easiest way to show this example is by installing linkerd: https://linkerd.io/2/getting-started/)

This will install an APIServer extension to the Kubernetes API

kubectl get apiservice.apiregistration.k8s.io v1alpha1.metrics.smi-spec.io  

Then if you kubectl proxy you can query the metrics API:

curl localhost:8001/apis/metrics.smi-spec.io/v1alpha1/

This will show you the list of resources for which you can get TrafficMetric:

{
  "apiVersion": "v1",
  "groupVersion": "metrics.smi-spec.io/v1alpha1",
  "kind": "APIResourceList",
  "resources": [
    {
      "kind": "TrafficMetrics",
      "name": "namespaces",
      "namespaced": false,
      "singularName": "",
      "verbs": ["get", "list"]
    },
    {
      "kind": "TrafficMetrics",
      "name": "deployments",
      "namespaced": true,
      "singularName": "",
      "verbs": ["get", "list"]
    },
    {
      "kind": "TrafficMetrics",
      "name": "pods",
      "namespaced": true,
      "singularName": "",
      "verbs": ["get", "list"]
    },
    {
      "kind": "TrafficMetrics",
      "name": "daemonsets",
      "namespaced": true,
      "singularName": "",
      "verbs": ["get", "list"]
    },
    {
      "kind": "TrafficMetrics",
      "name": "statefulsets",
      "namespaced": true,
      "singularName": "",
      "verbs": ["get", "list"]
    }
  ]
}

If you pick a specific resource:

curl localhost:8001/apis/metrics.smi-spec.io/v1alpha1/deployments

You will see TrafficMetrics for the specific resource (in this case, deployments -- but could be pods directly or namespaces, etc)

HTH

christian-posta avatar Jun 04 '19 18:06 christian-posta

You'll also notice that it is an APIService and works identically to how metrics.k8s.io and custom.metrics.k8s.io work.

Think of this as the status piece of other k8s resources instead of the spec. This analogy doesn't work particularly well though, as none of TrafficMetrics is being persisted to etcd (proxied back to the service itself).

grampelberg avatar Jun 04 '19 18:06 grampelberg