Skip to content

Commit

Permalink
Rename model
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhtc1202 committed Jul 19, 2021
1 parent f47e845 commit ae07feb
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/app/api/grpcapi/piped_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (a *PipedAPI) ReportStat(ctx context.Context, req *pipedservice.ReportStatR
}

now := time.Now().Unix()
val, err := json.Marshal(model.PipedStat{Timestamp: now, Stats: req.PipedStats})
val, err := json.Marshal(model.PipedStat{PipedId: pipedID, Metrics: req.PipedStats, Timestamp: now})
if err != nil {
a.logger.Error("failed to store the reported piped stat",
zap.String("piped-id", pipedID),
Expand Down
1 change: 1 addition & 0 deletions pkg/app/ops/pipedstatsbuilder/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ go_test(
embed = [":go_default_library"],
deps = [
"//pkg/cache:go_default_library",
"//pkg/model:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
"@org_uber_go_zap//:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/ops/pipedstatsbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func (b *PipedStatsBuilder) Build() (io.Reader, error) {
b.logger.Error("failed to unmarshal piped stat data", zap.Error(err))
return nil, err
}
data = append(data, ps.Stats)
// TODO: Filter returning piped metrics by value timestamp.
data = append(data, ps.Metrics)
}
return bytes.NewReader(bytes.Join(data, []byte("\n"))), nil
}
2 changes: 1 addition & 1 deletion pkg/app/ops/pipedstatsbuilder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (m *mockBuilderBackend) GetAll() (map[string]interface{}, error) {
if err != nil {
return nil, err
}
val, _ := json.Marshal(model.PipedStat{Stats: data, Timestamp: time.Now().Unix()})
val, _ := json.Marshal(model.PipedStat{Metrics: data, Timestamp: time.Now().Unix()})
out[file] = val
}
return out, nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/model/piped_stat.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ option go_package = "github.com/pipe-cd/pipe/pkg/model";
import "validate/validate.proto";

message PipedStat {
int64 timestamp = 1 [(validate.rules).int64.gt = 0];
bytes stats = 2;
string piped_id = 1 [(validate.rules).string.min_len = 1];
bytes metrics = 2;
int64 timestamp = 10 [(validate.rules).int64.gt = 0];
}

0 comments on commit ae07feb

Please sign in to comment.