summaryrefslogtreecommitdiffstats
path: root/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp')
-rw-r--r--searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp137
1 files changed, 72 insertions, 65 deletions
diff --git a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp
index e72771f5aa6..dcfbc34653d 100644
--- a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp
+++ b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp
@@ -1,5 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include "verify_ranksetup.h"
#include "config-verify-ranksetup.h"
#include <vespa/config-attributes.h>
#include <vespa/config-indexschema.h>
@@ -21,12 +22,10 @@
#include <vespa/searchlib/fef/fef.h>
#include <vespa/searchlib/fef/test/plugin/setup.h>
#include <vespa/config/subscription/configsubscriber.hpp>
-#include <vespa/vespalib/util/signalhandler.h>
+#include <vespa/vespalib/util/stringfmt.h>
+#include <vespa/vespalib/stllike/asciistream.h>
#include <optional>
-#include <vespa/log/log.h>
-LOG_SETUP("vespa-verify-ranksetup");
-
using config::ConfigContext;
using config::ConfigHandle;
using config::ConfigRuntimeException;
@@ -50,8 +49,10 @@ using vespalib::eval::SimpleConstantValue;
using vespalib::eval::TensorSpec;
using vespalib::eval::Value;
using vespalib::eval::ValueType;
+using vespalib::make_string_short::fmt;
-std::optional<vespalib::string> get_file(const vespalib::string &ref, const VerifyRanksetupConfig &myCfg) {
+std::optional<vespalib::string>
+get_file(const vespalib::string &ref, const VerifyRanksetupConfig &myCfg) {
for (const auto &entry: myCfg.file) {
if (ref == entry.ref) {
return entry.path;
@@ -60,37 +61,43 @@ std::optional<vespalib::string> get_file(const vespalib::string &ref, const Veri
return std::nullopt;
}
-RankingExpressions make_expressions(const RankingExpressionsConfig &expressionsCfg, const VerifyRanksetupConfig &myCfg) {
+RankingExpressions
+make_expressions(const RankingExpressionsConfig &expressionsCfg, const VerifyRanksetupConfig &myCfg,
+ std::vector<search::fef::Message> & messages) {
RankingExpressions expressions;
for (const auto &entry: expressionsCfg.expression) {
if (auto file = get_file(entry.fileref, myCfg)) {
- LOG(debug, "Add expression %s with ref=%s and path=%s", entry.name.c_str(), entry.fileref.c_str(), file.value().c_str());
expressions.add(entry.name, file.value());
} else {
- LOG(warning, "could not find file name for ranking expression '%s' (ref:'%s')",
- entry.name.c_str(), entry.fileref.c_str());
+ messages.emplace_back(search::fef::Level::WARNING,
+ fmt("could not find file name for ranking expression '%s' (ref:'%s')",
+ entry.name.c_str(), entry.fileref.c_str()));
}
}
return expressions;
}
-OnnxModels make_models(const OnnxModelsConfig &modelsCfg, const VerifyRanksetupConfig &myCfg) {
+OnnxModels
+make_models(const OnnxModelsConfig &modelsCfg, const VerifyRanksetupConfig &myCfg,
+ std::vector<search::fef::Message> & messages) {
OnnxModels::Vector model_list;
for (const auto &entry: modelsCfg.model) {
if (auto file = get_file(entry.fileref, myCfg)) {
model_list.emplace_back(entry.name, file.value());
OnnxModels::configure(entry, model_list.back());
} else {
- LOG(warning, "could not find file name for onnx model '%s' (ref:'%s')",
- entry.name.c_str(), entry.fileref.c_str());
+ messages.emplace_back(search::fef::Level::WARNING,
+ fmt("could not find file name for onnx model '%s' (ref:'%s')",
+ entry.name.c_str(), entry.fileref.c_str()));
}
}
return OnnxModels(model_list);
}
-class App
+class VerifyRankSetup
{
-public:
+private:
+ std::vector<search::fef::Message> _messages;
bool verify(const search::index::Schema &schema,
const search::fef::Properties &props,
const IConstantValueRepo &repo,
@@ -105,30 +112,42 @@ public:
const RankingExpressionsConfig &expressionsCfg,
const OnnxModelsConfig &modelsCfg);
- int usage();
- int main(int argc, char **argv);
+public:
+ VerifyRankSetup();
+ ~VerifyRankSetup();
+ const std::vector<search::fef::Message> & getMessages() const { return _messages; }
+ bool verify(const std::string & configId);
};
struct DummyConstantValueRepo : IConstantValueRepo {
const RankingConstantsConfig &cfg;
DummyConstantValueRepo(const RankingConstantsConfig &cfg_in) : cfg(cfg_in) {}
- virtual vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &name) const override {
- for (const auto &entry: cfg.constant) {
- if (entry.name == name) {
- try {
- auto tensor = vespalib::eval::value_from_spec(TensorSpec(entry.type), FastValueBuilderFactory::get());
- return std::make_unique<SimpleConstantValue>(std::move(tensor));
- } catch (std::exception &) {
- return std::make_unique<BadConstantValue>();
- }
+ vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &name) const override;
+};
+
+vespalib::eval::ConstantValue::UP
+DummyConstantValueRepo::getConstant(const vespalib::string &name) const {
+ for (const auto &entry: cfg.constant) {
+ if (entry.name == name) {
+ try {
+ auto tensor = vespalib::eval::value_from_spec(TensorSpec(entry.type), FastValueBuilderFactory::get());
+ return std::make_unique<SimpleConstantValue>(std::move(tensor));
+ } catch (std::exception &) {
+ return std::make_unique<BadConstantValue>();
}
}
- return vespalib::eval::ConstantValue::UP(nullptr);
}
-};
+ return vespalib::eval::ConstantValue::UP(nullptr);
+}
+
+VerifyRankSetup::VerifyRankSetup()
+ : _messages()
+{ }
+
+VerifyRankSetup::~VerifyRankSetup() = default;
bool
-App::verify(const search::index::Schema &schema,
+VerifyRankSetup::verify(const search::index::Schema &schema,
const search::fef::Properties &props,
const IConstantValueRepo &repo,
const RankingExpressions &expressions,
@@ -143,25 +162,25 @@ App::verify(const search::index::Schema &schema,
rankSetup.configure(); // reads config values from the property map
bool ok = true;
if (!rankSetup.getFirstPhaseRank().empty()) {
- ok = verifyFeature(factory, indexEnv, rankSetup.getFirstPhaseRank(), "first phase ranking") && ok;
+ ok = verifyFeature(factory, indexEnv, rankSetup.getFirstPhaseRank(), "first phase ranking", _messages) && ok;
}
if (!rankSetup.getSecondPhaseRank().empty()) {
- ok = verifyFeature(factory, indexEnv, rankSetup.getSecondPhaseRank(), "second phase ranking") && ok;
+ ok = verifyFeature(factory, indexEnv, rankSetup.getSecondPhaseRank(), "second phase ranking", _messages) && ok;
}
for (size_t i = 0; i < rankSetup.getSummaryFeatures().size(); ++i) {
- ok = verifyFeature(factory, indexEnv, rankSetup.getSummaryFeatures()[i], "summary features") && ok;
+ ok = verifyFeature(factory, indexEnv, rankSetup.getSummaryFeatures()[i], "summary features", _messages) && ok;
}
for (const auto & feature : rankSetup.get_match_features()) {
- ok = verifyFeature(factory, indexEnv, feature, "match features") && ok;
+ ok = verifyFeature(factory, indexEnv, feature, "match features", _messages) && ok;
}
for (size_t i = 0; i < rankSetup.getDumpFeatures().size(); ++i) {
- ok = verifyFeature(factory, indexEnv, rankSetup.getDumpFeatures()[i], "dump features") && ok;
+ ok = verifyFeature(factory, indexEnv, rankSetup.getDumpFeatures()[i], "dump features", _messages) && ok;
}
return ok;
}
bool
-App::verifyConfig(const VerifyRanksetupConfig &myCfg,
+VerifyRankSetup::verifyConfig(const VerifyRanksetupConfig &myCfg,
const RankProfilesConfig &rankCfg,
const IndexschemaConfig &schemaCfg,
const AttributesConfig &attributeCfg,
@@ -174,8 +193,8 @@ App::verifyConfig(const VerifyRanksetupConfig &myCfg,
search::index::SchemaBuilder::build(schemaCfg, schema);
search::index::SchemaBuilder::build(attributeCfg, schema);
DummyConstantValueRepo repo(constantsCfg);
- auto expressions = make_expressions(expressionsCfg, myCfg);
- auto models = make_models(modelsCfg, myCfg);
+ auto expressions = make_expressions(expressionsCfg, myCfg, _messages);
+ auto models = make_models(modelsCfg, myCfg, _messages);
for(size_t i = 0; i < rankCfg.rankprofile.size(); i++) {
search::fef::Properties properties;
const RankProfilesConfig::Rankprofile &profile = rankCfg.rankprofile[i];
@@ -184,33 +203,20 @@ App::verifyConfig(const VerifyRanksetupConfig &myCfg,
profile.fef.property[j].value);
}
if (verify(schema, properties, repo, expressions, models)) {
- LOG(info, "rank profile '%s': pass", profile.name.c_str());
+ _messages.emplace_back(search::fef::Level::INFO,
+ fmt("rank profile '%s': pass", profile.name.c_str()));
} else {
- LOG(error, "rank profile '%s': FAIL", profile.name.c_str());
+ _messages.emplace_back(search::fef::Level::ERROR,
+ fmt("rank profile '%s': FAIL", profile.name.c_str()));
ok = false;
}
}
return ok;
}
-int
-App::usage()
-{
- fprintf(stderr, "Usage: vespa-verify-ranksetup <config-id>\n");
- return 1;
-}
-
-int
-App::main(int argc, char **argv)
+bool
+VerifyRankSetup::verify(const std::string & configid)
{
- if (argc != 2) {
- return usage();
- }
-
- const std::string configid = argv[1];
- LOG(debug, "verifying rank setup for config id '%s' ...",
- configid.c_str());
-
bool ok = false;
try {
auto ctx = std::make_shared<ConfigContext>(*config::legacyConfigId2Spec(configid));
@@ -233,18 +239,19 @@ App::main(int argc, char **argv)
*expressionsHandle->getConfig(),
*modelsHandle->getConfig());
} catch (ConfigRuntimeException & e) {
- LOG(error, "Unable to subscribe to config: %s", e.getMessage().c_str());
+ _messages.emplace_back(search::fef::Level::ERROR,
+ fmt("Unable to subscribe to config: %s", e.getMessage().c_str()));
} catch (InvalidConfigException & e) {
- LOG(error, "Error getting config: %s", e.getMessage().c_str());
- }
- if (!ok) {
- return 1;
+ _messages.emplace_back(search::fef::Level::ERROR,
+ fmt("Error getting config: %s", e.getMessage().c_str()));
}
- return 0;
+ return ok;
}
-int main(int argc, char **argv) {
- vespalib::SignalHandler::PIPE.ignore();
- App app;
- return app.main(argc, argv);
+std::pair<bool, std::vector<search::fef::Message>>
+verifyRankSetup(const char * configId) {
+ VerifyRankSetup verifier;
+ bool ok = verifier.verify(configId);
+
+ return {ok, verifier.getMessages()};
}