v3: run.isTest now propagates through child tasks and the trace (#917)

* run.isTest now propagates through child tasks and the trace

* Try to fix the pr checks docker hub rate limit error
This commit is contained in:
Eric Allam
2024-02-28 17:01:31 +00:00
committed by GitHub
parent b6517af522
commit 933cf0f119
13 changed files with 43 additions and 16 deletions
+2 -3
View File
@@ -7,11 +7,10 @@ jobs:
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: 🐳 Login to Docker Hub
if: github.event_name == 'push'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ secrets.DOCKERHUB_USERNAME || vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN || vars.DOCKERHUB_TOKEN }}
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
@@ -42,6 +42,7 @@ export type TraceAttributes = Partial<
| "attemptId"
| "isError"
| "runId"
| "runIsTest"
| "output"
| "metadata"
| "properties"
@@ -376,6 +377,7 @@ export class EventRepository {
[SemanticInternalAttributes.PROJECT_ID]: options.environment.projectId,
[SemanticInternalAttributes.PROJECT_REF]: options.environment.project.externalRef,
[SemanticInternalAttributes.RUN_ID]: options.attributes.runId,
[SemanticInternalAttributes.RUN_IS_TEST]: options.attributes.runIsTest ?? false,
[SemanticInternalAttributes.TASK_SLUG]: options.taskSlug,
[SemanticResourceAttributes.SERVICE_NAME]: "api server",
[SemanticResourceAttributes.SERVICE_NAMESPACE]: "trigger.dev",
@@ -410,6 +412,7 @@ export class EventRepository {
projectId: options.environment.projectId,
projectRef: options.environment.project.externalRef,
runId: options.attributes.runId,
runIsTest: options.attributes.runIsTest ?? false,
taskSlug: options.taskSlug,
queueId: options.attributes.queueId,
queueName: options.attributes.queueName,
@@ -489,6 +492,7 @@ export class EventRepository {
[SemanticInternalAttributes.PROJECT_ID]: options.environment.projectId,
[SemanticInternalAttributes.PROJECT_REF]: options.environment.project.externalRef,
[SemanticInternalAttributes.RUN_ID]: options.attributes.runId,
[SemanticInternalAttributes.RUN_IS_TEST]: options.attributes.runIsTest ?? false,
[SemanticInternalAttributes.TASK_SLUG]: options.taskSlug,
[SemanticResourceAttributes.SERVICE_NAME]: "api server",
[SemanticResourceAttributes.SERVICE_NAMESPACE]: "trigger.dev",
@@ -524,6 +528,7 @@ export class EventRepository {
projectId: options.environment.projectId,
projectRef: options.environment.project.externalRef,
runId: options.attributes.runId,
runIsTest: options.attributes.runIsTest ?? false,
taskSlug: options.taskSlug,
queueId: options.attributes.queueId,
queueName: options.attributes.queueName,
@@ -386,6 +386,7 @@ export class DevQueueConsumer {
context: lockedTaskRun.context,
createdAt: lockedTaskRun.createdAt,
tags: lockedTaskRun.tags.map((tag) => tag.name),
isTest: lockedTaskRun.isTest,
},
queue: {
id: queue.friendlyId,
+15 -1
View File
@@ -25,7 +25,6 @@ import {
CreatableEventEnvironmentType,
} from "./eventRepository.server";
import { logger } from "~/services/logger.server";
import { env } from "~/env.server";
export type OTLPExporterConfig = {
batchSize: number;
@@ -263,6 +262,7 @@ function extractResourceProperties(attributes: KeyValue[]) {
"unknown"
),
runId: extractStringAttribute(attributes, SemanticInternalAttributes.RUN_ID, "unknown"),
runIsTest: extractBooleanAttribute(attributes, SemanticInternalAttributes.RUN_IS_TEST, false),
attemptId: extractStringAttribute(attributes, SemanticInternalAttributes.ATTEMPT_ID),
attemptNumber: extractNumberAttribute(attributes, SemanticInternalAttributes.ATTEMPT_NUMBER),
taskSlug: extractStringAttribute(attributes, SemanticInternalAttributes.TASK_SLUG, "unknown"),
@@ -506,6 +506,20 @@ function extractNumberAttribute(
return isIntValue(attribute?.value) ? Number(attribute.value.value.intValue) : fallback;
}
function extractBooleanAttribute(attributes: KeyValue[], name: string): boolean | undefined;
function extractBooleanAttribute(attributes: KeyValue[], name: string, fallback: boolean): boolean;
function extractBooleanAttribute(
attributes: KeyValue[],
name: string,
fallback?: boolean
): boolean | undefined {
const attribute = attributes.find((attribute) => attribute.key === name);
if (!attribute) return fallback;
return isBoolValue(attribute?.value) ? attribute.value.value.boolValue : fallback;
}
function isPartialSpan(span: Span): boolean {
if (!span.attributes) return false;
@@ -16,13 +16,11 @@ export class TestTaskService extends BaseService {
}
const triggerTaskService = new TriggerTaskService();
return await triggerTaskService.call(
data.taskIdentifier,
authenticatedEnvironment,
{ payload: data.payload },
{
isTest: true,
}
);
return await triggerTaskService.call(data.taskIdentifier, authenticatedEnvironment, {
payload: data.payload,
options: {
test: true,
},
});
}
}
@@ -2,7 +2,6 @@ import {
PRIMARY_VARIANT,
SemanticInternalAttributes,
TriggerTaskRequestBody,
flattenAttributes,
} from "@trigger.dev/core/v3";
import { nanoid } from "nanoid";
import { createHash } from "node:crypto";
@@ -17,7 +16,6 @@ export type TriggerTaskServiceOptions = {
idempotencyKey?: string;
triggerVersion?: string;
traceContext?: Record<string, string | undefined>;
isTest?: boolean;
};
export class TriggerTaskService extends BaseService {
@@ -61,6 +59,7 @@ export class TriggerTaskService extends BaseService {
icon: "play",
variant: PRIMARY_VARIANT,
},
runIsTest: body.options?.test ?? false,
},
incomplete: true,
immediate: true,
@@ -112,7 +111,7 @@ export class TriggerTaskService extends BaseService {
lockedToVersionId: lockedToBackgroundWorker?.id,
concurrencyKey: body.options?.concurrencyKey,
queue: queueName,
isTest: options.isTest ?? false,
isTest: body.options?.test ?? false,
},
});
+1
View File
@@ -41,6 +41,7 @@ export const TriggerTaskRequestBody = z.object({
lockToVersion: z.string().optional(),
queue: QueueOptions.optional(),
concurrencyKey: z.string().optional(),
test: z.boolean().optional(),
})
.optional(),
});
+1
View File
@@ -51,6 +51,7 @@ export const TaskRun = z.object({
payloadType: z.string(),
context: z.any(),
tags: z.array(z.string()),
isTest: z.boolean().default(false),
createdAt: z.coerce.date(),
});
@@ -11,6 +11,7 @@ export const SemanticInternalAttributes = {
ATTEMPT_ID: "ctx.attempt.id",
ATTEMPT_NUMBER: "ctx.attempt.number",
RUN_ID: "ctx.run.id",
RUN_IS_TEST: "ctx.run.isTest",
TASK_SLUG: "ctx.task.id",
TASK_PATH: "ctx.task.filePath",
TASK_EXPORT_NAME: "ctx.task.exportName",
@@ -80,6 +80,7 @@ export class TaskContextManager {
[SemanticInternalAttributes.PROJECT_REF]: this.ctx.project.ref,
[SemanticInternalAttributes.PROJECT_NAME]: this.ctx.project.name,
[SemanticInternalAttributes.RUN_ID]: this.ctx.run.id,
[SemanticInternalAttributes.RUN_IS_TEST]: this.ctx.run.isTest,
[SemanticInternalAttributes.ORGANIZATION_SLUG]: this.ctx.organization.slug,
[SemanticInternalAttributes.ORGANIZATION_NAME]: this.ctx.organization.name,
};
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "TaskEvent" ADD COLUMN "runIsTest" BOOLEAN NOT NULL DEFAULT false;
+2 -1
View File
@@ -1724,7 +1724,8 @@ model TaskEvent {
projectId String
projectRef String
runId String
runId String
runIsTest Boolean @default(false)
taskSlug String
taskPath String?
+4
View File
@@ -165,6 +165,7 @@ export function createTask<TInput, TOutput, TInitOutput extends InitOutput>(
options: {
queue: params.queue,
concurrencyKey: options?.concurrencyKey,
test: taskContextManager.ctx?.run.isTest,
},
});
@@ -221,6 +222,7 @@ export function createTask<TInput, TOutput, TInitOutput extends InitOutput>(
options: {
queue: item.options?.queue ?? params.queue,
concurrencyKey: item.options?.concurrencyKey,
test: taskContextManager.ctx?.run.isTest,
},
})),
});
@@ -287,6 +289,7 @@ export function createTask<TInput, TOutput, TInitOutput extends InitOutput>(
lockToVersion: taskContextManager.worker?.version, // Lock to current version because we're waiting for it to finish
queue: params.queue,
concurrencyKey: options?.concurrencyKey,
test: taskContextManager.ctx?.run.isTest,
},
});
@@ -357,6 +360,7 @@ export function createTask<TInput, TOutput, TInitOutput extends InitOutput>(
lockToVersion: taskContextManager.worker?.version,
queue: item.options?.queue ?? params.queue,
concurrencyKey: item.options?.concurrencyKey,
test: taskContextManager.ctx?.run.isTest,
},
})),
dependentAttempt: ctx.attempt.id,