/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

syntax = "proto3";

package luci.resultdb.v1;

import "google/api/field_behavior.proto";
import "google/protobuf/timestamp.proto";
import public "tools/tradefederation/core/proto/resultdb/test_result.proto";
import public "tools/tradefederation/core/proto/resultdb/common.proto";

option go_package = "go.chromium.org/luci/resultdb/proto/v1;resultpb";
option java_package = "com.android.resultdb.proto";
option java_multiple_files = true;

// A file produced during a build/test, typically a test artifact.
// The parent resource is either a TestResult or an Invocation.
//
// An invocation-level artifact might be related to tests, or it might not, for
// example it may be used to store build step logs when streaming support is
// added.
// Next id: 16.
message Artifact {
  // Can be used to refer to this artifact.
  // Format:
  // - For invocation-level artifacts:
  //   "invocations/{INVOCATION_ID}/artifacts/{ARTIFACT_ID}".
  // - For test-result-level artifacts:
  //   "invocations/{INVOCATION_ID}/tests/{URL_ESCAPED_TEST_ID}/results/{RESULT_ID}/artifacts/{ARTIFACT_ID}".
  // where URL_ESCAPED_TEST_ID is the test_id escaped with
  // https://golang.org/pkg/net/url/#PathEscape (see also https://aip.dev/122),
  // and ARTIFACT_ID is documented below.
  // Examples: "screenshot.png", "traces/a.txt".
  string name = 1 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.field_behavior) = IMMUTABLE
  ];

  // The structured test identifier. Uniquely identifies the test that was run.
  //
  // This field is only populated for test-result-level artifacts.
  // MUST set if result_id is set.
  // MUST NOT set for legacy uploader where test id should be specified in the parent.
  TestIdentifier test_id_structured = 12 [(google.api.field_behavior) = IMMUTABLE];

  // A unique identifier of the test in a LUCI project, excluding variant.
  // Regex: ^[[::print::]]{1,512}$
  //
  // This is the flat-form encoding of the test_id_structured above,
  // only populated for test-result-level artifacts.
  // See TestIdentifier for details how a structured test identifier is converted
  // to flat test ID.
  //
  // Output only.
  string test_id = 13 [(google.api.field_behavior) = OUTPUT_ONLY, (google.api.field_behavior) = IMMUTABLE];

  // This field is only populated for test-result-level artifacts.
  // MUST set if test_id_structured is set.
  // MUST NOT set for legacy uploader where result id should be specified in the parent.
  string result_id = 14 [(google.api.field_behavior) = IMMUTABLE];

  // A local identifier of the artifact, unique within the parent resource.
  // MAY have slashes, but MUST NOT start with a slash.
  // SHOULD not use backslashes.
  // Regex: ^(?:[[:word:]]|\.)([\p{L}\p{M}\p{N}\p{P}\p{S}\p{Zs}]{0,254}[[:word:]])?$
  string artifact_id = 2;

  // A signed short-lived URL to fetch the contents of the artifact.
  // See also fetch_url_expiration.
  //
  // While the fetch_url will be returned by default, in some cases it may introduce significantly
  // higher latency and potentially trigger errors if quota limits are exceeded.
  // Thus please mask fetch_url unless you are actually going to use it.
  string fetch_url = 3;

  // When fetch_url expires. If expired, re-request this Artifact.
  google.protobuf.Timestamp fetch_url_expiration = 4;

  // Media type of the artifact.
  // Logs are typically "text/plain" and screenshots are typically "image/png".
  // Optional.
  string content_type = 5;

  // Size of the file.
  // Can be used in UI to decide between displaying the artifact inline or only
  // showing a link if it is too large.
  // If you are using the gcs_uri, this field is not verified, but only treated as a hint.
  int64 size_bytes = 6;

  // Contents of the artifact.
  // This is INPUT_ONLY, and taken by BatchCreateArtifacts().
  // All getter RPCs, such as ListArtifacts(), do not populate values into
  // the field in the response.
  // If specified, `gcs_uri` must be empty.
  bytes contents = 7 [ (google.api.field_behavior) = INPUT_ONLY ];

  // The GCS URI of the artifact if it's stored in GCS. If specified, `contents`
  // and `rbe_uri` must be empty.
  string gcs_uri = 8;

  // Status of the test result that the artifact belongs to.
  // This is only applicable for test-level artifacts, not invocation-level artifacts.
  // Deprecated: This field is ignored by ResultDB and not set.
  TestStatus test_status = 9 [ deprecated = true ];

  // Indicates whether ListArtifactLines RPC can be used with this artifact.
  bool has_lines = 11;

  // The RBE URI of the artifact if it's stored in RBE. If specified, `contents`
  // and `gcs_uri` must be empty.
  string rbe_uri = 15;
}

message ArtifactLine {
  enum Severity {
    SEVERITY_UNSPECIFIED = 0;
    VERBOSE = 10;
    TRACE = 20;
    DEBUG = 30;
    INFO = 40;
    NOTICE = 50;
    WARNING = 60;
    ERROR = 70;
    CRITICAL = 80;
    FATAL = 90;
  }

  // The position of this line in the artifact.
  // The numbers start from 1.
  int64 number = 1;

  // The extracted timestamp of the log line. Extraction is best effort only.
  google.protobuf.Timestamp timestamp = 2;

  // The extracted severity of the line. Extraction is best effort only.
  Severity severity = 3;

  // The content of the line as it is found in the log file.
  // Lines are split on the \n character and the character is included in the line content that immediately precedes it.
  // Empty lines will be included in the response.
  bytes content = 4;
}
