chaostoolkit / chaostoolkit-kubernetes

Kubernetes driver extension of the Chaos Toolkit probes and actions API
https://chaostoolkit.org/drivers/kubernetes/
Apache License 2.0
189 stars 79 forks source link

Is there a way to check tolerance against read_pod_logs? #95

Open myroslavrozum opened 4 years ago

myroslavrozum commented 4 years ago

Hello, I wanted to check logs returned by read_pod_logs with regex but getting the error: "return rx.search(value) is not None". My probe was similar to:

{
   "name": "read-microservices-logs",
   "type": "probe",
   "tolerance": {
      "type": "regex,",
      "pattern": "UP"
   },
   "provider": {
      "func": "read_pod_logs",
      "arguments": {
         "label_selector": "app.kubernetes.io/name=ui",
         "ns": "dev",
         "container_name": "ui"
      },
      "module": "chaosk8s.probes",
      "type": "python"
   }
}

But got an error: File "/opt/hostedtoolcache/Python/3.8.1/x64/lib/python3.8/site-packages/chaoslib/hypothesis.py", line 304, in _ return rx.search(value) is not None TypeError: expected string or bytes-like object

Can it be caused by function returning dictionary instead of string?

myroslavrozum commented 4 years ago

I believe I found an answer to my question, and the answer is "yes, in general but...". You can pass pod's name as a target to read_pod_logs: https://github.com/chaostoolkit/chaostoolkit-lib/blob/master/chaoslib/hypothesis.py#L302 So just adding:

{
   "name": "read-microservices-logs",
   "type": "probe",
   "tolerance": {
      "type": "regex,",
      "pattern": "UP"
      "target": ui-849869f549-gyhbc
   },
   "provider": {
      "func": "read_pod_logs",
      "arguments": {
         "label_selector": "app.kubernetes.io/name=ui",
         "ns": "dev",
         "container_name": "ui"
      },
      "module": "chaosk8s.probes",
      "type": "python"
   }
}

worked but it's not really useful since pod names are dynamic. Should'n it be replaced with container's name instead?