Commit Graph
15 Commits
Author SHA1 Message Date
Nico b0dc97006c Dedupe network errors so usage_statistics cron stops failing (#45142)
**Related issue:** Resolves #42613

Dedupes errors that report HTTP 408 (request timeouts). As of now, I
believe this only fires for timeouts on the
**/api/v1/osquery/distributed/write** endpoint.
This is so that we have a unique error hash with an incrementing count,
instead of thousands of entries each with count: 1, which produces a
huge JSON payload when passed to
https://fleetdm.com/api/v1/webhooks/receive-usage-analytics for
processing.

Trade-off:
- Before: every occurrence got its own Redis entry so thousands of
near-identical examples coexisted.
- After: they collapse into one entry whose :json value still contains a
representative example, but we'd only keep the last IP+Port instead of
all of them.

# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

## Testing

- [x] Added/updated automated tests

- [x] QA'd all new/changed functionality manually

Build a ~5 MB JSON body in a temporary file:

```bash
{ printf '{"node_key":"'; head -c 5000000 /dev/zero | tr '\0' 'x'; printf '"}'; } > /tmp/distwrite-body.json
```

Clear out redis:

```bash
docker exec fleet-redis-1 redis-cli FLUSHDB
```

Send a dummy request and throttle the upload at 100 KB/s → ~50s to send,
read timeout fires at 25s.
I sent this 3 times and got the "request body read error" error back
after each request.

```bash
curl -sk --limit-rate 100K -X POST -H 'Content-Type: application/json' --data-binary @/tmp/distwrite-body.json https://127.0.0.1:8080/api/v1/osquery/distributed/write

{
  "error": "request body read error: i/o timeout",
  "uuid": "95937f50-1008-4625-9423-bc19c7be6818"
}
```

Count the error keys containing "request body read error" as the value. 

```bash
docker exec fleet-redis-1 sh -c 'for k in $(redis-cli --scan --pattern "error:*:json"); do v=$(redis-cli GET "$k"); echo "$v" | grep -q "request body read error" && echo "$k count=$(redis-cli GET "${k%:json}:count")"; done'\

error:{Cco_JmAdBVVVJI9k0XjNNUCmG0z1IKguMQD4VDaejfc=}:json count=3
```

Notice the single entry and count=3 (since I ran the dummy request 3
times).

Running this on main outputs three entries each with count=1.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Network error deduplication for request-timeout errors now normalizes
socket addresses, preventing the usage statistics cron from failing when
many similar network errors accumulate.

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/fleetdm/fleet/pull/45142)

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-11 22:21:57 +02:00
Victor Lyuboslavsky 70ffac6341 Incremental migration to slog (#40120)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #40054 

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
  - Already added in previous PR

## Testing

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Updated internal logging infrastructure across multiple server
components to use standardized logging methods and improved context
propagation.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-19 15:35:35 -06:00
Roberto Dip 1cc13a09fb 🧹 friday cleanup party: substitute deprecated import of go-kit (#19774)
`go-kit/kit/log` was deprecated and generating warnings

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Manual QA for all new/changed functionality
2024-06-17 10:27:31 -03:00
gillespi314 6fb3a87ae9 Enable errcheck linter for golangci-lint (#8899) 2022-12-05 16:50:49 -06:00
Roberto Dip b2d07e56b5 report error analytics (#6341)
Related to #5898, this reports an anonymized summary of errors stored in Redis into the analytics payload.

For each error stored, this includes:

- A `count` attribute with the number of occurrences of the error
- A `loc` attribute with the 3 topmost lines in the stack trace. Note that stack traces only contain package name + line number (example: github.com/fleetdm/fleet/server.go:12

This also includes a minor refactor around error types.
2022-06-28 16:31:14 -03:00
Roberto Dip 984605f630 store count alongside unique error instances in Redis (#6232)
Related to #4972, this adds a new key, error:<hash>:count to Redis in order to keep track of how many times each instance of an error occurred.
2022-06-21 08:43:53 -03:00
Michal Nicpon 983f9e59b3 Include CVE scores when listing software (#5673) 2022-05-20 10:58:40 -06:00
Roberto Dip 894fa22c71 implement a thin wrapper around stdlib errors (#5733)
This solves #5679 , and also implements #5515, #5509 and lays the ground for #5516

With the introduction of Wrap, Is and As in the standard library, we've now got built-in support for wrapping.

On top of that, a common pattern in the community is to define errors tailored to the context of each project while still conforming to the error and Unwrap interfaces (see Upspin, Chromium)

The output now includes stack traces and additional info
2022-05-18 11:47:55 -03:00
Roberto Dip cba78bdcd1 don't clear errors automatically when reading them from Redis (#5623)
this change prevents errors from being automatically cleared once they are read. A new flag `-flush` is introduced to flush errors on read if necessary.
2022-05-10 11:44:43 -03:00
Martin Angers afb3310937 Migrate team-related endpoints to new pattern (#3740) 2022-01-19 10:52:14 -05:00
Martin Angers 4143a37056 Fix redis scan keys issue for live queries (#3107) 2021-12-14 16:30:26 -05:00
Martin Angers 69a4985cac Use new error handling approach in other packages (#2954) 2021-11-22 09:13:26 -05:00
Zach Wasserman e04f210f51 Disable storage of errors (#3066)
This is a temporary mitigation for the issue described in #3065.

The intent is to merge this, cut a 4.6.1 release, and then come up with
a more comprehensive solution for 4.7.0.
2021-11-21 21:02:20 -08:00
Martin Angers 3ae57a0242 Create errors with ctxerr, add the call to store them in redis (#2786) 2021-11-15 09:11:38 -05:00
Tomas Touceda 2902da76ca Issue 2027 better error visibility (#2069) 2021-11-02 13:35:57 -04:00