Skip to content

Commit

Permalink
MM-60285 Add fresh label to channel and team switch metrics (mattermo…
Browse files Browse the repository at this point in the history
…st#28100)

* Changed measureAndReport to take an object as parameters

* MM-60285 Add fresh label to channel and team switch metrics
  • Loading branch information
hmhealey authored Sep 5, 2024
1 parent 8694b78 commit 8c5f00d
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 26 deletions.
14 changes: 12 additions & 2 deletions server/channels/app/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,19 @@ func (a *App) RegisterPerformanceReport(rctx request.CTX, report *model.Performa
case model.ClientPageLoadDuration:
a.Metrics().ObserveClientPageLoadDuration(commonLabels["platform"], commonLabels["agent"], h.Value/1000)
case model.ClientChannelSwitchDuration:
a.Metrics().ObserveClientChannelSwitchDuration(commonLabels["platform"], commonLabels["agent"], h.Value/1000)
a.Metrics().ObserveClientChannelSwitchDuration(
commonLabels["platform"],
commonLabels["agent"],
h.GetLabelValue("fresh", model.AcceptedTrueFalseLabels, ""),
h.Value/1000,
)
case model.ClientTeamSwitchDuration:
a.Metrics().ObserveClientTeamSwitchDuration(commonLabels["platform"], commonLabels["agent"], h.Value/1000)
a.Metrics().ObserveClientTeamSwitchDuration(
commonLabels["platform"],
commonLabels["agent"],
h.GetLabelValue("fresh", model.AcceptedTrueFalseLabels, ""),
h.Value/1000,
)
case model.ClientRHSLoadDuration:
a.Metrics().ObserveClientRHSLoadDuration(commonLabels["platform"], commonLabels["agent"], h.Value/1000)
case model.ClientGlobalThreadsLoadDuration:
Expand Down
4 changes: 2 additions & 2 deletions server/einterfaces/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ type MetricsInterface interface {
ObserveClientCumulativeLayoutShift(platform, agent string, elapsed float64)
IncrementClientLongTasks(platform, agent string, inc float64)
ObserveClientPageLoadDuration(platform, agent string, elapsed float64)
ObserveClientChannelSwitchDuration(platform, agent string, elapsed float64)
ObserveClientTeamSwitchDuration(platform, agent string, elapsed float64)
ObserveClientChannelSwitchDuration(platform, agent, fresh string, elapsed float64)
ObserveClientTeamSwitchDuration(platform, agent, fresh string, elapsed float64)
ObserveClientRHSLoadDuration(platform, agent string, elapsed float64)
ObserveGlobalThreadsLoadDuration(platform, agent string, elapsed float64)
ObserveMobileClientLoadDuration(platform string, elapsed float64)
Expand Down
12 changes: 6 additions & 6 deletions server/einterfaces/mocks/MetricsInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions server/enterprise/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ func New(ps *platform.PlatformService, driver, dataSource string) *MetricsInterf
Name: "channel_switch",
Help: "Duration of the time taken from when a user clicks on a channel in the LHS to when posts in that channel become visible (seconds)",
},
[]string{"platform", "agent"},
[]string{"platform", "agent", "fresh"},
)
m.Registry.MustRegister(m.ClientChannelSwitchDuration)

Expand All @@ -1273,7 +1273,7 @@ func New(ps *platform.PlatformService, driver, dataSource string) *MetricsInterf
Name: "team_switch",
Help: "Duration of the time taken from when a user clicks on a team in the LHS to when posts in that team become visible (seconds)",
},
[]string{"platform", "agent"},
[]string{"platform", "agent", "fresh"},
)
m.Registry.MustRegister(m.ClientTeamSwitchDuration)

Expand Down Expand Up @@ -1822,12 +1822,12 @@ func (mi *MetricsInterfaceImpl) ObserveClientPageLoadDuration(platform, agent st
mi.ClientPageLoadDuration.With(prometheus.Labels{"platform": platform, "agent": agent}).Observe(elapsed)
}

