Skip to content

Commit c582420

Browse files
easyCZroboquat
authored andcommitted
[usage] Fix BilledSession credits precision
1 parent 5137505 commit c582420

File tree

6 files changed

+70
-24
lines changed

6 files changed

+70
-24
lines changed

components/usage-api/go/v1/usage.pb.go

Lines changed: 29 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/usage-api/typescript/src/usage/v1/usage_pb.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ export class BilledSession extends jspb.Message {
103103
clearEndTime(): void;
104104
getEndTime(): google_protobuf_timestamp_pb.Timestamp | undefined;
105105
setEndTime(value?: google_protobuf_timestamp_pb.Timestamp): BilledSession;
106+
getCreditsDeprecated(): number;
107+
setCreditsDeprecated(value: number): BilledSession;
106108
getCredits(): number;
107109
setCredits(value: number): BilledSession;
108110

@@ -128,6 +130,7 @@ export namespace BilledSession {
128130
workspaceClass: string,
129131
startTime?: google_protobuf_timestamp_pb.Timestamp.AsObject,
130132
endTime?: google_protobuf_timestamp_pb.Timestamp.AsObject,
133+
creditsDeprecated: number,
131134
credits: number,
132135
}
133136
}

components/usage-api/typescript/src/usage/v1/usage_pb.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ proto.usage.v1.BilledSession.toObject = function(includeInstance, msg) {
562562
workspaceClass: jspb.Message.getFieldWithDefault(msg, 8, ""),
563563
startTime: (f = msg.getStartTime()) && google_protobuf_timestamp_pb.Timestamp.toObject(includeInstance, f),
564564
endTime: (f = msg.getEndTime()) && google_protobuf_timestamp_pb.Timestamp.toObject(includeInstance, f),
565-
credits: jspb.Message.getFieldWithDefault(msg, 11, 0)
565+
creditsDeprecated: jspb.Message.getFieldWithDefault(msg, 11, 0),
566+
credits: jspb.Message.getFloatingPointFieldWithDefault(msg, 12, 0.0)
566567
};
567568

568569
if (includeInstance) {
@@ -643,6 +644,10 @@ proto.usage.v1.BilledSession.deserializeBinaryFromReader = function(msg, reader)
643644
break;
644645
case 11:
645646
var value = /** @type {number} */ (reader.readInt64());
647+
msg.setCreditsDeprecated(value);
648+
break;
649+
case 12:
650+
var value = /** @type {number} */ (reader.readDouble());
646651
msg.setCredits(value);
647652
break;
648653
default:
@@ -746,13 +751,20 @@ proto.usage.v1.BilledSession.serializeBinaryToWriter = function(message, writer)
746751
google_protobuf_timestamp_pb.Timestamp.serializeBinaryToWriter
747752
);
748753
}
749-
f = message.getCredits();
754+
f = message.getCreditsDeprecated();
750755
if (f !== 0) {
751756
writer.writeInt64(
752757
11,
753758
f
754759
);
755760
}
761+
f = message.getCredits();
762+
if (f !== 0.0) {
763+
writer.writeDouble(
764+
12,
765+
f
766+
);
767+
}
756768
};
757769

758770

@@ -975,10 +987,10 @@ proto.usage.v1.BilledSession.prototype.hasEndTime = function() {
975987

976988

977989
/**
978-
* optional int64 credits = 11;
990+
* optional int64 credits_deprecated = 11;
979991
* @return {number}
980992
*/
981-
proto.usage.v1.BilledSession.prototype.getCredits = function() {
993+
proto.usage.v1.BilledSession.prototype.getCreditsDeprecated = function() {
982994
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 11, 0));
983995
};
984996

@@ -987,9 +999,27 @@ proto.usage.v1.BilledSession.prototype.getCredits = function() {
987999
* @param {number} value
9881000
* @return {!proto.usage.v1.BilledSession} returns this
9891001
*/
990-
proto.usage.v1.BilledSession.prototype.setCredits = function(value) {
1002+
proto.usage.v1.BilledSession.prototype.setCreditsDeprecated = function(value) {
9911003
return jspb.Message.setProto3IntField(this, 11, value);
9921004
};
9931005

9941006

1007+
/**
1008+
* optional double credits = 12;
1009+
* @return {number}
1010+
*/
1011+
proto.usage.v1.BilledSession.prototype.getCredits = function() {
1012+
return /** @type {number} */ (jspb.Message.getFloatingPointFieldWithDefault(this, 12, 0.0));
1013+
};
1014+
1015+
1016+
/**
1017+
* @param {number} value
1018+
* @return {!proto.usage.v1.BilledSession} returns this
1019+
*/
1020+
proto.usage.v1.BilledSession.prototype.setCredits = function(value) {
1021+
return jspb.Message.setProto3FloatField(this, 12, value);
1022+
};
1023+
1024+
9951025
goog.object.extend(exports, proto.usage.v1);

components/usage-api/usage/v1/usage.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@ message BilledSession {
4949
google.protobuf.Timestamp start_time = 9;
5050
google.protobuf.Timestamp end_time = 10;
5151

52-
int64 credits = 11;
52+
int64 credits_deprecated = 11 [deprecated=true]; // insufficient precision to represent credits for workspace time
53+
double credits = 12;
5354
}

components/usage/go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
517517
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
518518
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
519519
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
520-
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
521520
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
522521
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
523522
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

components/usage/pkg/apiv1/usage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (us *UsageService) ListBilledUsage(ctx context.Context, in *v1.ListBilledUs
7878
WorkspaceClass: usageRecord.WorkspaceClass,
7979
StartTime: timestamppb.New(usageRecord.StartedAt),
8080
EndTime: endTime,
81-
Credits: int64(usageRecord.CreditsUsed),
81+
Credits: usageRecord.CreditsUsed,
8282
}
8383
billedSessions = append(billedSessions, billedSession)
8484
}

0 commit comments

Comments
 (0)