Skip to content

Commit

Permalink
cockpit: sample() re-usable for both archives
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly committed Sep 11, 2024
1 parent bb65e6d commit efa6948
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions src/cockpit/channels/pcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def needs_meta_update(self, results: 'pmapi.pmResult') -> bool:

return False

def sample(self, context: 'pmapi.pmContext', total_fetched: int) -> int:
def sample(self, context: 'pmapi.pmContext', archive_batch: int, limit: int, total_fetched: int) -> int:
# HACK: pmFetch only takes an array of ctypes.c_uint, no native type, alternative keep pmids.
pmids = (ctypes.c_uint * len(self.metric_descriptions))()
for i, metric in enumerate(self.metric_descriptions):
Expand All @@ -424,8 +424,8 @@ def sample(self, context: 'pmapi.pmContext', total_fetched: int) -> int:
while True:
fetched = []
try:
for _ in range(self.archive_batch):
if total_fetched == self.limit:
for _ in range(archive_batch):
if total_fetched == limit:
# Direct sample type
if context.type != c_api.PM_CONTEXT_ARCHIVE:
return total_fetched
Expand Down Expand Up @@ -635,11 +635,7 @@ def sample_archives(self, archives):
except pmapi.pmErr as exc:
raise ChannelError('internal-error', message=str(exc)) from None

total_fetched = self.sample(archive.context, total_fetched)
if total_fetched == self.limit:
return True
else:
return True
total_fetched = self.sample(archive.context, self.archive_batch, self.limit, total_fetched)

def prepare_direct_context(self, name: str, context_type: str) -> 'pmapi.pmContext':
try:
Expand Down Expand Up @@ -674,15 +670,6 @@ async def run(self, options: JsonObject) -> None:
direct_context = self.prepare_direct_context(name, context_type)
self.ready()

# TODO: we need to have a sample method which works archive independent
# The problem is metric descriptions, which is tied per archive, can we de-couple that?
# The C implementation does this per archive, and save that globally

# def sample(self, archive, total_fetched):
# TODO: HACK this is a big hack :)
self.archive_batch = 1
self.limit = 1
while True:
# Get stuff
self.sample(direct_context, 0)
self.sample(direct_context, 1, 1, 0)
await asyncio.sleep(self.interval / 1000)

0 comments on commit efa6948

Please sign in to comment.