-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Tim Rühsen <[email protected]>
- Loading branch information
1 parent
e113282
commit 9c4b3f2
Showing
8 changed files
with
245 additions
and
38 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package collector // import "go.opentelemetry.io/ebpf-profiler/collector" | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"time" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/consumer/xconsumer" | ||
"go.opentelemetry.io/collector/receiver" | ||
"go.opentelemetry.io/collector/receiver/xreceiver" | ||
|
||
"go.opentelemetry.io/ebpf-profiler/collector/internal" | ||
"go.opentelemetry.io/ebpf-profiler/internal/controller" | ||
) | ||
|
||
var ( | ||
typeStr = component.MustNewType("profiling") | ||
|
||
errInvalidConfig = errors.New("invalid config") | ||
) | ||
|
||
// NewFactory creates a factory for the receiver. | ||
func NewFactory() receiver.Factory { | ||
return xreceiver.NewFactory( | ||
typeStr, | ||
defaultConfig, | ||
xreceiver.WithProfiles(createProfilesReceiver, component.StabilityLevelAlpha)) | ||
} | ||
|
||
func createProfilesReceiver( | ||
_ context.Context, | ||
_ receiver.Settings, //nolint:gocritic // we must respect the collector API | ||
baseCfg component.Config, | ||
nextConsumer xconsumer.Profiles) (xreceiver.Profiles, error) { | ||
cfg, ok := baseCfg.(*controller.Config) | ||
if !ok { | ||
return nil, errInvalidConfig | ||
} | ||
|
||
return internal.NewController(cfg, nextConsumer) | ||
} | ||
|
||
func defaultConfig() component.Config { | ||
return &controller.Config{ | ||
ReporterInterval: 5 * time.Second, | ||
MonitorInterval: 5 * time.Second, | ||
SamplesPerSecond: 20, | ||
ProbabilisticInterval: 1 * time.Minute, | ||
ProbabilisticThreshold: 100, | ||
Tracers: "all", | ||
ClockSyncInterval: 3 * time.Minute, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package collector | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
"go.opentelemetry.io/collector/receiver/receivertest" | ||
) | ||
|
||
func TestNewFactory(t *testing.T) { | ||
f := NewFactory() | ||
require.NotNil(t, f) | ||
} | ||
|
||
func TestCreateProfilesReceiver(t *testing.T) { | ||
for _, tt := range []struct { | ||
name string | ||
config component.Config | ||
|
||
wantError error | ||
}{ | ||
{ | ||
name: "Default config", | ||
config: defaultConfig(), | ||
}, | ||
{ | ||
name: "Nil config", | ||
wantError: errInvalidConfig, | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
_, err := createProfilesReceiver( | ||
context.Background(), | ||
receivertest.NewNopSettings(), | ||
tt.config, | ||
consumertest.NewNop(), | ||
) | ||
require.ErrorIs(t, err, tt.wantError) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package internal // import "go.opentelemetry.io/ebpf-profiler/collector/internal" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/consumer/xconsumer" | ||
|
||
"go.opentelemetry.io/ebpf-profiler/internal/controller" | ||
"go.opentelemetry.io/ebpf-profiler/reporter" | ||
"go.opentelemetry.io/ebpf-profiler/times" | ||
) | ||
|
||
// Controller is a bridge between the Collector's [receiverprofiles.Profiles] | ||
// interface and our [internal.Controller] | ||
type Controller struct { | ||
ctlr *controller.Controller | ||
} | ||
|
||
func NewController(cfg *controller.Config, | ||
nextConsumer xconsumer.Profiles) (*Controller, error) { | ||
intervals := times.New(cfg.MonitorInterval, | ||
cfg.ReporterInterval, cfg.ProbabilisticInterval) | ||
|
||
rep, err := reporter.NewCollector(&reporter.Config{ | ||
MaxRPCMsgSize: 32 << 20, // 32 MiB | ||
MaxGRPCRetries: 5, | ||
GRPCOperationTimeout: intervals.GRPCOperationTimeout(), | ||
GRPCStartupBackoffTime: intervals.GRPCStartupBackoffTime(), | ||
GRPCConnectionTimeout: intervals.GRPCConnectionTimeout(), | ||
ReportInterval: intervals.ReportInterval(), | ||
ExecutablesCacheElements: 16384, | ||
// Next step: Calculate FramesCacheElements from numCores and samplingRate. | ||
FramesCacheElements: 65536, | ||
CGroupCacheElements: 1024, | ||
SamplesPerSecond: cfg.SamplesPerSecond, | ||
}, nextConsumer) | ||
if err != nil { | ||
return nil, err | ||
} | ||
cfg.Reporter = rep | ||
|
||
return &Controller{ | ||
ctlr: controller.New(cfg), | ||
}, nil | ||
} | ||
|
||
// Start starts the receiver. | ||
func (c *Controller) Start(ctx context.Context, _ component.Host) error { | ||
return c.ctlr.Start(ctx) | ||
} | ||
|
||
// Shutdown stops the receiver. | ||
func (c *Controller) Shutdown(_ context.Context) error { | ||
c.ctlr.Shutdown() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters