Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-33023 Prevent periodic sinks from collecting if prepare fails #19326

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions system/jlib/jmetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,11 @@ PeriodicMetricSink::~PeriodicMetricSink()
void PeriodicMetricSink::startCollection(MetricsManager *_pManager)
{
pManager = _pManager;
prepareToStartCollecting();
isCollecting = true;
collectThread = std::thread(&PeriodicMetricSink::collectionThread, this);
if (prepareToStartCollecting())
{
isCollecting = true;
collectThread = std::thread(&PeriodicMetricSink::collectionThread, this);
}
}


Expand Down
2 changes: 1 addition & 1 deletion system/jlib/jmetrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class jlib_decl PeriodicMetricSink : public MetricSink

protected:
explicit PeriodicMetricSink(const char *_name, const char *_type, const IPropertyTree *_pSettingsTree);
virtual void prepareToStartCollecting() = 0;
virtual bool prepareToStartCollecting() = 0;
virtual void collectingHasStopped() = 0;
virtual void doCollection() = 0;
void collectionThread();
Expand Down
4 changes: 2 additions & 2 deletions system/metrics/sinks/elastic/elasticSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ ElasticMetricSink::ElasticMetricSink(const char *name, const IPropertyTree *pSet
}


void ElasticMetricSink::prepareToStartCollecting()
bool ElasticMetricSink::prepareToStartCollecting()
{

return false;
}


Expand Down
2 changes: 1 addition & 1 deletion system/metrics/sinks/elastic/elasticSink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ELASTICSINK_API ElasticMetricSink : public hpccMetrics::PeriodicMetricSink
~ElasticMetricSink() override = default;

protected:
virtual void prepareToStartCollecting() override;
virtual bool prepareToStartCollecting() override;
virtual void collectingHasStopped() override;
virtual void doCollection() override;

Expand Down
3 changes: 2 additions & 1 deletion system/metrics/sinks/file/fileSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ FileMetricSink::FileMetricSink(const char *name, const IPropertyTree *pSettingsT
}


void FileMetricSink::prepareToStartCollecting()
bool FileMetricSink::prepareToStartCollecting()
{
fhandle = fopen(fileName.str(), clearFileOnStartCollecting ? "w" : "a");
return (fhandle != nullptr);
}


Expand Down
2 changes: 1 addition & 1 deletion system/metrics/sinks/file/fileSink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FILESINK_API FileMetricSink : public PeriodicMetricSink
~FileMetricSink() override = default;

protected:
virtual void prepareToStartCollecting() override;
virtual bool prepareToStartCollecting() override;
virtual void collectingHasStopped() override;
void doCollection() override;
virtual void writeReportHeaderToFile() const;
Expand Down
2 changes: 1 addition & 1 deletion system/metrics/sinks/log/logSink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LOGSINK_API LogMetricSink : public PeriodicMetricSink
~LogMetricSink() override = default;

protected:
virtual void prepareToStartCollecting() override {}
virtual bool prepareToStartCollecting() override { return true; }
virtual void collectingHasStopped() override {}
virtual void doCollection() override;
void writeLogEntry(const std::shared_ptr<IMetric> &pMetric);
Expand Down
3 changes: 2 additions & 1 deletion testing/unittests/metrics/PeriodicSinkTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ class PeriodicTestSink : public PeriodicMetricSink
~PeriodicTestSink() = default;

protected:
virtual void prepareToStartCollecting() override
virtual bool prepareToStartCollecting() override
{
prepareCalled = true;
numCollections = 0;
return true;
}

virtual void collectingHasStopped() override
Expand Down
Loading