syntax = "proto3";

package flyteidl.core;

option go_package = "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core";

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

// Indicates various phases of Workflow Execution
message WorkflowExecution {
    enum Phase {
        UNDEFINED = 0;
        QUEUED = 1;
        RUNNING = 2;
        SUCCEEDING = 3;
        SUCCEEDED = 4;
        FAILING = 5;
        FAILED = 6;
        ABORTED = 7;
        TIMED_OUT = 8;
        ABORTING = 9;
    }
}

// Indicates various phases of Node Execution that only include the time spent to run the nodes/workflows
message NodeExecution {
    enum Phase {
        UNDEFINED = 0;
        QUEUED = 1;
        RUNNING = 2;
        SUCCEEDED = 3;
        FAILING = 4;
        FAILED = 5;
        ABORTED = 6;
        SKIPPED = 7;
        TIMED_OUT = 8;
        DYNAMIC_RUNNING = 9;
        RECOVERED = 10;
    }
}

// Phases that task plugins can go through. Not all phases may be applicable to a specific plugin task,
// but this is the cumulative list that customers may want to know about for their task.
message TaskExecution{
    enum Phase {
        UNDEFINED = 0;
        QUEUED = 1;
        RUNNING = 2;
        SUCCEEDED = 3;
        ABORTED = 4;
        FAILED = 5;
        // To indicate cases where task is initializing, like: ErrImagePull, ContainerCreating, PodInitializing
        INITIALIZING = 6;
        // To address cases, where underlying resource is not available: Backoff error, Resource quota exceeded
        WAITING_FOR_RESOURCES = 7;
    }
}


// Represents the error message from the execution.
message ExecutionError {
    // Error code indicates a grouping of a type of error.
    // More Info: <Link>
    string code = 1;
    // Detailed description of the error - including stack trace.
    string message = 2;
    // Full error contents accessible via a URI
    string error_uri = 3;
    // Error type: System or User
    enum ErrorKind {
        UNKNOWN = 0;
        USER = 1;
        SYSTEM = 2;
    }
    ErrorKind kind = 4;
    // Timestamp of the error
    google.protobuf.Timestamp timestamp = 5;
    // Worker that generated the error
    string worker = 6;
}

// Log information for the task that is specific to a log sink
// When our log story is flushed out, we may have more metadata here like log link expiry
message TaskLog {

    enum MessageFormat {
        UNKNOWN = 0;
        CSV = 1;
        JSON = 2;
    }

    string uri = 1;
    string name = 2;
    MessageFormat message_format = 3;
    google.protobuf.Duration ttl = 4;
    bool ShowWhilePending = 5;
    bool HideOnceFinished = 6;
}

// Contains metadata required to identify logs produces by a set of pods
message LogContext {
    repeated PodLogContext pods = 1;
    string primary_pod_name = 2;
}

// Contains metadata required to identify logs produces by a single pod
message PodLogContext {
    string namespace = 1;

    string pod_name = 2;

    repeated ContainerContext containers = 3;

    string primary_container_name = 4;

    repeated ContainerContext init_containers = 5;
}

// Contains metadata required to identify logs produces by a single container
message ContainerContext {
    string container_name = 1;

    // Contains metadata required to identify logs produces by a single light-weight process that was run inside a container
    message ProcessContext {
        google.protobuf.Timestamp container_start_time = 1;
        google.protobuf.Timestamp container_end_time = 2;
    }

    ProcessContext process = 2;
}

// Represents customized execution run-time attributes.
message QualityOfServiceSpec {
    // Indicates how much queueing delay an execution can tolerate.
    google.protobuf.Duration queueing_budget = 1;

    // Add future, user-configurable options here
}

// Indicates the priority of an execution.
message QualityOfService {
    enum Tier {
        // Default: no quality of service specified.
        UNDEFINED = 0;
        HIGH = 1;
        MEDIUM = 2;
        LOW = 3;
    }

    oneof designation {
        Tier tier = 1;
        QualityOfServiceSpec spec = 2;
    }
}
