syntax = "proto3";

package logcov.proto.logpattern;

option go_package = "logpattern_go_proto";

// The path a package in a repo
message Package {
   // repo name
   // e.g. "tidb", "tikv", "github.com/pingcap/tidb"
   string repo = 1;
   // the path relative to repo root e.g. "pkg/util"
   string path = 2;
   // repo git hash
   string hash = 3;
   // repo git tag
   string tag = 4;
}

// The position of a code byte in the code file
message CodePosition {
   // The line number within code file
   int32 line = 1;
 
   // The column within code file
   int32 column  = 2;
}

// A Position represents a unique location within a repo.
message Position {
   Package package_info = 1;

   // A path-structured label describing the location of this object relative to
   // the repo. For code, this will generally be the relative
   // path to the file containing the log, e.g., "dm/dm-master/service.go" in dm.
   string file_path = 2;

   // The start code byte position
   CodePosition pos = 3;

    // The end code byte position
   CodePosition end_pos = 4;
}

// Function information
message FuncInfo {
   // The function name
   string name = 1;

   // Function definied position
   Position pos = 2;

   // Function code
   bytes code = 3;
}

// A LogPattern represents a log in code file
message LogPattern {
   // log position
   Position pos = 1;
   // The function this log belongs to
   FuncInfo func = 2;
   // log level "info,warn,error" if has
   string level = 3;
   // used to quickly identify the log,
   // e.g. the `format` field of Printf(format string, v ...interface{}) in 
   repeated string signature = 4;
   // the defer log" defer log.Error(...)
   bool is_defer_log = 5;
}

// Coverage data
message Coverage {
   // code position
   Position pos = 1;
   // total count to be covered
   int32 cov_count = 2;
   // the count to be covered in every file
   map<string, int32> cov_count_by_log = 3;
    // log message contain a log example
   string message = 4;
}

// An UnknowLogPattern represents a log pattern that not captured by log extractor
// but exits in log
message UnknowLogPattern {
   // log position
   Position pos = 1;
   // log level "info,warn,error" if has
   string level = 2;
   // total count to be covered
   int32 cov_count = 3;
   // the count to be covered in every file
   map<string, int32> cov_count_by_log = 4;
   // log message contain a log example
   string message = 5;
}

// LogPatternRule is used to filter log printing pattern in the code,
// which is referred to as log pattern.
// usage:
// LogPatternRule.log_level = ["error", "warn"] will filter error or warn level log print pattern
// LogPatternRule.log_signatures = ["network disconnect"] will filter log contains "network disconnect"
message LogPatternRule {
   repeated string log_level = 1;
   repeated string log_signatures = 2;
}
