Skip to content

Commit

Permalink
Move DiskIoMetrics out of IndexMetricsEntry.
Browse files Browse the repository at this point in the history
  • Loading branch information
toregge committed Nov 15, 2024
1 parent f7b6a5d commit 75783d3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ vespa_add_library(searchcore_proton_metrics STATIC
attribute_metrics_entry.cpp
cache_metrics.cpp
content_proton_metrics.cpp
disk_io_metrics.cpp
documentdb_job_trackers.cpp
documentdb_tagged_metrics.cpp
document_db_commit_metrics.cpp
Expand Down
44 changes: 44 additions & 0 deletions searchcore/src/vespa/searchcore/proton/metrics/disk_io_metrics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "disk_io_metrics.h"
#include <vespa/searchlib/util/cache_disk_io_stats.h>

using search::CacheDiskIoStats;
using search::DiskIoStats;

namespace proton {

namespace {

void update_helper(metrics::LongValueMetric &metric, const DiskIoStats &stats) {
metric.addTotalValueBatch(stats.read_bytes_total(), stats.read_operations(),
stats.read_bytes_min(), stats.read_bytes_max());
}

}

DiskIoMetrics::SearchMetrics::SearchMetrics(metrics::MetricSet* parent)
: MetricSet("search", {}, "The search io for a given component", parent),
_read_bytes("read_bytes", {}, "Bytes read in posting list files as part of search", this),
_cached_read_bytes("cached_read_bytes", {}, "Bytes read from posting list files cache as part of search", this)
{
}

DiskIoMetrics::SearchMetrics::~SearchMetrics() = default;

void
DiskIoMetrics::SearchMetrics::update(const CacheDiskIoStats& cache_disk_io_stats)
{
update_helper(_read_bytes, cache_disk_io_stats.read());
update_helper(_cached_read_bytes, cache_disk_io_stats.cached_read());
}

DiskIoMetrics::DiskIoMetrics(metrics::MetricSet* parent)
: MetricSet("io", {}, "The disk usage for a given component", parent),
_search(this)
{
}

DiskIoMetrics::~DiskIoMetrics() = default;

}
34 changes: 34 additions & 0 deletions searchcore/src/vespa/searchcore/proton/metrics/disk_io_metrics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/metrics/metricset.h>
#include <vespa/metrics/valuemetric.h>

namespace search { class CacheDiskIoStats; }

namespace proton {

/*
* Class containing disk io metrics, e.g. per index field or
* aggregated at document type level.
*/
class DiskIoMetrics : public metrics::MetricSet {
class SearchMetrics : public metrics::MetricSet {
metrics::LongValueMetric _read_bytes;
metrics::LongValueMetric _cached_read_bytes;
public:
explicit SearchMetrics(metrics::MetricSet* parent);
~SearchMetrics() override;
void update(const search::CacheDiskIoStats& cache_disk_io_stats);
};

SearchMetrics _search;

public:
explicit DiskIoMetrics(metrics::MetricSet* parent);
~DiskIoMetrics() override;
void update(const search::CacheDiskIoStats& cache_disk_io_stats) { _search.update(cache_disk_io_stats); }
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,15 @@
#include "index_metrics_entry.h"
#include <vespa/searchlib/util/cache_disk_io_stats.h>

using search::CacheDiskIoStats;
using search::DiskIoStats;

namespace proton {

namespace {

const std::string entry_name("index");
const std::string entry_description("Metrics for indexes for a given field");

void update_helper(metrics::LongValueMetric &metric, const DiskIoStats &stats) {
metric.addTotalValueBatch(stats.read_bytes_total(), stats.read_operations(),
stats.read_bytes_min(), stats.read_bytes_max());
}

}

IndexMetricsEntry::DiskIoMetrics::SearchMetrics::SearchMetrics(metrics::MetricSet* parent)
: MetricSet("search", {}, "The search io for a given component", parent),
_read_bytes("read_bytes", {}, "Bytes read in posting list files as part of search", this),
_cached_read_bytes("cached_read_bytes", {}, "Bytes read from posting list files cache as part of search", this)
{
}

IndexMetricsEntry::DiskIoMetrics::SearchMetrics::~SearchMetrics() = default;

void
IndexMetricsEntry::DiskIoMetrics::SearchMetrics::update(const CacheDiskIoStats& cache_disk_io_stats)
{
update_helper(_read_bytes, cache_disk_io_stats.read());
update_helper(_cached_read_bytes, cache_disk_io_stats.cached_read());
}

IndexMetricsEntry::DiskIoMetrics::DiskIoMetrics(metrics::MetricSet* parent)
: MetricSet("io", {}, "The disk usage for a given component", parent),
_search(this)
{
}

IndexMetricsEntry::DiskIoMetrics::~DiskIoMetrics() = default;

IndexMetricsEntry::IndexMetricsEntry(const std::string& field_name)
: FieldMetricsEntry(entry_name, field_name, entry_description),
_disk_io(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,16 @@

#pragma once

#include "disk_io_metrics.h"
#include "field_metrics_entry.h"

namespace search { class CacheDiskIoStats; }

namespace proton {

/*
* Class containing metrics for the index aspect of a field, i.e.
* disk indexes and memory indexes.
*/
class IndexMetricsEntry : public FieldMetricsEntry {
class DiskIoMetrics : public metrics::MetricSet {
class SearchMetrics : public metrics::MetricSet {
metrics::LongValueMetric _read_bytes;
metrics::LongValueMetric _cached_read_bytes;
public:
explicit SearchMetrics(metrics::MetricSet* parent);
~SearchMetrics() override;
void update(const search::CacheDiskIoStats& cache_disk_io_stats);
};

SearchMetrics _search;

public:
explicit DiskIoMetrics(metrics::MetricSet* parent);
~DiskIoMetrics() override;
void update(const search::CacheDiskIoStats& cache_disk_io_stats) { _search.update(cache_disk_io_stats); }
};

DiskIoMetrics _disk_io;

public:
Expand Down

0 comments on commit 75783d3

Please sign in to comment.