in pkg/client/client_v2.go [532:573]
func (c *clientV2) sendObserved(client proto.ElasticAgent_CheckinV2Client) error {
c.unitsMu.RLock()
observed := make([]*proto.UnitObserved, 0, len(c.units))
for _, unit := range c.units {
observed = append(observed, unit.toObserved())
}
// Check featuresIdx within the same mutex block since we
// need observed and featuresIdx to be synchronized with each other.
featuresIdx := c.featuresIdx
c.unitsMu.RUnlock()
c.componentMu.RLock()
componentIdx := c.componentIdx
c.componentMu.RUnlock()
msg := &proto.CheckinObserved{
Token: c.token,
Units: observed,
FeaturesIdx: featuresIdx,
ComponentIdx: componentIdx,
VersionInfo: nil,
}
if !c.versionInfoSent {
msg.VersionInfo = &proto.CheckinObservedVersionInfo{
Name: c.versionInfo.Name,
Meta: c.versionInfo.Meta,
BuildHash: c.versionInfo.BuildHash,
}
// supports information is sent when version information is set,
// this ensures that its always sent once per connected loop
if c.opts.chunkingAllowed {
msg.Supports = []proto.ConnectionSupports{proto.ConnectionSupports_CheckinChunking}
}
}
err := sendObservedChunked(client, msg, c.opts.chunkingAllowed, c.opts.maxMessageSize)
if err != nil && !errors.Is(err, io.EOF) {
c.errCh <- err
} else {
c.versionInfoSent = true
}
return err
}