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

Feature/bai 1466 record who exports a model #1566

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion backend/src/connectors/audit/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@ export abstract class BaseAuditConnector {
)

abstract onCreateS3Export(req: Request, modelId: string, semvers?: string[])
abstract onCreateImport(req: Request, mirroredModelId: string, sourceModelId: string, modelCardVersions: number[])
abstract onCreateImport(
req: Request,
mirroredModelId: string,
sourceModelId: string,
modelCardVersions: number[],
exporter: string,
)

abstract onError(req: Request, error: BailoError)

Expand Down
8 changes: 7 additions & 1 deletion backend/src/connectors/audit/silly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ export class SillyAuditConnector extends BaseAuditConnector {
onUpdateInference(_req: Request, _inferences: InferenceDoc) {}
onCreateInference(_req: Request, _inferences: InferenceDoc) {}
onCreateS3Export(_req: Request, _modelId: string, _semvers?: string[]) {}
onCreateImport(_req: Request, _mirroredModelId: string, _sourceModelId: string, _modelCardVersions: number[]) {}
onCreateImport(
_req: Request,
_mirroredModelId: string,
_sourceModelId: string,
_modelCardVersions: number[],
_exporter: string,
) {}
onError(_req: Request, _error: BailoError) {}
onCreateCommentResponse(_req: Request, _responseInterface: ResponseInterface) {}
onViewResponses(_req: Request, _responseInters: ResponseInterface[]) {}
Expand Down
10 changes: 8 additions & 2 deletions backend/src/connectors/audit/stdout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,15 @@ export class StdoutAuditConnector extends BaseAuditConnector {
req.log.info(event, req.audit.description)
}

onCreateImport(req: Request, mirroredModelId: string, sourceModelId: string, modelCardVersions: number[]) {
onCreateImport(
req: Request,
mirroredModelId: string,
sourceModelId: string,
modelCardVersions: number[],
exporter: string,
) {
this.checkEventType(AuditInfo.CreateImport, req)
const event = this.generateEvent(req, { mirroredModelId, sourceModelId, modelCardVersions })
const event = this.generateEvent(req, { mirroredModelId, sourceModelId, modelCardVersions, exporter })
req.log.info(event, req.audit.description)
}
}
11 changes: 9 additions & 2 deletions backend/src/routes/v2/model/postRequestImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const postRequestImportFromS3Schema = z.object({
body: z.object({
payloadUrl: z.string(),
mirroredModelId: z.string(),
exporter: z.string(),
}),
})

Expand Down Expand Up @@ -48,11 +49,17 @@ export const postRequestImportFromS3 = [
async (req: Request, res: Response<PostRequestImportResponse>) => {
req.audit = AuditInfo.CreateImport
const {
body: { payloadUrl, mirroredModelId },
body: { payloadUrl, mirroredModelId, exporter },
} = parse(req, postRequestImportFromS3Schema)

const importInfo = await importModel(req.user, mirroredModelId, payloadUrl)
await audit.onCreateImport(req, importInfo.mirroredModelId, importInfo.sourceModelId, importInfo.modelCardVersions)
await audit.onCreateImport(
req,
importInfo.mirroredModelId,
importInfo.sourceModelId,
importInfo.modelCardVersions,
exporter,
)

return res.json(importInfo)
},
Expand Down
15 changes: 14 additions & 1 deletion backend/src/services/mirroredModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function exportModel(
if (config.modelMirror.export.kmsSignature.enabled) {
log.debug({ modelId, semvers }, 'Using signatures. Uploading to temporary S3 location first.')
uploadToTemporaryS3Location(modelId, semvers, s3Stream).then(() =>
copyToExportBucketWithSignatures(modelId, semvers, mirroredModelId).catch((error) =>
copyToExportBucketWithSignatures(modelId, semvers, mirroredModelId, user.dn).catch((error) =>
log.error({ modelId, semvers, error }, 'Failed to upload export to export location with signatures'),
),
)
Expand Down Expand Up @@ -92,6 +92,8 @@ export async function importModel(_user: UserInterface, mirroredModelId: string,
}
let sourceModelId

log.info({ mirroredModelId, payloadUrl }, 'Received a request to import a model.')

let res: Response
try {
res = await fetch(payloadUrl)
Expand All @@ -109,6 +111,8 @@ export async function importModel(_user: UserInterface, mirroredModelId: string,
throw InternalError('Unable to get the file.', { payloadUrl })
}

log.info({ mirroredModelId, payloadUrl }, 'Obtained the file from the payload URL.')

const modelCards: ModelCardRevisionInterface[] = []
const zipData = new Uint8Array(await res.arrayBuffer())
let zipContent
Expand All @@ -134,8 +138,15 @@ export async function importModel(_user: UserInterface, mirroredModelId: string,
modelCards.push(modelCard)
})

log.info({ mirroredModelId, payloadUrl, sourceModelId }, 'Finished parsing the collection of model cards.')

await Promise.all(modelCards.map((card) => saveImportedModelCard(card, sourceModelId)))
await setLatestImportedModelCard(mirroredModelId)
log.info(
{ mirroredModelId, payloadUrl, sourceModelId, modelCardVersions: modelCards.map((modelCard) => modelCard.version) },
'Finished importing the collection of model cards.',
)

return { mirroredModelId, sourceModelId, modelCardVersions: modelCards.map((modelCard) => modelCard.version) }
}

Expand All @@ -160,6 +171,7 @@ async function copyToExportBucketWithSignatures(
modelId: string,
semvers: string[] | undefined,
mirroredModelId: string,
exporter: string,
) {
let signatures = {}
log.debug({ modelId, semvers }, 'Getting stream from S3 to generate signatures.')
Expand All @@ -178,6 +190,7 @@ async function copyToExportBucketWithSignatures(
await uploadToExportS3Location(modelId, semvers, streamToCopy, {
modelId,
mirroredModelId,
exporter,
...signatures,
})
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/services/smtp/smtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async function sendEmail(email: Mail.Options) {
log.info({ messageId: info.messageId }, 'Email sent')
} catch (err) {
const content = { to: email.to, subject: email.subject, text: email.text }
log.warn(content, `Unable to send email`)
log.warn({ content, err }, `Unable to send email`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor, but as this will show in the logs can we call this error instead of err?

return Promise.reject(`Unable to send email: ${JSON.stringify(content)}`)
}
}
Expand Down
Loading