Skip to content

Commit 26346a9

Browse files
committed
refactor: don't make METER_TYPE a manifest constant
Instead, attach the actual value to the meterUsage/crankStats record, since that is the most likely place that will change what it means.
1 parent 877ffac commit 26346a9

File tree

4 files changed

+34
-28
lines changed

4 files changed

+34
-28
lines changed

packages/SwingSet/src/kernel/metering.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ export function makeMeterManager(replaceGlobalMeter) {
3939
// console.error(`-- METER REFILL`);
4040
// console.error(` allocate used: ${FULL - refillFacet.getAllocateBalance()}`);
4141
// console.error(` compute used : ${FULL - refillFacet.getComputeBalance()}`);
42-
const used = harden({
42+
const meterUsage = harden({
43+
// TODO: Change this meterType whenever the semantics change.
44+
meterType: 'tame-metering-1',
4345
allocate: FULL - refillFacet.getAllocateBalance(),
4446
compute: FULL - refillFacet.getComputeBalance(),
4547
});
4648
if (meter.isExhausted() && !refillIfExhausted) {
47-
return used;
49+
return meterUsage;
4850
}
4951
refillFacet.allocate();
5052
refillFacet.compute();
5153
refillFacet.stack();
52-
return used;
54+
return meterUsage;
5355
}
5456

5557
if (refillEachCrank) {

packages/SwingSet/src/kernel/vatManager/deliver.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { assert, details as X } from '@agoric/assert';
22
import { insistMessage } from '../../message';
33

4-
const METER_TYPE = 'tame-metering-1';
54
export function makeDeliver(tools, dispatch) {
65
const {
76
meterRecord,
@@ -56,11 +55,13 @@ export function makeDeliver(tools, dispatch) {
5655
// refill this vat's meter, if any, accumulating its usage for stats
5756
if (meterRecord) {
5857
// note that refill() won't actually refill an exhausted meter
59-
status[2] = { ...meterRecord.refill(), meterType: METER_TYPE };
58+
const meterUsage = meterRecord.refill();
6059
const exhaustionError = meterRecord.isExhausted();
6160
if (exhaustionError) {
62-
status = ['error', exhaustionError.message, status[2]];
61+
status = ['error', exhaustionError.message, meterUsage];
6362
} else {
63+
// We will have ['ok', null, meterUsage]
64+
status[2] = meterUsage;
6465
updateStats(status[2]);
6566
}
6667
}

packages/cosmic-swingset/lib/kernel-stats.js

+22-17
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,30 @@ export function makeSlogCallbacks({ metricMeter, labels }) {
117117
});
118118
},
119119
delivery(_method, [vatID], finisher) {
120-
return wrapDeltaMS(finisher, (deltaMS, [[_status, _problem, usage]]) => {
121-
getGroupedMetric('swingset_vat_delivery', { vatID }).record(deltaMS);
122-
if (usage) {
123-
// Add to aggregated metering stats.
124-
const group = { vatID };
125-
for (const [key, value] of Object.entries(usage)) {
126-
if (key === 'meterType') {
127-
// eslint-disable-next-line no-continue
128-
continue;
120+
return wrapDeltaMS(
121+
finisher,
122+
(deltaMS, [[_status, _problem, meterUsage]]) => {
123+
getGroupedMetric('swingset_vat_delivery', { vatID }).record(deltaMS);
124+
if (meterUsage) {
125+
// Add to aggregated metering stats.
126+
const group = { vatID };
127+
for (const [key, value] of Object.entries(meterUsage)) {
128+
if (key === 'meterType') {
129+
// eslint-disable-next-line no-continue
130+
continue;
131+
}
132+
getGroupedMetric(`swingset_meter_usage`, group, {
133+
// The meterType is an instance-specific label--a change in it
134+
// will result in the old value being discarded.
135+
...(meterUsage.meterType && {
136+
meterType: meterUsage.meterType,
137+
}),
138+
stat: key,
139+
}).record(value || 0);
129140
}
130-
getGroupedMetric(`swingset_meter_usage`, group, {
131-
// The meterType is an instance-specific label--a change in it
132-
// will result in the old value being discarded.
133-
...(usage.meterType && { meterType: usage.meterType }),
134-
stat: key,
135-
}).record(value || 0);
136141
}
137-
}
138-
});
142+
},
143+
);
139144
},
140145
};
141146

packages/xsnap/src/xsnap.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ import * as node from './node-stream';
1818
// This will need adjustment, but seems to be fine for a start.
1919
const DEFAULT_CRANK_METERING_LIMIT = 1e7;
2020

21-
// The version identifier for our meter type.
22-
// TODO Bump this whenever there's a change to metering semantics.
23-
const METER_TYPE = 'xs-meter-1';
24-
2521
const OK = '.'.charCodeAt(0);
2622
const ERROR = '!'.charCodeAt(0);
2723
const QUERY = '?'.charCodeAt(0);
@@ -155,7 +151,9 @@ export function xsnap(options) {
155151
compute = JSON.parse(decoder.decode(meterData));
156152
}
157153
const crankStats = {
158-
meterType: METER_TYPE,
154+
// The version identifier for our meter type.
155+
// TODO Bump this whenever there's a change to metering semantics.
156+
meterType: 'xs-meter-1',
159157
allocate: null, // No allocation meter yet.
160158
compute,
161159
};

0 commit comments

Comments
 (0)