Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dylan/s3en 2264 add date filters to the metrics dashboard charts #106

Prev Previous commit
Next Next commit
clean up
  • Loading branch information
dylanzuber-scale3 committed May 16, 2024
commit 812e239999a7c66ef99a7ee49625983e7f41f931
4 changes: 2 additions & 2 deletions components/charts/latency-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function TraceLatencyChart({
})
);

const countData = metricsLatencyAverageTracePerDay?.totalTracesPerDay?.map(
const countData = metricsLatencyAverageTracePerDay?.totalTracesPerHour?.map(
(data: any, index: number) => ({
date: data?.date || "",
"Trace Count": data?.traceCount || 0,
Expand All @@ -80,7 +80,7 @@ export function TraceLatencyChart({
const data = avgLatencyData?.map((avgLatency: any, index: number) => {
return {
...avgLatency,
// "Trace Count": countData[index]["Trace Count"],
"Trace Count": countData[index]["Trace Count"],
"p99 Trace Latency(ms)": p99LatencyData[index]["p99 Trace Latency(ms)"],
"p95 Trace Latency(ms)": p95LatencyData[index]["p95 Trace Latency(ms)"],
};
Expand Down
43 changes: 14 additions & 29 deletions lib/services/trace_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ export interface PaginationResult<T> {
metadata?: { page?: number; page_size?: number; total_pages: number };
}

function getFormattedTime(lastNHours: number): string {
const nHoursAgo = format(
new Date(Date.now() - lastNHours * 60 * 60 * 1000),
"yyyy-MM-dd HH:mm:ss"
);
return nHoursAgo;
}

export interface ITraceService {
GetTotalTracePerHourPerProject: (
project_id: string,
Expand Down Expand Up @@ -175,10 +183,7 @@ export class TraceService implements ITraceService {
project_id: string,
lastNHours = 168
): Promise<any> {
const nHoursAgo = format(
new Date(Date.now() - lastNHours * 60 * 60 * 1000),
"yyyy-MM-dd HH:mm:ss"
);
const nHoursAgo = getFormattedTime(lastNHours);
try {
const tableExists = await this.client.checkTableExists(project_id);
if (!tableExists) {
Expand Down Expand Up @@ -227,10 +232,7 @@ export class TraceService implements ITraceService {
project_id: string,
lastNHours = 168
): Promise<any> {
const nHoursAgo = format(
new Date(Date.now() - lastNHours * 60 * 60 * 1000),
"yyyy-MM-dd HH:mm:ss"
);
const nHoursAgo = getFormattedTime(lastNHours);
try {
const tableExists = await this.client.checkTableExists(project_id);
if (!tableExists) {
Expand Down Expand Up @@ -405,10 +407,7 @@ export class TraceService implements ITraceService {
if (!lastNHours) {
return await this.client.find<Span[]>(query);
} else {
const nHoursAgo = format(
new Date(Date.now() - lastNHours * 60 * 60 * 1000),
"yyyy-MM-dd HH:mm:ss"
);
const nHoursAgo = getFormattedTime(lastNHours);
query.where(sql.gte("start_time", nHoursAgo));

return await this.client.find<Span[]>(query);
Expand Down Expand Up @@ -506,10 +505,7 @@ export class TraceService implements ITraceService {
};
}

const nHoursAgo = format(
new Date(Date.now() - lastNHours * 60 * 60 * 1000),
"yyyy-MM-dd HH:mm:ss"
);
const nHoursAgo = getFormattedTime(lastNHours);

// Directly embedding the ClickHouse-specific functions within string literals
let innerSelect = sql
Expand Down Expand Up @@ -591,10 +587,7 @@ export class TraceService implements ITraceService {
return [];
}

const nHoursAgo = format(
new Date(Date.now() - lastNHours * 60 * 60 * 1000),
"yyyy-MM-dd HH:mm:ss"
);
const nHoursAgo = getFormattedTime(lastNHours);

const query = sql
.select([
Expand Down Expand Up @@ -665,15 +658,7 @@ export class TraceService implements ITraceService {
return [];
}

// const nDaysAgo = format(
// new Date(Date.now() - lastNDays * 24 * 60 * 60 * 1000),
// "yyyy-MM-dd"
// );

const nHoursAgo = format(
new Date(Date.now() - lastNHours * 60 * 60 * 1000),
"yyyy-MM-dd HH:mm:ss"
);
const nHoursAgo = getFormattedTime(lastNHours);

const query = sql
.select([
Expand Down