Skip to content

Commit

Permalink
chore: dump previous logs as well
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Nov 7, 2024
1 parent 7e8abfa commit ba7cc7a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 25 deletions.
4 changes: 0 additions & 4 deletions charts/ftl/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ runner:
valueFrom:
fieldRef:
fieldPath: status.hostIP
# - name: OTEL_EXPORTER_OTLP_ENDPOINT
# value: "http://$(HOST_IP):4317"
# - name: OTEL_RESOURCE_ATTRIBUTES
# value: "env=ftlDefault"

ports:
- name: http
Expand Down
6 changes: 5 additions & 1 deletion deployment/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ controller:
ports:
- name: "http-8891"
port: 8891

runner:
podAnnotations:
proxy.istio.io/config: |
holdApplicationUntilProxyStarts: true
sidecar.istio.io/logLevel: "debug"

provisioner:
enabled: true
Expand Down
81 changes: 61 additions & 20 deletions internal/integration/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,29 +542,70 @@ func dumpKubePods(ctx context.Context, kubeClient optional.Option[kubernetes.Cli
continue
}
for _, container := range pod.Spec.Containers {
path := filepath.Join(dumpPath, pod.Name, container.Name+".log")
req := client.CoreV1().Pods(kubeNamespace).GetLogs(pod.Name, &kubecore.PodLogOptions{Container: container.Name})
podLogs, err := req.Stream(context.Background())
if err != nil {
Infof("Error getting logs for pod %s: %v", pod.Name, err)
continue
}
defer func() {
_ = podLogs.Close()
}()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, podLogs)
if err != nil {
Infof("Error copying logs for pod %s: %v", pod.Name, err)
continue
}
str := buf.String()
err = os.WriteFile(path, []byte(str), 0644) // #nosec
if err != nil {
Infof("Error writing logs for pod %s: %v", pod.Name, err)
for _, prev := range []bool{false, true} {
var path string
if prev {
path = filepath.Join(dumpPath, pod.Name, container.Name+"-previous.log")
} else {
path = filepath.Join(dumpPath, pod.Name, container.Name+".log")
}
req := client.CoreV1().Pods(kubeNamespace).GetLogs(pod.Name, &kubecore.PodLogOptions{Container: container.Name, Previous: prev})
podLogs, err := req.Stream(context.Background())
if err != nil {
if prev {
// This is pretty normal not to have previous logs
continue
}
Infof("Error getting logs for pod %s: %v previous: %v", pod.Name, err, prev)
continue
}
defer func() {
_ = podLogs.Close()
}()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, podLogs)
if err != nil {
Infof("Error copying logs for pod %s: %v", pod.Name, err)
continue
}
str := buf.String()
err = os.WriteFile(path, []byte(str), 0644) // #nosec
if err != nil {
Infof("Error writing logs for pod %s: %v", pod.Name, err)
}

}

}
}
}
istio, err := k8sscaling.CreateIstioClientSet()
if err != nil {
Infof("Error creating istio clientset: %v", err)
return
}
auths, err := istio.SecurityV1().AuthorizationPolicies(kubeNamespace).List(ctx, kubemeta.ListOptions{})
if err == nil {
for _, policy := range auths.Items {
Infof("Dumping yamp for auth policy %s", policy.Name)
policyPath := filepath.Join(dumpPath, policy.Name)
err := os.MkdirAll(policyPath, 0755) // #nosec
if err != nil {
Infof("Error creating directory %s: %v", policyPath, err)
continue
}
podYaml, err := yaml.Marshal(policy)
if err != nil {
Infof("Error marshalling pod %s: %v", policy.Name, err)
continue
}
err = os.WriteFile(filepath.Join(policyPath, "pod.yaml"), podYaml, 0644) // #nosec
if err != nil {
Infof("Error writing policy %s: %v", policy.Name, err)
continue
}

}
}
}
}

0 comments on commit ba7cc7a

Please sign in to comment.