MCPcopy Create free account
hub / github.com/apache/devlake / downloadAndParseFile

Function downloadAndParseFile

backend/plugins/q_dev/tasks/s3_logging_extractor.go:184–240  ·  view source on GitHub ↗

downloadAndParseFile downloads one S3 file and parses it into model records

(
	taskCtx plugin.SubTaskContext,
	data *QDevTaskData,
	fileMeta *models.QDevS3FileMeta,
	displayNameCache *sync.Map,
)

Source from the content-addressed store, hash-verified

182
183// downloadAndParseFile downloads one S3 file and parses it into model records
184func downloadAndParseFile(
185 taskCtx plugin.SubTaskContext,
186 data *QDevTaskData,
187 fileMeta *models.QDevS3FileMeta,
188 displayNameCache *sync.Map,
189) downloadResult {
190 result := downloadResult{FileMeta: fileMeta}
191
192 getResult, err := data.S3Client.S3.GetObject(&s3.GetObjectInput{
193 Bucket: aws.String(data.S3Client.Bucket),
194 Key: aws.String(fileMeta.S3Path),
195 })
196 if err != nil {
197 result.Err = err
198 return result
199 }
200 defer getResult.Body.Close()
201
202 gzReader, err := gzip.NewReader(getResult.Body)
203 if err != nil {
204 result.Err = err
205 return result
206 }
207 defer gzReader.Close()
208
209 var logFile loggingFile
210 if err := json.NewDecoder(gzReader).Decode(&logFile); err != nil {
211 result.Err = err
212 return result
213 }
214
215 isChatLog := strings.Contains(fileMeta.S3Path, "GenerateAssistantResponse")
216
217 for _, rawRecord := range logFile.Records {
218 if isChatLog {
219 chatLog, err := parseChatRecord(rawRecord, fileMeta, data.IdentityClient, displayNameCache)
220 if err != nil {
221 result.Err = err
222 return result
223 }
224 if chatLog != nil {
225 result.ChatLogs = append(result.ChatLogs, chatLog)
226 }
227 } else {
228 compLog, err := parseCompletionRecord(rawRecord, fileMeta, data.IdentityClient, displayNameCache)
229 if err != nil {
230 result.Err = err
231 return result
232 }
233 if compLog != nil {
234 result.CompLogs = append(result.CompLogs, compLog)
235 }
236 }
237 }
238
239 return result
240}
241

Callers 1

parallelDownloadAndParseFunction · 0.85

Calls 4

parseChatRecordFunction · 0.85
parseCompletionRecordFunction · 0.85
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected