syntax = "proto3";

package v1;

import "google/protobuf/wrappers.proto";

// polaris server上报的统计数据
message ServerStatistics {
	google.protobuf.StringValue id = 1; // 唯一标识
	ServerStatisticsKey key = 2; // 维度
	Indicator value = 3; // 指标
}

message ServerStatisticsKey {
	google.protobuf.StringValue server_host = 1; // server地址
	google.protobuf.StringValue resource = 2; // server处理的资源类型，分为Namespace、Service和Instance
	google.protobuf.StringValue operation = 3;	// server对于资源进行的操作，分为创建、查询、修改和删除
	google.protobuf.StringValue code = 4; // server对于资源操作的返回码
	google.protobuf.BoolValue success = 5; // server对于资源操作是否成功
	google.protobuf.StringValue delay_range = 6; // 操作延迟范围，如[3ms, 10ms)
}

// SDK上报的API调用统计
message SDKAPIStatistics {
	google.protobuf.StringValue id = 1; // 唯一标识
	SDKAPIStatisticsKey key = 2; // 维度
	Indicator value = 3; // 指标
}

message SDKAPIStatisticsKey {
	google.protobuf.StringValue client_host = 1; // SDK的ip
	google.protobuf.StringValue sdk_api = 2; // 被调用的api
	google.protobuf.StringValue res_code = 3; // 调用结果码，如果有错误，那么就是具体的错误码，否则为0，表示成功
	google.protobuf.BoolValue success = 4; // API调用是否成功
	google.protobuf.StringValue delay_range = 5; // 操作延迟范围，如[3ms, 10ms)
	google.protobuf.StringValue client_version = 6; // 版本号
	google.protobuf.StringValue client_type = 7; // sdk或agent
	APIResultType result = 8; //api接口调用的的返回类型
}

// server和sdk的上报指标
message Indicator {
	google.protobuf.UInt32Value total_request_per_minute = 1; //总请求数
}

// SDK上报的服务调用统计
message ServiceStatistics {
	google.protobuf.StringValue id = 1; // 唯一标识
	ServiceStatisticsKey key = 2; // 维度
	ServiceIndicator value = 3; // 指标
}

// 服务调用的上报维度
message ServiceStatisticsKey {
	google.protobuf.StringValue caller_host = 1; // 该服务调用者的IP
	google.protobuf.StringValue namespace = 2; // 命名空间
	google.protobuf.StringValue service = 3; // 服务名
	google.protobuf.StringValue instance_host = 4; //具体服务实例ip
	google.protobuf.BoolValue success = 5; // 服务调用是否成功
}

// 服务调用的上报指标
message ServiceIndicator {
	google.protobuf.UInt32Value total_request_per_minute = 1; // 总请求数
	google.protobuf.UInt64Value total_delay_per_minute = 2; // 总延迟
}

//api接口调用
enum APIResultType {
	//未知原因，更新pb后的sdk不得上报这种类型，用于兼容旧版本sdk
	UnknownType = 0;
	//用户调用成功
	Success = 1;
	//由于用户的原因，如参数错误导致的调用错误
	UserFail = 2;
	//由于系统原因（sdk或者server）导致用户调用失败
	PolarisFail = 3;
}
