diff --git a/pkg/app/api/grpcapi/web_api.go b/pkg/app/api/grpcapi/web_api.go index f0eb8e144b..80857efdeb 100644 --- a/pkg/app/api/grpcapi/web_api.go +++ b/pkg/app/api/grpcapi/web_api.go @@ -1309,3 +1309,8 @@ func (a *WebAPI) ListAPIKeys(ctx context.Context, req *webservice.ListAPIKeysReq Keys: apiKeys, }, nil } + +// GetInsightData returns the accumulated insight data. +func (a *WebAPI) GetInsightData(_ context.Context, _ *webservice.GetInsightDataRequest) (*webservice.GetInsightDataResponse, error) { + return nil, status.Error(codes.Unimplemented, "") +} diff --git a/pkg/app/api/service/webservice/service.proto b/pkg/app/api/service/webservice/service.proto index 18e560f296..ceb2b02395 100644 --- a/pkg/app/api/service/webservice/service.proto +++ b/pkg/app/api/service/webservice/service.proto @@ -19,6 +19,7 @@ option go_package = "github.com/pipe-cd/pipe/pkg/app/api/service/webservice"; import "validate/validate.proto"; import "pkg/model/common.proto"; +import "pkg/model/insight.proto"; import "pkg/model/application.proto"; import "pkg/model/application_live_state.proto"; import "pkg/model/command.proto"; @@ -85,6 +86,9 @@ service WebService { rpc GenerateAPIKey(GenerateAPIKeyRequest) returns (GenerateAPIKeyResponse) {} rpc DisableAPIKey(DisableAPIKeyRequest) returns (DisableAPIKeyResponse) {} rpc ListAPIKeys(ListAPIKeysRequest) returns (ListAPIKeysResponse) {} + + // Insights + rpc GetInsightData(GetInsightDataRequest) returns (GetInsightDataResponse) {} } message AddEnvironmentResponse { @@ -401,3 +405,16 @@ message ListAPIKeysRequest { message ListAPIKeysResponse { repeated model.APIKey keys = 1; } + +message GetInsightDataRequest { + pipe.model.InsightMetricsKind metrics_kind = 1 [(validate.rules).enum.defined_only = true]; + pipe.model.InsightStep step = 2 [(validate.rules).enum.defined_only = true]; + int64 range_from = 3 [(validate.rules).int64.gt = 0]; + int64 range_to = 4 [(validate.rules).int64.gt = 0]; + string application_id = 5; +} + +message GetInsightDataResponse { + int64 updated_at = 1; + repeated pipe.model.InsightDataPoint data_points = 2; +} diff --git a/pkg/model/BUILD.bazel b/pkg/model/BUILD.bazel index 2f7dd0e90f..cc55ea480c 100644 --- a/pkg/model/BUILD.bazel +++ b/pkg/model/BUILD.bazel @@ -13,6 +13,7 @@ proto_library( "environment.proto", "event.proto", "logblock.proto", + "insight.proto", "piped.proto", "piped_stats.proto", "project.proto", diff --git a/pkg/model/insight.proto b/pkg/model/insight.proto new file mode 100644 index 0000000000..35a774b4ed --- /dev/null +++ b/pkg/model/insight.proto @@ -0,0 +1,39 @@ +// Copyright 2020 The PipeCD Authors. +// +// 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 pipe.model; +option go_package = "github.com/pipe-cd/pipe/pkg/model"; + +import "validate/validate.proto"; + +message InsightDataPoint { + int64 timestamp = 1 [(validate.rules).int64.gt = 0]; + float value = 2 [(validate.rules).float.gt = 0]; +} + +enum InsightMetricsKind { + DEPLOYMENT_FREQUENCY = 0; + CHANGE_FAILURE_RATE = 1; + MTTR = 2; + LEAD_TIME = 3; +} + +enum InsightStep { + DAILY = 0; + WEEKLY = 1; + MONTHLY = 2; + YEARLY = 3; +}