Skip to content
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
18 changes: 4 additions & 14 deletions handwritten/bigtable/src/client-side-metrics/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,14 @@ function getInterval(
dataPoint:
DataPoint<number> | DataPoint<Histogram> | DataPoint<ExponentialHistogram>,
) {
let endSec = dataPoint.endTime[0];
let endNanos = dataPoint.endTime[1];
const startSec = dataPoint.startTime[0];
const startNanos = dataPoint.startTime[1];

if (startSec > endSec || (startSec === endSec && startNanos > endNanos)) {
endSec = startSec;
endNanos = startNanos;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The changes here are actually just reverting changes that were applied in 1ea27c9#diff-39c2f3c691ce7c9e2f54ab8c9020dff4aef632d80a11aa13fe19074c889aaad5R51-R60. We do not want the client side metrics exporter artificially warping collected client side metrics data which is what this commit did.

If we can change the tests instead then that would offer a much better solution.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this PR attempts to change the tests instead to solve the Flakey test problem.

return {
endTime: {
seconds: endSec,
nanos: endNanos,
seconds: dataPoint.endTime[0],
nanos: dataPoint.endTime[1],
},
startTime: {
seconds: startSec,
nanos: startNanos,
seconds: dataPoint.startTime[0],
nanos: dataPoint.startTime[1],
},
};
Comment on lines 51 to 60

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Reverting the interval check entirely from the production exporter leaves production environments vulnerable to metric export failures if startTime >= endTime occurs (e.g., due to clock drift, container virtualization, or high-resolution timer limitations). Since Cloud Monitoring requires startTime < endTime for cumulative/delta metrics, the previous fix of setting them equal was indeed insufficient, but the correct solution is to apply the strictly-greater-than adjustment (adding 1ms/1,000,000 nanos) in the production exporter itself, rather than only in the system tests.

  let endSec = dataPoint.endTime[0];
  let endNanos = dataPoint.endTime[1];
  const startSec = dataPoint.startTime[0];
  const startNanos = dataPoint.startTime[1];

  if (startSec > endSec || (startSec === endSec && startNanos >= endNanos)) {
    const adjustedNanos = startNanos + 1000000;
    if (adjustedNanos >= 1000000000) {
      endSec = startSec + 1;
      endNanos = adjustedNanos - 1000000000;
    } else {
      endSec = startSec;
      endNanos = adjustedNanos;
    }
  }

  return {
    endTime: {
      seconds: endSec,
      nanos: endNanos,
    },
    startTime: {
      seconds: startSec,
      nanos: startNanos,
    },
  };

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I agree with this. https://github.com/googleapis/google-cloud-node/pull/9717/changes#r4401545583 offers this solution, but failed exporter calls are silent so it doesn't bombard the user with errors and we don't want hidden code somewhere artificially manipulating the data.

}
Expand Down
Loading
Loading