Merge "First release"
This commit is contained in:
commit
79cf79e7fb
@ -41,17 +41,22 @@ namespace NebulOuS
|
||||
void MetricUpdater::AddMetricSubscription( const MetricTopic & TheMetrics,
|
||||
const Address OptimiserController )
|
||||
{
|
||||
if( TheMetrics.is_object() )
|
||||
for( const auto & [MetricName, TopicName] : TheMetrics.items() )
|
||||
if( TheMetrics.is_object() &&
|
||||
TheMetrics.at( NebulOuS::MetricList ).is_object() )
|
||||
{
|
||||
auto [ MetricRecord, NewMetric ] = MetricValues.try_emplace(
|
||||
TopicName, MetricName, JSON() );
|
||||
JSON MetricList = TheMetrics.at( NebulOuS::MetricList );
|
||||
|
||||
if( NewMetric )
|
||||
Send( Theron::AMQ::NetworkLayer::TopicSubscription(
|
||||
Theron::AMQ::NetworkLayer::TopicSubscription::Action::Subscription,
|
||||
TopicName ),
|
||||
Theron::AMQ::Network::GetAddress( Theron::Network::Layer::Session) );
|
||||
for( const JSON MetricDefinition : MetricList.items() )
|
||||
{
|
||||
auto [ MetricRecord, NewMetric ] = MetricValues.try_emplace(
|
||||
MetricDefinition.at( NebulOuS::MetricName ), JSON() );
|
||||
|
||||
if( NewMetric )
|
||||
Send( Theron::AMQ::NetworkLayer::TopicSubscription(
|
||||
Theron::AMQ::NetworkLayer::TopicSubscription::Action::Subscription,
|
||||
MetricRecord->first ),
|
||||
Theron::AMQ::Network::GetAddress( Theron::Network::Layer::Session) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -62,7 +67,7 @@ void MetricUpdater::AddMetricSubscription( const MetricTopic & TheMetrics,
|
||||
<< "in function " << Location.function_name() <<"] "
|
||||
<< "The message to define a new metric subscription is given as "
|
||||
<< std::endl << TheMetrics.dump(2) << std::endl
|
||||
<< "this is not a JSON object!";
|
||||
<< "this is not as expected!";
|
||||
|
||||
throw std::invalid_argument( ErrorMessage.str() );
|
||||
}
|
||||
@ -98,11 +103,12 @@ void MetricUpdater::UpdateMetricValue(
|
||||
const MetricValueUpdate & TheMetricValue, const Address TheMetricTopic)
|
||||
{
|
||||
Theron::AMQ::TopicName TheTopic
|
||||
= TheMetricTopic.AsString().erase(0, MetricValueRootString.size() );
|
||||
= TheMetricTopic.AsString().erase( 0,
|
||||
NebulOuS::MetricValueRootString.size() );
|
||||
|
||||
if( MetricValues.contains( TheTopic ) )
|
||||
{
|
||||
MetricValues.at( TheTopic ).Value = TheMetricValue[ NebulOuS::ValueLabel ];
|
||||
MetricValues.at( TheTopic ) = TheMetricValue[ NebulOuS::ValueLabel ];
|
||||
|
||||
ValidityTime = std::max( ValidityTime,
|
||||
TheMetricValue[ NebulOuS::TimePoint ].get< Solver::TimePointType >() );
|
||||
@ -135,10 +141,9 @@ void MetricUpdater::SLOViolationHandler(
|
||||
|
||||
Solver::MetricValueType TheApplicationExecutionContext;
|
||||
|
||||
for( const auto & [_, MetricRecord ] : MetricValues )
|
||||
if( !MetricRecord.Value.is_null() )
|
||||
TheApplicationExecutionContext.emplace( MetricRecord.OptimisationName,
|
||||
MetricRecord.Value );
|
||||
for( const auto & [ MetricName, MetricValue ] : MetricValues )
|
||||
if( !MetricValue.is_null() )
|
||||
TheApplicationExecutionContext.emplace( MetricName, MetricValue );
|
||||
|
||||
// The application context can then be sent to the solution manager
|
||||
// using the corresponding message, and the time stamp of the severity
|
||||
|
@ -88,7 +88,15 @@ constexpr std::string_view TimePoint = "predictionTime";
|
||||
// defined next.
|
||||
|
||||
constexpr std::string_view MetricSubscriptions
|
||||
= "eu.nebulouscloud.optimiser.solver.metrics";
|
||||
= "eu.nebulouscloud.monitoring.metric_lists";
|
||||
|
||||
// The JSON message attribute for the list of metrics is another JSON object
|
||||
// stored under the following key, see the Event type III defined in
|
||||
// https://158.39.75.54/projects/nebulous-collaboration-hub/wiki/slo-severity-based-violation-detector
|
||||
// where the name of the metric is defined under as sub-key.
|
||||
|
||||
constexpr std::string_view MetricList = "metric_list";
|
||||
constexpr std::string_view MetricName = "name";
|
||||
|
||||
// The metric value messages will be published on different topics and to
|
||||
// check if an inbound message is from a metric value topic, it is necessary
|
||||
@ -154,33 +162,11 @@ private:
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// The metric values are stored essentially as a JSON values where the
|
||||
// attributes are the metric names and the values are JSON values because
|
||||
// they are polymorphic with respect to different variable types, and as
|
||||
// they arrive as JSON values this avoids converting the values on input and
|
||||
// output. The metric optimisation name is just a string.
|
||||
// attributes are the metric names and the values are JSON values. It is
|
||||
// assumed that same metric name is used both for the optimisation model
|
||||
// and for the metric topic.
|
||||
|
||||
class MetricValueRecord
|
||||
{
|
||||
public:
|
||||
const std::string OptimisationName;
|
||||
JSON Value;
|
||||
|
||||
MetricValueRecord( const std::string & TheName, const JSON InitialValue )
|
||||
: OptimisationName( TheName ), Value( InitialValue )
|
||||
{}
|
||||
|
||||
MetricValueRecord( const MetricValueRecord & Other )
|
||||
: OptimisationName( Other.OptimisationName ), Value( Other.Value )
|
||||
{}
|
||||
|
||||
MetricValueRecord() = delete;
|
||||
~MetricValueRecord() = default;
|
||||
};
|
||||
|
||||
// This value record is used in the map where the subscribed topic name is
|
||||
// the key so that values can quickly be updated when messages arrives.
|
||||
|
||||
std::unordered_map< Theron::AMQ::TopicName, MetricValueRecord > MetricValues;
|
||||
std::unordered_map< Theron::AMQ::TopicName, JSON > MetricValues;
|
||||
|
||||
// The metric values should ideally be forecasted for the same future time
|
||||
// point, but this may not be assured, and as such a zero-order hold is
|
||||
|
Loading…
x
Reference in New Issue
Block a user