Skip to content

Commit

Permalink
Add support for module name (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
flenter authored Jun 8, 2023
1 parent d13655d commit 2f28d33
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/charts/components/SingleChart/SingleChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ function getQuery(options: PanelOptions) {
case "called_by":
return getCalledByRequestRate(options.functionName);
case "function":
return getRequestRate(options.functionName);
return getRequestRate(
options.functionName,
options.moduleName
? {
module: options.moduleName,
}
: undefined,
);
case "metric":
return getSumQuery(options.metricName);
default:
Expand Down
7 changes: 5 additions & 2 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ const HISTOGRAM_BUCKET_NAME = "function_calls_duration_bucket";
const ADD_BUILD_INFO_LABELS =
"* on (instance, job) group_left(version, commit) last_over_time(build_info[1s])";

export function getRequestRate(functionName: string) {
export function getRequestRate(
functionName: string,
labels: Record<string, string> = {},
) {
return `# Rate of calls to the \`${functionName}\` function per second, averaged over 5 minute windows
${getSumQuery(COUNTER_NAME, { function: functionName })}`;
${getSumQuery(COUNTER_NAME, { ...labels, function: functionName })}`;
}

export function getCalledByRequestRate(functionName: string) {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/getTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export function getTitle(options: PanelOptions) {
case "called_by":
return `Called by ${options.functionName}`;
case "function":
if (options.moduleName) {
return `${options.moduleName}::${options.functionName}`;
}
return options.functionName;
case "metric":
return options.metricName;
Expand Down

0 comments on commit 2f28d33

Please sign in to comment.