Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash-on-shutdown around all "CE" powered commands #534

Merged
merged 3 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/vcpkg/base/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ namespace vcpkg::Hash

std::string get_bytes_hash(const void* first, const void* last, Algorithm algo);
std::string get_string_hash(StringView s, Algorithm algo);
std::string get_string_sha256(StringView s);
ExpectedL<std::string> get_file_hash(const Filesystem& fs, const Path& target, Algorithm algo);
}
2 changes: 2 additions & 0 deletions src/vcpkg/base/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ namespace vcpkg::Hash
return get_bytes_hash(sv.data(), sv.data() + sv.size(), algo);
}

std::string get_string_sha256(StringView s) { return get_string_hash(s, Hash::Algorithm::Sha256); }

ExpectedL<std::string> get_file_hash(const Filesystem& fs, const Path& path, Algorithm algo)
{
std::error_code ec;
Expand Down
24 changes: 14 additions & 10 deletions src/vcpkg/commands.add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ namespace vcpkg::Commands
msg::command_line = "vcpkg add artifact");

auto artifact_name = args.command_arguments[1];

auto metrics = LockGuardPtr<Metrics>(g_metrics);
metrics->track_property("command_context", "artifact");
metrics->track_property("command_args", Hash::get_string_hash(artifact_name, Hash::Algorithm::Sha256));
auto artifact_hash = Hash::get_string_hash(artifact_name, Hash::Algorithm::Sha256);
{
auto metrics = LockGuardPtr<Metrics>(g_metrics);
metrics->track_property("command_context", "artifact");
metrics->track_property("command_args", artifact_hash);
} // unlock g_metrics

std::string ce_args[] = {"add", artifact_name};
Checks::exit_with_code(VCPKG_LINE_INFO, run_configure_environment_command(paths, ce_args));
Expand Down Expand Up @@ -135,12 +137,14 @@ namespace vcpkg::Commands
manifest->path, Json::stringify(serialize_manifest(manifest_scf), {}), VCPKG_LINE_INFO);
msg::println(msgAddPortSucceded);

auto metrics = LockGuardPtr<Metrics>(g_metrics);
metrics->track_property("command_context", "port");
metrics->track_property("command_args",
Strings::join(" ", Util::fmap(specs, [](auto&& spec) -> std::string {
return Hash::get_string_hash(spec.name, Hash::Algorithm::Sha256);
})));
auto command_args_hash = Strings::join(" ", Util::fmap(specs, [](auto&& spec) -> std::string {
return Hash::get_string_hash(spec.name, Hash::Algorithm::Sha256);
}));
{
auto metrics = LockGuardPtr<Metrics>(g_metrics);
metrics->track_property("command_context", "port");
metrics->track_property("command_args", command_args_hash);
} // unlock metrics

Checks::exit_success(VCPKG_LINE_INFO);
}
Expand Down
33 changes: 19 additions & 14 deletions src/vcpkg/commands.find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,27 +226,32 @@ namespace vcpkg::Commands
print2(Color::warning, "--x-json has no effect on find artifact\n");
}

auto metrics = LockGuardPtr<Metrics>(g_metrics);
metrics->track_property("command_context", "artifact");
if (filter.has_value())
Optional<std::string> filter_hash = filter.map(Hash::get_string_sha256);
auto args_hash = Hash::get_string_hash(filter.value_or_exit(VCPKG_LINE_INFO), Hash::Algorithm::Sha256);
vicroms marked this conversation as resolved.
Show resolved Hide resolved
{
metrics->track_property(
"command_args",
Hash::get_string_hash(filter.value_or_exit(VCPKG_LINE_INFO), Hash::Algorithm::Sha256));
}
auto metrics = LockGuardPtr<Metrics>(g_metrics);
metrics->track_property("command_context", "artifact");
if (auto p_filter_hash = filter_hash.get())
{
metrics->track_property("command_args", *p_filter_hash);
}
} // unlock metrics

perform_find_artifact_and_exit(paths, filter);
}

if (selector == "port")
{
auto metrics = LockGuardPtr<Metrics>(g_metrics);
metrics->track_property("command_context", "port");
if (filter.has_value())
Optional<std::string> filter_hash = filter.map(Hash::get_string_sha256);
{
metrics->track_property(
"command_args",
Hash::get_string_hash(filter.value_or_exit(VCPKG_LINE_INFO), Hash::Algorithm::Sha256));
}
auto metrics = LockGuardPtr<Metrics>(g_metrics);
metrics->track_property("command_context", "port");
if (auto p_filter_hash = filter_hash.get())
{
metrics->track_property("command_args", *p_filter_hash);
}
} // unlock metrics

perform_find_port_and_exit(paths, full_description, enable_json, filter, args.overlay_ports);
}

Expand Down