func (mi *MetricsInterfaceImpl) ObserveClientChannelSwitchDuration(platform, agent string, elapsed float64) {
mi.ClientChannelSwitchDuration.With(prometheus.Labels{"platform": platform, "agent": agent}).Observe(elapsed)
func (mi *MetricsInterfaceImpl) ObserveClientChannelSwitchDuration(platform, agent, fresh string, elapsed float64) {
mi.ClientChannelSwitchDuration.With(prometheus.Labels{"platform": platform, "agent": agent, "fresh": fresh}).Observe(elapsed)
}

func (mi *MetricsInterfaceImpl) ObserveClientTeamSwitchDuration(platform, agent string, elapsed float64) {
mi.ClientTeamSwitchDuration.With(prometheus.Labels{"platform": platform, "agent": agent}).Observe(elapsed)
func (mi *MetricsInterfaceImpl) ObserveClientTeamSwitchDuration(platform, agent, fresh string, elapsed float64) {
mi.ClientTeamSwitchDuration.With(prometheus.Labels{"platform": platform, "agent": agent, "fresh": fresh}).Observe(elapsed)
}

func (mi *MetricsInterfaceImpl) ObserveClientRHSLoadDuration(platform, agent string, elapsed float64) {
Expand Down
1 change: 1 addition & 0 deletions server/public/model/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (
"modal_content",
"other",
)
AcceptedTrueFalseLabels = sliceToMapKey("true", "false")
)

type MetricSample struct {
Expand Down
6 changes: 5 additions & 1 deletion webapp/channels/src/actions/views/rhs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,11 @@ export function setEditChannelMembers(active: boolean) {

export function measureRhsOpened() {
return () => {
measureAndReport(Measure.RhsLoad, Mark.PostSelected, undefined, true);
measureAndReport({
name: Measure.RhsLoad,
startMark: Mark.PostSelected,
canFail: true,
});

performance.clearMarks(Mark.PostSelected);
};
Expand Down
20 changes: 18 additions & 2 deletions webapp/channels/src/components/post_view/post_list/post_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,24 @@ function markAndMeasureChannelSwitchEnd(fresh = false) {
mark(Mark.PostListLoaded);

// Send new performance metrics to server
const channelSwitch = measureAndReport(Measure.ChannelSwitch, Mark.ChannelLinkClicked, Mark.PostListLoaded, true);
const teamSwitch = measureAndReport(Measure.TeamSwitch, Mark.TeamLinkClicked, Mark.PostListLoaded, true);
const channelSwitch = measureAndReport({
name: Measure.ChannelSwitch,
startMark: Mark.ChannelLinkClicked,
endMark: Mark.PostListLoaded,
labels: {
fresh: fresh.toString(),
},
canFail: true,
});
const teamSwitch = measureAndReport({
name: Measure.TeamSwitch,
startMark: Mark.TeamLinkClicked,
endMark: Mark.PostListLoaded,
labels: {
fresh: fresh.toString(),
},
canFail: true,
});

// Send old performance metrics to Rudder
if (shouldTrackPerformance()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ const GlobalThreads = () => {

useEffect(() => {
if (!isLoading) {
measureAndReport(Measure.GlobalThreadsLoad, Mark.GlobalThreadsLinkClicked, undefined, true);
measureAndReport({
name: Measure.GlobalThreadsLoad,
startMark: Mark.GlobalThreadsLinkClicked,
canFail: true,
});
performance.clearMarks(Mark.GlobalThreadsLinkClicked);
}
}, [isLoading]);
Expand Down
19 changes: 16 additions & 3 deletions webapp/channels/src/utils/performance_telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,34 @@ export function markAndReport(name: string): PerformanceMark {
* If either the start or end mark does not exist, undefined will be returned and, if canFail is false, an error
* will be logged.
*/
export function measureAndReport(measureName: string, startMark: string, endMark: string | undefined, canFail = false): PerformanceMeasure | undefined {
export function measureAndReport({
name,
startMark,
endMark,
labels,
canFail = false,
}: {
name: string;
startMark: string;
endMark?: string;
labels?: Record<string, string>;
canFail?: boolean;
}): PerformanceMeasure | undefined {
const options: PerformanceMeasureOptions = {
start: startMark,
end: endMark,
detail: {
labels,
report: true,
},
};

try {
return performance.measure(measureName, options);
return performance.measure(name, options);
} catch (e) {
if (!canFail) {
// eslint-disable-next-line no-console
console.error('Unable to measure ' + measureName, e);
console.error('Unable to measure ' + name, e);
}

return undefined;
Expand Down
18 changes: 15 additions & 3 deletions webapp/channels/src/utils/performance_telemetry/reporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,26 @@ describe('PerformanceReporter', () => {
performance.mark('testMarkA');
performance.mark('testMarkB');

measureAndReport('testMeasureA', 'testMarkA', 'testMarkB');
measureAndReport({
name: 'testMeasureA',
startMark: 'testMarkA',
endMark: 'testMarkB',
});

await waitForObservations();

performance.mark('testMarkC');

measureAndReport('testMeasureB', 'testMarkA', 'testMarkC');
measureAndReport('testMeasureC', 'testMarkB', 'testMarkC');
measureAndReport({
name: 'testMeasureB',
startMark: 'testMarkA',
endMark: 'testMarkC',
});
measureAndReport({
name: 'testMeasureC',
startMark: 'testMarkB',
endMark: 'testMarkC',
});

await waitForObservations();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export default class PerformanceReporter {
this.histogramMeasures.push({
metric: entry.name,
value: entry.duration,
labels: entry.detail.labels,
timestamp: Date.now(),
});
}
Expand Down

0 comments on commit 8c5f00d

Please sign in to comment.