Add useCurrentTime flag to HTTP metrics output timestamping#289
Merged
Conversation
Agent-Logs-Url: https://github.com/OpenAF/nAttrMon/sessions/3ccced4e-1038-4ccd-a932-f5487e35e5eb Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Modify nOutput_HTTP_Metrics to support useCurrentTime flag
Add May 21, 2026
useCurrentTime flag to HTTP metrics output timestamping
abrizida
approved these changes
May 27, 2026
abrizida
left a comment
Collaborator
There was a problem hiding this comment.
Tested and working in my environment.
nmaguiar
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
nOutput_HTTP_Metricsalways emitted OpenMetrics timestamps based on recorded attribute/warning retrieval times. This change adds an opt-inuseCurrentTimeflag to emit scrape-time timestamps (Date.now()) instead.Configuration
config/objects/nOutput_HTTP_Metrics.js:useCurrentTime(default:false)Timestamp selection for value/warning parsing
_parse(current/last values) and_parsew(warnings) to select timestamp via:useCurrentTime=false(existing behavior)Date.now()whenuseCurrentTime=trueSelf metrics timestamping
/metricshandler to pass an explicit timestamp only whenuseCurrentTime=true:__ow_metrics_fromObj2OpenMetrics(ow.metrics.getAll(), parent.nameSelf, parent.useCurrentTime ? Date.now() : undefined)Example:
Original prompt
Summary
Modify
config/objects/nOutput_HTTP_Metrics.jsto support a new boolean option flaguseCurrentTime(defaults tofalse). When set totrue, the current time (Date.now()) should be used as the timestamp passed toow.metrics.fromObj2OpenMetrics/__ow_metrics_fromObj2OpenMetrics, instead of the recorded retrieval time stored in the attribute value.Changes Required
1. Constructor — accept and store the new flag
In the
nOutput_HTTP_Metricsconstructor (where other flags likeincludeSelf,includeCVals, etc. are read fromaMap), add:2.
_parsefunction — use current time when flag is setCurrent code (around line 294–303):
Change to:
3.
_parsewfunction — use current time when flag is setCurrent code (around line 306–319):
Change to:
4. Self-metrics calls — pass current time when flag is set
In the
/metricsroute handler, theselfcase calls__ow_metrics_fromObj2OpenMetrics(ow.metrics.getAll(), parent.nameSelf)without any timestamp. WhenuseCurrentTimeistrue, passDate.now()as the timestamp:Change both occurrences (in the
switch(req.params.type)block and theif (parent.includeSelf)block):Usage example (YAML config)
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Change objects/nOutput*Metrics.js so that given an option flag to use the current time instead of the recorded time of retrieval.
Here is the help of the function:
ow.metrics.fromObj2OpenMetrics(aObj, aPrefix, aTimestamp, aHelpMap, aConvMap) : String
Assistant: Let me start by examining the relevant files in the repository.
Assistant: Now I have a full picture of the file. Here's the plan for the changes to
config/objects/nOutput_HTTP_Metrics.js:useCurrentTimeoption flag (defaults tofalse)._parse(line 296) — useDate.now()instead of(new Date(r.date)).getTime()when the flag is set._parsew(line 310) — useDate.now()instead of(new Date(w.lastupdate)).getTime()when the flag is set.selfmetrics calls (lines 457 & 463) — passDate.now()as the timestamp when the flag is set (currently no timestamp is passed at all for self-metrics).Would you like me to open a PR with these changes, or just show you the diff first?
User: Yes
Assistant: We're waiting for your response to the confirmation dialog to proceed with creating the pull request.
This pull request was created from Copilot chat.