vectordotdev / helm-charts

Helm charts for Vector.
https://vector.dev
Mozilla Public License 2.0
114 stars 89 forks source link

Use container resource.requests.cpu to populate VECTOR_THREADS #335

Closed ypid-work closed 1 year ago

ypid-work commented 1 year ago

I tested if Vector 0.33.0 can detect resource.requests.cpu from the Kubernetes pod it is running in. It or rather std::thread::available_parallelism() cannot. I then came up with:

    env:
      # Vector as of 0.33.0 is not aware of CPU requests.
      # Ref: https://vector.dev/highlights/2023-09-27-0-33-0-upgrade-guide/#potentially-impactful-changes
      - name: VECTOR_THREADS
        valueFrom:
           resourceFieldRef:
             containerName: robin-interactive-debugging
             resource: requests.cpu
             # No CPU fractions. Round up to get int.
             divisor: 1

Works nicely. Only thing to note, if a pod has no CPU request set, it sets the variable to 0 and vector is not happy about that. But that is something that can be solved with gotemplate.

I cannot contribute a PR but thought I would share this snippet. I am testing it starting now.

Ref: https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/#store-container-fields Ref: https://vector.dev/highlights/2023-09-27-0-33-0-upgrade-guide/#runtime-worker-threads

ypid-work commented 1 year ago

I did not consider that vector container should be allowed to use more CPU than what it requests as needed and unused capacity is there. So setting VECTOR_THREADS to CPU request is a bad idea as it would prevent that. I am closing this. The vector default is perfectly fine.

jszwedko commented 1 year ago

Thanks for following up @ypid-work !