Skip to content

Commit

Permalink
mergeTags
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 10, 2023
1 parent b0b959f commit 83f29fe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
21 changes: 18 additions & 3 deletions service/pool/Logs.mo
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ module {
};
};
};
// if to is null, delete the from tag
func merge_tag_(map: Map.RBTree<Text,Nat>, from: Text, opt_to: ?Text) {
ignore do ? {
let n1 = map.remove(from)!;
let to = opt_to!;
switch (map.get(to)) {
case null { map.put(to, n1) };
case (?n2) { map.put(to, n1 + n2) };
};
};
};
public func merge_tag(from: Text, to: ?Text) {
merge_tag_(canisters, from, to);
merge_tag_(installs, from, to);
};
public func addCanister(origin: Origin) {
addTags(canisters, ["origin:" # origin.origin]);
addTags(canisters, origin.tags);
Expand All @@ -46,9 +61,9 @@ module {
let install_dfx = get(installs.get("origin:dfx"), 0);
let profiling = get(installs.get("wasm:profiling"), 0);
let asset = get(installs.get("wasm:asset"), 0);
let install = get(installs.get("wasm:mode:install"), 0);
let reinstall = get(installs.get("wasm:mode:reinstall"), 0);
let upgrade = get(installs.get("wasm:mode:upgrade"), 0);
let install = get(installs.get("mode:install"), 0);
let reinstall = get(installs.get("mode:reinstall"), 0);
let upgrade = get(installs.get("mode:upgrade"), 0);
result := result
# encode_single_value("counter", "create_from_playground", canister_playground, "Number of canisters created from playground", now)
# encode_single_value("counter", "install_from_playground", install_playground, "Number of Wasms installed from playground", now)
Expand Down
13 changes: 10 additions & 3 deletions service/pool/Main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ shared (creator) actor class Self(opt_params : ?Types.InitParams) = this {
tags.add("wasm:asset");
};
switch (args.mode) {
case (#install) { tags.add("wasm:mode:install") };
case (#upgrade) { tags.add("wasm:mode:upgrade") };
case (#reinstall) { tags.add("wasm:mode:reinstall") };
case (#install) { tags.add("mode:install") };
case (#upgrade) { tags.add("mode:upgrade") };
case (#reinstall) { tags.add("mode:reinstall") };
};
let origin = { origin = install_config.origin.origin; tags = Buffer.toArray(tags) };
statsByOrigin.addInstall(origin);
Expand Down Expand Up @@ -274,6 +274,12 @@ shared (creator) actor class Self(opt_params : ?Types.InitParams) = this {
stats := Logs.defaultStats;
statsByOrigin := Logs.StatsByOrigin();
};
public shared ({ caller }) func mergeTags(from: Text, to: ?Text) : async () {
if (caller != controller) {
throw Error.reject "Only called by controller";
};
statsByOrigin.merge_tag(from, to);
};

// Metrics
public query func http_request(req : Metrics.HttpRequest) : async Metrics.HttpResponse {
Expand Down Expand Up @@ -427,6 +433,7 @@ shared (creator) actor class Self(opt_params : ?Types.InitParams) = this {
#installCode : Any;
#removeCode : Any;
#resetStats : Any;
#mergeTags : Any;
#wallet_receive : Any;

#create_canister : Any;
Expand Down
2 changes: 1 addition & 1 deletion src/components/DeployModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export function DeployModal({

async function addTags() {
if (initTypes.length > 0) {
await dispatch({ type: "addSessionTag", payload: "moc:init_args" });
await dispatch({ type: "addSessionTag", payload: "wasm:init_args" });
}
if (forceGC) {
await dispatch({ type: "addSessionTag", payload: "moc:gc:force" });
Expand Down

0 comments on commit 83f29fe

Please sign in to comment.