Use case:
Allow client libraries used inside the developer's code to get the service name, configuration name and revision name.
Example:
Proposal:
Similarly to Knative injecting a PORT environment variable, Knative also injects 3 environment variables with these values.
The env vars share the same prefix. I suggest SERVERLESS_, alternatively K_.
Values would be SERVERLESS_SERVICE, SERVERLESS_CONFIGURATION, SERVERLESS_REVISION
/area API
/kind feature
/kind spec
I work on OpenCensus. I was looking for ways to improve the metadata we are collection on Knative, and @steren pointed out this issue to me.
Being able to filter and breakdown monitoring/tracing data by service name and version is fundamentally important to be able to setup SLOs and alerts properly, do canary analysis, perform root-cause analysis in production.
Metric data is being exported to a single resource in the analysis backends.
For example, in order to see latency metrics for a service and set SLOs, we need to label metrics with service name when uploading to the backend. Otherwise, you can also see an aggregate of all collected latency metrics which is useless.
The state of the things are better for traces but without labelling properly, it is hard to generate auto-analysis reports and service dependency graphs.
Without labelling, there is also no way to see how the new versions of the same service performs. This is critical for canary analysis.
@steren I was interested in the suggestions
SERVERLESS_SERVICE, SERVERLESS_CONFIGURATION, SERVERLESS_REVISION
.. maybe it could be more clear as
SERVICELESS_SERVICE, CONFIGURATIONLESS_CONFIGURATION, REVISIONLESS_REVISION?
Why not KNATIVE_?
@adriancole your comment is neither constructive nor respectful. Please remember the code of conduct
A KNATIVE_ or K_ prefix would work fine.
A short prefix might be preferred, so my preference goes for K_.
This seems reasonable, But leaving naming aside for a moment (I'd prefix with KNATIVE_ though to mirror the k8s resource types) are we sure separate per-resource env vars is the right mechanism? Just these three, or are there more?
Again, this seems like a good approach, but are there any downsides? E.g., do we risk polluting environments with more over time? Does it scale to hundreds of system-generated labels (not that I can think of anywhere near that many now)? Are there any alternative approaches to consider before we adopt this one as standard?
It'll be hard to walk back in favor of something else later on, so let's be convinced it's right.
A single variable with structured data such as json. Spring boot supports this with SPRING_APPLICATION_JSON. Cloud foundry also has a similar env var.
I discussed this offline with Steren a few days ago. This seems probably useful (will bring it up at the API WG), but more importantly, we should set up a documented place for operators to document the extensions to the runtime contract that they offer. There are at least four such extension points available:
Environment Variables (as mentioned here)
K_ might be preferable to bare SERVICE or REVISION).Local filesystem mounts:
ioutil.ReadFile with os.Getenv, for example).Network API endpoints:
Incoming request header decoration (i.e. X-Forwarded-For:):
I'll start a doc for a registry; my general preference would be in the order provided above (in the absence of existing interoperability factors).
With respect to this specific proposal, it sounds like @rakyll is in favor, and @spencergibb suggests packing a single environment variable with structured data instead of multiple environment variables.
I also like the idea of packing a single environment variable with structured data instead of multiple environment variables. In cloudfoundry we do something similar with VCAP_APPLICATION variable. I would be open to doing a PR and get feedback from all of you.
Most helpful comment
@steren I was interested in the suggestions
SERVERLESS_SERVICE,SERVERLESS_CONFIGURATION,SERVERLESS_REVISION.. maybe it could be more clear as
SERVICELESS_SERVICE,CONFIGURATIONLESS_CONFIGURATION,REVISIONLESS_REVISION?