16 #include "tensorflow_serving/servables/tensorflow/machine_learning_metadata.h"
18 #include "tensorflow/cc/saved_model/constants.h"
19 #include "tensorflow/core/lib/io/path.h"
20 #include "tensorflow/core/lib/monitoring/gauge.h"
21 #include "tensorflow/core/lib/strings/strcat.h"
23 namespace tensorflow {
28 static constexpr
char kMLMDKeyFile[] =
"mlmd_uuid";
30 auto* mlmd_map = monitoring::Gauge<string, 2>::New(
31 "/tensorflow/serving/mlmd_map",
32 "Mapping for ML Metadata UUID to model_name and version.",
"model_name",
37 void MaybePublishMLMDStreamz(
const string& export_dir,
const string& model_name,
39 const string mlmd_path = tensorflow::io::JoinPath(
40 export_dir, tensorflow::kSavedModelAssetsExtraDirectory, kMLMDKeyFile);
41 if (tsl::Env::Default()->FileExists(mlmd_path).ok()) {
43 auto status = ReadFileToString(tsl::Env::Default(), mlmd_path, &mlmd_key);
45 LOG(WARNING) <<
"ML Metadata Key Found But couldn't be read.";
47 mlmd_map->GetCell(model_name, strings::StrCat(version))->Set(mlmd_key);