aggregates wsh:run events per (cmd, haderror) key within the current 1-hour bucket
(ctx context.Context, tevent *telemetrydata.TEvent)
| 199 | |
| 200 | // aggregates wsh:run events per (cmd, haderror) key within the current 1-hour bucket |
| 201 | func updateWshRunTEvent(ctx context.Context, tevent *telemetrydata.TEvent) error { |
| 202 | eventTs := time.Now().Truncate(time.Hour).Add(time.Hour) |
| 203 | incomingCount := tevent.Props.WshCount |
| 204 | if incomingCount <= 0 { |
| 205 | incomingCount = 1 |
| 206 | } |
| 207 | return wstore.WithTx(ctx, func(tx *wstore.TxWrap) error { |
| 208 | uuidStr := tx.GetString( |
| 209 | `SELECT uuid FROM db_tevent WHERE ts = ? AND event = ? AND json_extract(props, '$."wsh:cmd"') IS ?`, |
| 210 | eventTs.UnixMilli(), WshRunEventName, tevent.Props.WshCmd, |
| 211 | ) |
| 212 | if uuidStr != "" { |
| 213 | var curProps telemetrydata.TEventProps |
| 214 | rawProps := tx.GetString(`SELECT props FROM db_tevent WHERE uuid = ?`, uuidStr) |
| 215 | if rawProps != "" { |
| 216 | if err := json.Unmarshal([]byte(rawProps), &curProps); err != nil { |
| 217 | log.Printf("error unmarshalling wsh:run props: %v\n", err) |
| 218 | } |
| 219 | } |
| 220 | curCount := curProps.WshCount |
| 221 | if curCount <= 0 { |
| 222 | curCount = 1 |
| 223 | } |
| 224 | curProps.WshCount = curCount + incomingCount |
| 225 | curProps.WshErrorCount += tevent.Props.WshErrorCount |
| 226 | tx.Exec(`UPDATE db_tevent SET props = ? WHERE uuid = ?`, dbutil.QuickJson(curProps), uuidStr) |
| 227 | } else { |
| 228 | newProps := tevent.Props |
| 229 | newProps.WshCount = incomingCount |
| 230 | tsLocal := utilfn.ConvertToWallClockPT(eventTs).Format(time.RFC3339) |
| 231 | tx.Exec(`INSERT INTO db_tevent (uuid, ts, tslocal, event, props) VALUES (?, ?, ?, ?, ?)`, |
| 232 | uuid.New().String(), eventTs.UnixMilli(), tsLocal, WshRunEventName, dbutil.QuickJson(newProps)) |
| 233 | } |
| 234 | return nil |
| 235 | }) |
| 236 | } |
| 237 | |
| 238 | func TruncateActivityTEventForShutdown(ctx context.Context) error { |
| 239 | nowTs := time.Now() |
no test coverage detected