sapling/eden/fs/telemetry/LogEvent.h
Katie Mancini 3827b9787d add fetch type to data fetch logging
Summary:
Having the type of data fetched can help in debugging where these fetches are
comming from. In the currently logs figuring out if a data fetch is blob or
tree requires some manual work. When looking at a big bunch of fetches this is
not super practical.

So this includes this info in our logging.

Reviewed By: chadaustin

Differential Revision: D23243444

fbshipit-source-id: 9abe5180c5d2afc0d02b27ba6a6b76401e86556e
2020-08-21 17:38:14 -07:00

227 lines
5.6 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include <optional>
#include <string>
#include <unordered_map>
#include "eden/fs/service/gen-cpp2/eden_types.h"
namespace facebook {
namespace eden {
class DynamicEvent {
public:
using IntMap = std::unordered_map<std::string, int64_t>;
using StringMap = std::unordered_map<std::string, std::string>;
using DoubleMap = std::unordered_map<std::string, double>;
DynamicEvent() = default;
DynamicEvent(const DynamicEvent&) = default;
DynamicEvent(DynamicEvent&&) = default;
DynamicEvent& operator=(const DynamicEvent&) = default;
DynamicEvent& operator=(DynamicEvent&&) = default;
void addInt(std::string name, int64_t value);
void addString(std::string name, std::string value);
void addDouble(std::string name, double value);
/**
* Convenience function that adds boolean values as integer 0 or 1.
*/
void addBool(std::string name, bool value) {
addInt(std::move(name), value);
}
const IntMap& getIntMap() const {
return ints_;
}
const StringMap& getStringMap() const {
return strings_;
}
const DoubleMap& getDoubleMap() const {
return doubles_;
}
private:
// Due to limitations in the underlying log database, limit the field types to
// int64_t, double, string, and vector<string>
// TODO: add vector<string> support if needed.
IntMap ints_;
StringMap strings_;
DoubleMap doubles_;
};
struct FetchHeavy {
static constexpr const char* type = "fetch_heavy";
std::string client_cmdline;
pid_t pid;
uint64_t fetch_count;
void populate(DynamicEvent& event) const {
event.addString("client_cmdline", client_cmdline);
event.addInt("client_pid", pid);
event.addInt("fetch_count", fetch_count);
}
};
struct ParentMismatch {
static constexpr const char* type = "parent_mismatch";
std::string mercurial_parent;
std::string eden_parent;
void populate(DynamicEvent& event) const {
event.addString("mercurial_parent", mercurial_parent);
event.addString("eden_parent", eden_parent);
}
};
struct DaemonStart {
static constexpr const char* type = "daemon_start";
double duration = 0.0;
bool is_takeover = false;
bool success = false;
void populate(DynamicEvent& event) const {
event.addDouble("duration", duration);
event.addBool("is_takeover", is_takeover);
event.addBool("success", success);
}
};
struct DaemonStop {
static constexpr const char* type = "daemon_stop";
double duration = 0.0;
bool is_takeover = false;
bool success = false;
void populate(DynamicEvent& event) const {
event.addDouble("duration", duration);
event.addBool("is_takeover", is_takeover);
event.addBool("success", success);
}
};
struct FinishedCheckout {
static constexpr const char* type = "checkout";
std::string mode;
double duration = 0.0;
bool success = false;
int64_t fetchedTrees = 0;
int64_t fetchedBlobs = 0;
void populate(DynamicEvent& event) const {
event.addString("mode", mode);
event.addDouble("duration", duration);
event.addBool("success", success);
event.addInt("fetched_trees", fetchedTrees);
event.addInt("fetched_blobs", fetchedBlobs);
}
};
struct FinishedMount {
static constexpr const char* type = "mount";
std::string repo_type;
std::string repo_source;
bool is_takeover = false;
double duration = 0.0;
bool success = false;
bool clean = false;
void populate(DynamicEvent& event) const {
event.addString("repo_type", repo_type);
event.addString("repo_source", repo_source);
event.addBool("is_takeover", is_takeover);
event.addDouble("duration", duration);
event.addBool("success", success);
event.addBool("clean", clean);
}
};
struct FuseError {
static constexpr const char* type = "fuse_error";
int64_t fuse_op = 0;
int64_t error_code = 0;
void populate(DynamicEvent& event) const {
event.addInt("fuse_op", fuse_op);
event.addInt("error_code", error_code);
}
};
struct RocksDbAutomaticGc {
static constexpr const char* type = "rocksdb_autogc";
double duration = 0.0;
bool success = false;
int64_t size_before = 0;
int64_t size_after = 0;
void populate(DynamicEvent& event) const {
event.addDouble("duration", duration);
event.addBool("success", success);
event.addInt("size_before", size_before);
event.addInt("size_after", size_after);
}
};
struct ThriftError {
static constexpr const char* type = "thrift_error";
std::string thrift_method;
void populate(DynamicEvent& event) const {
event.addString("thrift_method", thrift_method);
}
};
struct ThriftAuthFailure {
static constexpr const char* type = "thrift_auth_failure";
std::string thrift_method;
std::string reason;
void populate(DynamicEvent& event) const {
event.addString("thrift_method", thrift_method);
event.addString("reason", reason);
}
};
struct ServerDataFetch {
static constexpr const char* type = "server_data_fetch";
std::string cause;
std::optional<pid_t> client_pid;
std::optional<std::string> client_cmdline;
std::string fetched_path;
std::string fetched_object_type;
void populate(DynamicEvent& event) const {
event.addString("interface", cause);
if (client_pid) {
event.addInt("client_pid", client_pid.value());
}
if (client_cmdline) {
event.addString("client_cmdline", client_cmdline.value());
}
event.addString("fetched_path", fetched_path);
event.addString("fetched_object_type", fetched_object_type);
}
};
} // namespace eden
} // namespace facebook