-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Design proposal: customize container log-tailing #1911
Design proposal: customize container log-tailing #1911
Conversation
Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
Codecov Report
@@ Coverage Diff @@
## master #1911 +/- ##
==========================================
+ Coverage 49.75% 56.12% +6.36%
==========================================
Files 175 180 +5
Lines 8084 7753 -331
==========================================
+ Hits 4022 4351 +329
+ Misses 3684 2986 -698
- Partials 378 416 +38
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @corneliusweig, thanks for submitting this proposal and for your patience in getting it reviewed (I was out last week).
Just had one question for you!
```yaml | ||
log: | ||
# a list of deployment.spec.selector items, rules are OR'ed | ||
- matchExpressions: # in one item, rules are AND'ed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify -- I would either specify matchExpressions
or matchLabels
? and will matchExpressions
look for matches with labels on pods, or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@priyawadhwa Yes, matchExpressions
and matchLabels
should be marked with yamltags:oneOf=selector
or so. I'll add that.
Both matchExpression
and matchLabels
should have the same semantics as for deployments, so they both refer to labels -- only matchExpression
will allow more logical operations than just matchLabels
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thoughts, after reading kubectl explain deployment.spec.selector
carefully again, I don't think we should place the oneOf
constraint here. matchLabels
is simply a shorthand for matchExpressions
and can be trivially AND'ed with a matchExpressions
object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. The nice thing about matchLabels
is that it's simpler, but matchExpressions
is essentially a superset of matchLabels
. I'm wondering if it would be cleaner to only have matchExpressions
.
We could have something like
- key: tail
values: ['true']
and then default the operator
to In
so that it would be a bit simpler like matchLabels
. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite convinced.
If Skaffold wants to look like k8s selectors, we should strive to be as compliant as possible. Using similar names with deviating semantics (default operator) creates confusion. The great advantage of using the standard syntax and semantics for the selector is the recognizability with existing k8s syntax.
Bottom line: if you really think we should deviate from the standard k8s config, then the new config should also look different. But why should it? I think k8s has found a sweet spot of configurability (matchExpressions
) and simplicity (matchLabels
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, I don't feel super strongly about it, so let's keep it the way you have it!
## Integration test plan | ||
|
||
- Add a test case with two deployments, where one is selected based on the log spec and the other is excluded. | ||
Make sure that the excluded pod does not show up in the logs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
@priyawadhwa No problem at all, I saw your great performance at Next'19. Well done! At you convenience, please take another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Left a question for you.
This looks promising - I have one clarification question: we are talking about pod selectors here - but in case of istio it is not an extra pod that we need to filter out but the sidecar container. Which raises the question - should we introduce both pod and container selection logic? |
@balopat Yeah, so true.. this won't (yet) solve the istio problem. First of all, I think there is a fundamental difference between label selectors and selecting individual containers: labels are usually generic so that white-listing labels makes sense. Containers on the other hand have no generic name/labels, so that white-listing does not make sense. Therefore, I think that the container selector should follow a black-listing logic. Thus, my favored option would be: log:
- matchExpressions:
- key: app
values: ['traefik']
operator: In
matchLabels: # note: matchLabels and matchExpressions in one selector are AND'ed
tail: 'true'
excludeContainers:
- 'istio-proxy'
- 'istio*' # allow glob patterns for the name
- ... Here, In addition, I could imagine that WDYT? |
Resolution: A UUID label is not required for now but can be added later when users request it. | ||
|
||
## Implementation plan | ||
1. Switch the selection of pods for the log selector from image lists to `tail=true` label (#1910). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an issue with helm
: labels are applied to resources after they are created. not before. This means that we won't see the logs during a short period of time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an issue with helm : labels are applied to resources after they are created. not before.
You mean this is a restriction of helm
itself or how skaffold handles helm
deployments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because helm
templates are resolved cluster side, skaffold can't apply the labels on the yaml before sending to k8s, the way it does with kubectl
and kustomize
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a minor inconvenience. Once the label is applied by helm
, the logs will be tailed starting from the global startTime
(pkg/skaffold/kubernetes/log.go:50). I just tried this with the following patch based on PR #1910
diff --git a/examples/helm-deployment/Dockerfile b/examples/helm-deployment/Dockerfile
index c1c9be3e..2307eff6 100644
--- a/examples/helm-deployment/Dockerfile
+++ b/examples/helm-deployment/Dockerfile
@@ -1,3 +1,7 @@
-FROM nginx:stable
+FROM golang:1.10.1-alpine3.7 as builder
+COPY main.go .
+RUN go build -o /app main.go
-COPY static /usr/share/nginx/html/
+FROM alpine:3.7
+CMD ["./app"]
+COPY --from=builder /app .
diff --git a/examples/helm-deployment/main.go b/examples/helm-deployment/main.go
new file mode 100644
index 00000000..46d5cbd9
--- /dev/null
+++ b/examples/helm-deployment/main.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+ "fmt"
+ "time"
+)
+
+func main() {
+ for i := 0; ; i++ {
+ fmt.Printf("Hello world! %d\n", i)
+
+ time.Sleep(time.Second * 1)
+ }
+}
diff --git a/examples/helm-deployment/skaffold-helm/templates/deployment.yaml b/examples/helm-deployment/skaffold-helm/templates/deployment.yaml
index ad989438..f1b4442b 100644
--- a/examples/helm-deployment/skaffold-helm/templates/deployment.yaml
+++ b/examples/helm-deployment/skaffold-helm/templates/deployment.yaml
@@ -14,6 +14,7 @@ spec:
labels:
app: {{ template "skaffold-helm.name" . }}
release: {{ .Release.Name }}
+ tail: "true"
spec:
containers:
- name: {{ .Chart.Name }}
All logs starting from iteration 0
are shown when using the label selector approach.
Therefore, there will be a small delay until the logs are shown, but nothing will be lost.
What bothers me though, is that helm
deployments don't seem to apply the tail=true
label to deployed pods. I had to manually apply that in the above patch. Is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
@corneliusweig that makes sense to me; in this case we include a container's logs if:
I'm good with that, @balopat WDYT? |
Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
@balopat @priyawadhwa Have you had time to discuss the log tailing config? Do you think it's worth to be implemented? |
@corneliusweig after reading #1911 (comment), i am thinking do we need a pod selecting logic?
For the 2nd use case, Maybe, we could fix the way we tail logs,
Now regarding the first use case, which is "user defined additional pod logs",
Maybe, we should do the same for logging, where users can define additional images they want logs from? This could be a command line flag. What do you think? |
with the helm labeling improvements and first parts of the implementation for this underway, I think we're about ready to merge this proposal. to me the logic for excluding containers from logs if they match the provided regex but are specified in the @balopat @dgageot @priyawadhwa anyone have any final objections? |
@priyawadhwa, @corneliusweig Sorry if it wasn't clear. |
@tejal29 @corneliusweig I do like the idea of minimal configuration. I think @tejal29's idea would work, except we would still need to add some additional support for excluding containers that skaffold thinks it should log. @corneliusweig WDYT? |
It's too late here. I'll follow up tomorrow. |
@tejal29 Alright, sorry for the delay. Overall, I find this an elegant extension of the existing functionality. It covers most of the use-cases which were suggested for the log-tailing customization. The one which it does not fully cover is when Skaffold builds and manages a pod, but the user is in general not interested in the logs thereof (#1991). However, I have other more fundamental problems with the
In addition, there are advantages of making the log configuration explicit:
Overall, I think label based pod selection has a lot of advantages. I'm still thinking about how to incorporate your idea to only tail from those containers in a pod whose image is built by Skaffold. In spririt this is a white-list approach based on the container image. However, I don't think it can work with the proposed logging config, because when I add an additional pod into the set of pods for log-tailing, I would additionally have to include its image in this whitelist. So to tail logs from an additional pod I would have to make two independent adjustments, which is an awful user experience. |
Thanks @corneliusweig for the detailed explanation. My proposal was to stay away from "pods" and control this config at container level.
The reasons i want to stay away from pods Vs containers
Regarding you points
I am ok with this since we are logging containers which users developed.
I like the sharing aspect. I dont mind adding a logging config instead of command line. Could we only add additional containers to log in the skaffold config instead of the label selector logic?
Agree. Same comment as above, my concern should it be on pod level or container image level? Regarding your observations:
The
I am not aware of the history here either. :( Maybe someone else can enlighted us here.
This is true. I am just worried, we are adding a bunch of config for that to happen. With |
Hey @tejal29, sorry for my delayed response, I was quite busy these last days. You are raising some important concerns which should be clarified before discussing the implementation details. Should skaffold focus on containers or pods? You are right that Skaffold is a tool to ease container development. On the other hand, containers are deployed as pods. So as soon as it comes to deployment, Skaffold should IMHO not ignore or try to hide the fact that the container is now part of a k8s pod. After all, Skaffold also helps to run containers (as pods) and at that point it's the pod that needs to function and not just the container inside the pod. Skaffold also ensures quick feedback cycles when changing a configuration manifest, which clearly belongs to the realm of pods and not just container. My feeling is that trying to hide away the pod and just focus on the container inside a pod will cause trouble. For example, what about init-containers. It is very common to use pre-built containers to check for database connectivity. If the focus is on built containers only, this will mean that logs from init containers should never be shown, but some users already request to change that (also see #1865). In the end, I think this is something you need to discuss internally because this is a decision of where you are headed with Skaffold. @tejal29 can you bring this up in one of your meetings? I'll most likely not be able to join on Wednesday for the bi-weekly. |
Thoughts/ideas from today's Office Hours:
|
To be realistic, I'll not find time to work on this anytime soon. Also, the design during the discussion in the office hour went in a very different direction, so that a revised version of this design proposal should be discussed on a different PR. Therefore it's overdue to being closed now. But if you miss that capability, give a +1 on the original PR description so that we see if this should be prioritized. |
@corneliusweig just wanted to say thanks for all your work here, this drove some really great conversations that made us think hard about the way we've designed the log tailing in skaffold. you rock! |
@nkubala ❤️ I think you are giving more credit than I deserve. I'm still a bit sad that I didn't have the time to push it through. But it sounds like you are picking up some ideas from here, so the work was not in vain 🎊 |
No description provided.