MM-58281 Change performance timestamps to be floats (#27046)

* MM-58281 Change performance timestamps to be floats

* Commit missed line
Этот коммит содержится в:
Harrison Healey
2024-05-17 13:52:03 -04:00
коммит произвёл GitHub
родитель 3e734ee949
Коммит b9f7d38cb1
5 изменённых файлов: 27 добавлений и 27 удалений

Просмотреть файл

@@ -111,8 +111,8 @@ func TestSubmitMetrics(t *testing.T) {
resp, err := th.Client.SubmitClientMetrics(th.Context.Context(), &model.PerformanceReport{ resp, err := th.Client.SubmitClientMetrics(th.Context.Context(), &model.PerformanceReport{
Version: "0.1", Version: "0.1",
Start: time.Now().Add(-1 * time.Minute).UnixMilli(), Start: float64(time.Now().Add(-1 * time.Minute).UnixMilli()),
End: time.Now().UnixMilli(), End: float64(time.Now().UnixMilli()),
Counters: []*model.MetricSample{ Counters: []*model.MetricSample{
{Metric: model.ClientLongTasks, Value: 1}, {Metric: model.ClientLongTasks, Value: 1},
}, },
@@ -145,8 +145,8 @@ func TestSubmitMetrics(t *testing.T) {
resp, err := th.Client.SubmitClientMetrics(th.Context.Context(), &model.PerformanceReport{ resp, err := th.Client.SubmitClientMetrics(th.Context.Context(), &model.PerformanceReport{
Version: "0.1", Version: "0.1",
Start: time.Now().Add(-1 * time.Minute).UnixMilli(), Start: float64(time.Now().Add(-1 * time.Minute).UnixMilli()),
End: time.Now().UnixMilli(), End: float64(time.Now().UnixMilli()),
Counters: []*model.MetricSample{ Counters: []*model.MetricSample{
{Metric: model.ClientLongTasks, Value: 1}, {Metric: model.ClientLongTasks, Value: 1},
}, },

Просмотреть файл

@@ -36,7 +36,7 @@ var (
type MetricSample struct { type MetricSample struct {
Metric MetricType `json:"metric"` Metric MetricType `json:"metric"`
Value float64 `json:"value"` Value float64 `json:"value"`
Timestamp int64 `json:"timestamp,omitempty"` Timestamp float64 `json:"timestamp,omitempty"`
Labels map[string]string `json:"labels,omitempty"` Labels map[string]string `json:"labels,omitempty"`
} }
@@ -45,8 +45,8 @@ type PerformanceReport struct {
Version string `json:"version"` Version string `json:"version"`
ClientID string `json:"client_id"` ClientID string `json:"client_id"`
Labels map[string]string `json:"labels"` Labels map[string]string `json:"labels"`
Start int64 `json:"start"` Start float64 `json:"start"`
End int64 `json:"end"` End float64 `json:"end"`
Counters []*MetricSample `json:"counters"` Counters []*MetricSample `json:"counters"`
Histograms []*MetricSample `json:"histograms"` Histograms []*MetricSample `json:"histograms"`
} }
@@ -70,8 +70,8 @@ func (r *PerformanceReport) IsValid() error {
} }
now := time.Now().UnixMilli() now := time.Now().UnixMilli()
if r.End < now-performanceReportTTLMilliseconds { if r.End < float64(now-performanceReportTTLMilliseconds) {
return fmt.Errorf("report is outdated: %d", r.End) return fmt.Errorf("report is outdated: %f", r.End)
} }
return nil return nil

Просмотреть файл

@@ -23,8 +23,8 @@ func TestPerformanceReport_IsValid(t *testing.T) {
report: &PerformanceReport{ report: &PerformanceReport{
Version: "0.1.0", Version: "0.1.0",
Labels: map[string]string{"platform": "linux"}, Labels: map[string]string{"platform": "linux"},
Start: time.Now().UnixMilli() - 10000, Start: float64(time.Now().UnixMilli() - 10000),
End: time.Now().UnixMilli(), End: float64(time.Now().UnixMilli()),
}, },
expected: nil, expected: nil,
}, },
@@ -38,8 +38,8 @@ func TestPerformanceReport_IsValid(t *testing.T) {
report: &PerformanceReport{ report: &PerformanceReport{
Version: "2.0.0", Version: "2.0.0",
Labels: map[string]string{"platform": "linux"}, Labels: map[string]string{"platform": "linux"},
Start: time.Now().UnixMilli() - 10000, Start: float64(time.Now().UnixMilli() - 10000),
End: time.Now().UnixMilli(), End: float64(time.Now().UnixMilli()),
}, },
expected: fmt.Errorf("report version is not supported: server version: 0.1.0, report version: 2.0.0"), expected: fmt.Errorf("report version is not supported: server version: 0.1.0, report version: 2.0.0"),
}, },
@@ -48,8 +48,8 @@ func TestPerformanceReport_IsValid(t *testing.T) {
report: &PerformanceReport{ report: &PerformanceReport{
Version: "0.1.0", Version: "0.1.0",
Labels: map[string]string{"platform": "linux"}, Labels: map[string]string{"platform": "linux"},
Start: time.Now().UnixMilli(), Start: float64(time.Now().UnixMilli()),
End: time.Now().Add(-1 * time.Hour).UnixMilli(), End: float64(time.Now().Add(-1 * time.Hour).UnixMilli()),
}, },
expected: fmt.Errorf("report timestamps are erroneous"), expected: fmt.Errorf("report timestamps are erroneous"),
}, },
@@ -58,10 +58,10 @@ func TestPerformanceReport_IsValid(t *testing.T) {
report: &PerformanceReport{ report: &PerformanceReport{
Version: "0.1.0", Version: "0.1.0",
Labels: map[string]string{"platform": "linux"}, Labels: map[string]string{"platform": "linux"},
Start: time.Now().Add(-7 * time.Minute).UnixMilli(), Start: float64(time.Now().Add(-7 * time.Minute).UnixMilli()),
End: outdatedTimestamp, End: float64(outdatedTimestamp),
}, },
expected: fmt.Errorf("report is outdated: %d", outdatedTimestamp), expected: fmt.Errorf("report is outdated: %f", float64(outdatedTimestamp)),
}, },
} }

Просмотреть файл

@@ -52,23 +52,23 @@ describe('PerformanceReporter', () => {
expect(sendBeacon.mock.calls[0][0]).toEqual(siteUrl + '/api/v4/client_perf'); expect(sendBeacon.mock.calls[0][0]).toEqual(siteUrl + '/api/v4/client_perf');
const report = JSON.parse(sendBeacon.mock.calls[0][1]); const report = JSON.parse(sendBeacon.mock.calls[0][1]);
expect(report).toMatchObject({ expect(report).toMatchObject({
start: Math.round(performance.timeOrigin + testMarkA.startTime), start: performance.timeOrigin + testMarkA.startTime,
end: Math.round(performance.timeOrigin + testMarkB.startTime), end: performance.timeOrigin + testMarkB.startTime,
histograms: [ histograms: [
{ {
metric: 'testMeasureA', metric: 'testMeasureA',
value: testMarkB.startTime - testMarkA.startTime, value: testMarkB.startTime - testMarkA.startTime,
timestamp: Math.round(performance.timeOrigin + testMarkA.startTime), timestamp: performance.timeOrigin + testMarkA.startTime,
}, },
{ {
metric: 'testMeasureB', metric: 'testMeasureB',
value: testMarkC.startTime - testMarkA.startTime, value: testMarkC.startTime - testMarkA.startTime,
timestamp: Math.round(performance.timeOrigin + testMarkA.startTime), timestamp: performance.timeOrigin + testMarkA.startTime,
}, },
{ {
metric: 'testMeasureC', metric: 'testMeasureC',
value: testMarkC.startTime - testMarkB.startTime, value: testMarkC.startTime - testMarkB.startTime,
timestamp: Math.round(performance.timeOrigin + testMarkB.startTime), timestamp: performance.timeOrigin + testMarkB.startTime,
}, },
], ],
}); });
@@ -94,7 +94,7 @@ describe('PerformanceReporter', () => {
expect(reporter.handleObservations).toHaveBeenCalled(); expect(reporter.handleObservations).toHaveBeenCalled();
const timestamp = Math.round(performance.timeOrigin + performance.now()); const timestamp = performance.timeOrigin + performance.now();
await waitForReport(); await waitForReport();

Просмотреть файл

@@ -141,7 +141,7 @@ export default class PerformanceReporter {
this.histogramMeasures.push({ this.histogramMeasures.push({
metric: entry.name, metric: entry.name,
value: entry.duration, value: entry.duration,
timestamp: Math.round(performance.timeOrigin + entry.startTime), timestamp: performance.timeOrigin + entry.startTime,
}); });
} }
@@ -166,7 +166,7 @@ export default class PerformanceReporter {
this.histogramMeasures.push({ this.histogramMeasures.push({
metric: metric.name, metric: metric.name,
value: metric.value, value: metric.value,
timestamp: Math.round(performance.timeOrigin + performance.now()), timestamp: performance.timeOrigin + performance.now(),
}); });
} }
@@ -267,7 +267,7 @@ export default class PerformanceReporter {
counterMeasures.push({ counterMeasures.push({
metric: name, metric: name,
value, value,
timestamp: Math.round(now), timestamp: now,
}); });
} }