-
Notifications
You must be signed in to change notification settings - Fork 8
/
reject_client.go
46 lines (40 loc) · 1.54 KB
/
reject_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package trace2receiver
import "errors"
// There are some clients that we want to reject as soon as we
// learn their identity. Primarily this is for daemon Git processes
// like `git fsmonitor--daemon run` and `git daemon` (and their dash
// name peers) that run (for days/months) in the background. Since
// we do not generate the OTLP process span until the client drops
// the connection (ideally after the `atexit` event), we would be
// forced to collect massive state for the background daemon and
// bog down the entire telemetry service. So let's reject them as
// soon as we identify them.
//
// There may be other background commands (like the new bundle server),
// so we may have to have more than one detection methods.
//
// At this point I'm just going to hard code the rejection. I don't
// think it is worth adding code to `FilterSettings` to make this
// optional.
type RejectClientError struct {
Err error
FSMonitor bool
}
func (rce *RejectClientError) Error() string {
return rce.Err.Error()
}
// Is this Git command a `git fsmonitor--daemon` command?
//
// Check in `apply__cmd_name()` since we know FSMonitor sends a valid
// `cmd_name` event. We really only need to reject `run` commands,
// but unfortunately, it does not send `cmd_mode` events, so we cannot
// distinguish between `run`, `start` and `stop`.
func IsFSMonitorDaemon(verb string) error {
if verb == "fsmonitor--daemon" {
return &RejectClientError{
Err: errors.New("rejecting telemetry from fsmonitor--daemon"),
FSMonitor: true,
}
}
return nil
}