Skip to content

Commit

Permalink
[chore][receiver/sqlserver] Rename and move Windows-specific logic (#…
Browse files Browse the repository at this point in the history
…32471)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
A major part of
#31915
is adding support for other operating systems than Windows. This change
moves Windows-specific logic into files named as such, and renames some
specific functionality to match purpose, instead of generic names.

`newSQLServerScraper` -> `newSQLServerPCScraper` (PC in this context
stands for performance counters)
`sqlServerScraper` -> `sqlServerPCScraper``

This only renames internal functions and files, there's no user-facing
impact of this.

**Link to tracking Issue:** <Issue number if applicable>

#31915

#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Existing tests are passing.
  • Loading branch information
crobert-1 authored Apr 17, 2024
1 parent 8012101 commit 6f25527
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion receiver/sqlserverreceiver/factory_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func createMetricsReceiver(
if !ok {
return nil, errConfigNotSQLServer
}
sqlServerScraper := newSQLServerScraper(params, cfg)
sqlServerScraper := newSQLServerPCScraper(params, cfg)

scraper, err := scraperhelper.NewScraper(metadata.Type.String(), sqlServerScraper.scrape,
scraperhelper.WithStart(sqlServerScraper.start),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata"
)

type sqlServerScraper struct {
// SQL Server Perf Counter (PC) Scraper. This is used to scrape metrics from Windows Perf Counters.
type sqlServerPCScraper struct {
logger *zap.Logger
config *Config
watcherRecorders []watcherRecorder
Expand All @@ -37,17 +38,17 @@ type watcherRecorder struct {
// it needs metadata.MetricsBuilder and timestamp as arguments.
type curriedRecorder func(*metadata.MetricsBuilder, pcommon.Timestamp)

// newSQLServerScraper returns a new sqlServerScraper.
func newSQLServerScraper(params receiver.CreateSettings, cfg *Config) *sqlServerScraper {
return &sqlServerScraper{
// newSQLServerPCScraper returns a new sqlServerPCScraper.
func newSQLServerPCScraper(params receiver.CreateSettings, cfg *Config) *sqlServerPCScraper {
return &sqlServerPCScraper{
logger: params.Logger,
config: cfg,
mb: metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, params),
}
}

// start creates and sets the watchers for the scraper.
func (s *sqlServerScraper) start(_ context.Context, _ component.Host) error {
func (s *sqlServerPCScraper) start(_ context.Context, _ component.Host) error {
s.watcherRecorders = []watcherRecorder{}

for _, pcr := range perfCounterRecorders {
Expand All @@ -71,7 +72,7 @@ func (s *sqlServerScraper) start(_ context.Context, _ component.Host) error {
}

// scrape collects windows performance counter data from all watchers and then records/emits it using the metricBuilder
func (s *sqlServerScraper) scrape(_ context.Context) (pmetric.Metrics, error) {
func (s *sqlServerPCScraper) scrape(_ context.Context) (pmetric.Metrics, error) {
recordersByDatabase, errs := recordersPerDatabase(s.watcherRecorders)

for dbName, recorders := range recordersByDatabase {
Expand Down Expand Up @@ -113,7 +114,7 @@ func recordersPerDatabase(watcherRecorders []watcherRecorder) (map[string][]curr
return dbToRecorders, errs
}

func (s *sqlServerScraper) emitMetricGroup(recorders []curriedRecorder, databaseName string) {
func (s *sqlServerPCScraper) emitMetricGroup(recorders []curriedRecorder, databaseName string) {
now := pcommon.NewTimestampFromTime(time.Now())

for _, recorder := range recorders {
Expand All @@ -132,7 +133,7 @@ func (s *sqlServerScraper) emitMetricGroup(recorders []curriedRecorder, database
}

// shutdown stops all of the watchers for the scraper.
func (s sqlServerScraper) shutdown(_ context.Context) error {
func (s sqlServerPCScraper) shutdown(_ context.Context) error {
var errs error
for _, wr := range s.watcherRecorders {
err := wr.watcher.Close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestSqlServerScraper(t *testing.T) {
logger, obsLogs := observer.New(zap.WarnLevel)
settings := receivertest.NewNopCreateSettings()
settings.Logger = zap.New(logger)
s := newSQLServerScraper(settings, cfg)
s := newSQLServerPCScraper(settings, cfg)

assert.NoError(t, s.start(context.Background(), nil))
assert.Equal(t, 0, len(s.watcherRecorders))
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestScrape(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
settings := receivertest.NewNopCreateSettings()
scraper := newSQLServerScraper(settings, cfg)
scraper := newSQLServerPCScraper(settings, cfg)

for i, rec := range perfCounterRecorders {
perfCounterWatcher := &mockPerfCounterWatcher{}
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestScrape(t *testing.T) {
cfg.InstanceName = "CustomInstance"

settings := receivertest.NewNopCreateSettings()
scraper := newSQLServerScraper(settings, cfg)
scraper := newSQLServerPCScraper(settings, cfg)

for i, rec := range perfCounterRecorders {
perfCounterWatcher := &mockPerfCounterWatcher{}
Expand Down

0 comments on commit 6f25527

Please sign in to comment.