Errata in multiple metric definitions

A repeated message with the same version as
the previous would trigger a wrong message exception.

Change-Id: Id575e13c0183c31eb56251d9b181911eb27ea4cb
This commit is contained in:
Geir Horn 2024-01-27 19:17:06 +01:00
parent d0ad28446b
commit 879b659125

View File

@ -49,48 +49,48 @@ void MetricUpdater::AddMetricSubscription( const MetricTopic & TheMetrics,
const Address OptimiserController )
{
if( TheMetrics.is_object() &&
TheMetrics.at( NebulOuS::MetricList ).is_array() &&
(MetricsVersion < TheMetrics.at( MetricVersionCounter ).get<long int>()) )
TheMetrics.at( NebulOuS::MetricList ).is_array() )
{
// The first step is to try inserting the metrics into the metric value map
// and if this is successful, a subscription is created for the publisher
// of this metric value. The metric names are recorded since some of them
// may correspond to known metrics, some of them may correspond to metrics
// that are new.
std::set< std::string > MetricNames;
for (auto & MetricRecord : TheMetrics.at( NebulOuS::MetricList ) )
if( MetricsVersion < TheMetrics.at( MetricVersionCounter ).get<long int>() )
{
auto [ MetricRecordPointer, MetricAdded ] = MetricValues.try_emplace(
MetricRecord.at( NebulOuS::MetricName ), JSON() );
// The first step is to try inserting the metrics into the metric value
// map and if this is successful, a subscription is created for the
// publisherof this metric value. The metric names are recorded since
// some of them may correspond to known metrics, some of them may
// correspond to metrics that are new.
MetricNames.insert( MetricRecordPointer->first );
std::set< std::string > MetricNames;
if( MetricAdded )
Send( Theron::AMQ::NetworkLayer::TopicSubscription(
Theron::AMQ::NetworkLayer::TopicSubscription::Action::Subscription,
std::string( MetricValueRootString ) + MetricRecordPointer->first ),
//Theron::AMQ::Network::GetAddress( Theron::Network::Layer::Session) );
GetSessionLayerAddress() );
}
// There could be some metric value records that were defined by the previous
// metrics defined, but missing from the new metric set. If this is the case,
// the metric value records for the missing metrics should be unsubcribed
// and their metric records removed.
for( const auto & TheMetric : std::views::keys( MetricValues ) )
if( !MetricName.contains( TheMetric ) )
for (auto & MetricRecord : TheMetrics.at( NebulOuS::MetricList ) )
{
Send( Theron::AMQ::NetworkLayer::TopicSubscription(
Theron::AMQ::NetworkLayer::TopicSubscription::Action::CloseSubscription,
std::string( MetricValueRootString ) + TheMetric ),
//Theron::AMQ::Network::GetAddress( Theron::Network::Layer::Session) );
GetSessionLayerAddress() );
auto [ MetricRecordPointer, MetricAdded ] = MetricValues.try_emplace(
MetricRecord.at( NebulOuS::MetricName ), JSON() );
MetricValues.erase( TheMetric );
MetricNames.insert( MetricRecordPointer->first );
if( MetricAdded )
Send( Theron::AMQ::NetworkLayer::TopicSubscription(
Theron::AMQ::NetworkLayer::TopicSubscription::Action::Subscription,
std::string( MetricValueRootString ) + MetricRecordPointer->first ),
GetSessionLayerAddress() );
}
// There could be some metric value records that were defined by the
// previous metrics defined, but missing from the new metric set. If
// this is the case, the metric value records for the missing metrics
// should be unsubcribed and their metric records removed.
for( const auto & TheMetric : std::views::keys( MetricValues ) )
if( !MetricName.contains( TheMetric ) )
{
Send( Theron::AMQ::NetworkLayer::TopicSubscription(
Theron::AMQ::NetworkLayer::TopicSubscription::Action::CloseSubscription,
std::string( MetricValueRootString ) + TheMetric ),
GetSessionLayerAddress() );
MetricValues.erase( TheMetric );
}
}
}
else
{