Skip to content
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

Triggering long running background jobs when events occurs #7732

Open
pierDipi opened this issue Feb 28, 2024 · 9 comments
Open

Triggering long running background jobs when events occurs #7732

pierDipi opened this issue Feb 28, 2024 · 9 comments
Assignees
Labels
kind/feature-request triage/accepted Issues which should be fixed (post-triage)

Comments

@pierDipi
Copy link
Member

pierDipi commented Feb 28, 2024

Problem

Usually event processing combined with a Knative Service is expected to complete in a relative short period of time (minutes) as it requires the HTTP connection to stay open as otherwise the service is scaled down and keeping long running connections open increases the possibility of failing and so the processing needs to restart as the request is retried.

This limitation is not ideal, therefore providing a resource (JobSink) which will trigger a long running job when an event occurs might be a good alternative vehicle.

Example JobSink API:

apiVersion: sinks.knative.dev/v1alpha1
kind: JobSink
metadata:
  name: job-sink-success
spec:
  job:
    apiVersion: batch/v1
    kind: Job
    spec:
      completions: 12
      parallelism: 3
      template:
        spec:
          restartPolicy: Never
          containers:
            - name: main
              image: docker.io/library/bash:5
              command: [ "bash" ] 
              args:
                - -c
                - echo "Hello world!" && sleep 5
      backoffLimit: 6
      podFailurePolicy:
        rules:
          - action: FailJob
            onExitCodes:
              containerName: main      # optional
              operator: In             # one of: In, NotIn
              values: [ 42 ]
          - action: Ignore             # one of: Ignore, FailJob, Count
            onPodConditions:
              - type: DisruptionTarget   # indicates Pod disruption

Possible Client UX

We could provide kn client UX which would take a k8s job and turn it into a jobsink as creating a Job might be easier with existing IDE tooling:

kn jobsink create --from-job-file=job.yaml -oyaml > jobsink.yaml

Persona:
Which persona is this feature for?

Developers

Exit Criteria
A measurable (binary) test that would indicate that the problem has been resolved.

Time Estimate (optional):
How many developer-days do you think this may take to resolve?

10

Additional context (optional)
Add any other context about the feature request here.

@fsedano
Copy link

fsedano commented Mar 22, 2024

/assign

@fsedano
Copy link

fsedano commented Mar 22, 2024

@pierDipi as discussed in Kubecon -- This is my main use case, so I'd like to work on solving this issue.

@pierDipi
Copy link
Member Author

pierDipi commented Mar 25, 2024

Thanks @fsedano feel free to go ahead, here is my PoC branch on my fork https://github.com/pierDipi/eventing/tree/jobsink

@pierDipi
Copy link
Member Author

/triage accepted

@knative-prow knative-prow bot added the triage/accepted Issues which should be fixed (post-triage) label Mar 25, 2024
@fsedano
Copy link

fsedano commented Apr 9, 2024

Before working on this, I think we should fix an underlying issue being discussed here:

knative/serving#13075

Because of this, the premise "as it requires the HTTP connection to stay open as otherwise the service is scaled down " is not 100% true -- Keeping the HTTP open won't guarantee the pod is not killed.

@Cali0707
Copy link
Member

@fsedano I think the idea of this proposal was to create a k8s Job resource, instead of a Knative service (correct me if I'm wrong @pierDipi ). That way, this limitation would not be an issue

@pierDipi
Copy link
Member Author

pierDipi commented Apr 12, 2024

Yes, that's what the POC also does, it creates a job for each received event. A received event is mounted as a JSON file volume to each job

@mroberts91
Copy link

@fsedano, Are you still actively working on this feature? If so, I'd like to know your timeframe.

I see a lot of value in this feature and am trying to determine whether it is worth waiting for its release or writing a one-off job handler for a current use case.

@fsedano
Copy link

fsedano commented May 22, 2024

@mroberts91 before working on this I want to handle the regular UX described here: knative/serving#13075 (which is impacting my use case)

Would that also help you? Or do you need the job route as discussed here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature-request triage/accepted Issues which should be fixed (post-triage)
Projects
Status: In Progress
Development

No branches or pull requests

4 participants