ignores the timestamp in tevent, and uses the current time
(ctx context.Context, tevent *telemetrydata.TEvent)
| 165 | |
| 166 | // ignores the timestamp in tevent, and uses the current time |
| 167 | func updateActivityTEvent(ctx context.Context, tevent *telemetrydata.TEvent) error { |
| 168 | eventTs := time.Now() |
| 169 | // compute to 1-hour boundary, and round up to next 1-hour boundary |
| 170 | eventTs = eventTs.Truncate(time.Hour).Add(time.Hour) |
| 171 | |
| 172 | return wstore.WithTx(ctx, func(tx *wstore.TxWrap) error { |
| 173 | // find event that matches this timestamp with event name "app:activity" |
| 174 | var hasRow bool |
| 175 | var curActivity telemetrydata.TEventProps |
| 176 | uuidStr := tx.GetString(`SELECT uuid FROM db_tevent WHERE ts = ? AND event = ?`, eventTs.UnixMilli(), ActivityEventName) |
| 177 | if uuidStr != "" { |
| 178 | hasRow = true |
| 179 | rawProps := tx.GetString(`SELECT props FROM db_tevent WHERE uuid = ?`, uuidStr) |
| 180 | err := json.Unmarshal([]byte(rawProps), &curActivity) |
| 181 | if err != nil { |
| 182 | // ignore, curActivity will just be 0 |
| 183 | log.Printf("error unmarshalling activity props: %v\n", err) |
| 184 | } |
| 185 | } |
| 186 | mergeActivity(&curActivity, tevent.Props) |
| 187 | |
| 188 | if hasRow { |
| 189 | query := `UPDATE db_tevent SET props = ? WHERE uuid = ?` |
| 190 | tx.Exec(query, dbutil.QuickJson(curActivity), uuidStr) |
| 191 | } else { |
| 192 | query := `INSERT INTO db_tevent (uuid, ts, tslocal, event, props) VALUES (?, ?, ?, ?, ?)` |
| 193 | tsLocal := utilfn.ConvertToWallClockPT(eventTs).Format(time.RFC3339) |
| 194 | tx.Exec(query, uuid.New().String(), eventTs.UnixMilli(), tsLocal, ActivityEventName, dbutil.QuickJson(curActivity)) |
| 195 | } |
| 196 | return nil |
| 197 | }) |
| 198 | } |
| 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 { |
no test coverage detected