-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to using perf counters to get disk io metrics on Windows (#1340)
- Loading branch information
1 parent
11e8cb0
commit 7eee24f
Showing
9 changed files
with
572 additions
and
194 deletions.
There are no files selected for viewing
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
124 changes: 0 additions & 124 deletions
124
receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper.go
This file was deleted.
Oops, something went wrong.
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
28 changes: 28 additions & 0 deletions
28
receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_others_fallback.go
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,28 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// +build !linux,!windows | ||
|
||
package diskscraper | ||
|
||
import ( | ||
"github.com/shirou/gopsutil/disk" | ||
|
||
"go.opentelemetry.io/collector/consumer/pdata" | ||
) | ||
|
||
const systemSpecificMetricsLen = 0 | ||
|
||
func appendSystemSpecificMetrics(metrics pdata.MetricSlice, startIdx int, startTime pdata.TimestampUnixNano, ioCounters map[string]disk.IOCountersStat) { | ||
} |
File renamed without changes.
95 changes: 95 additions & 0 deletions
95
receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_others_test.go
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,95 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// +build !windows | ||
|
||
package diskscraper | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/shirou/gopsutil/disk" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"go.opentelemetry.io/collector/consumer/pdata" | ||
) | ||
|
||
func TestScrapeMetrics_Others(t *testing.T) { | ||
type testCase struct { | ||
name string | ||
bootTimeFunc func() (uint64, error) | ||
ioCountersFunc func(names ...string) (map[string]disk.IOCountersStat, error) | ||
expectedStartTime pdata.TimestampUnixNano | ||
initializationErr string | ||
expectedErr string | ||
} | ||
|
||
testCases := []testCase{ | ||
{ | ||
name: "Validate Start Time", | ||
bootTimeFunc: func() (uint64, error) { return 100, nil }, | ||
expectedStartTime: 100 * 1e9, | ||
}, | ||
{ | ||
name: "Boot Time Error", | ||
bootTimeFunc: func() (uint64, error) { return 0, errors.New("err1") }, | ||
initializationErr: "err1", | ||
}, | ||
{ | ||
name: "Error", | ||
ioCountersFunc: func(names ...string) (map[string]disk.IOCountersStat, error) { return nil, errors.New("err2") }, | ||
expectedErr: "err2", | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
t.Run(test.name, func(t *testing.T) { | ||
scraper := newDiskScraper(context.Background(), &Config{}) | ||
if test.bootTimeFunc != nil { | ||
scraper.bootTime = test.bootTimeFunc | ||
} | ||
if test.ioCountersFunc != nil { | ||
scraper.ioCounters = test.ioCountersFunc | ||
} | ||
|
||
err := scraper.Initialize(context.Background()) | ||
if test.initializationErr != "" { | ||
assert.EqualError(t, err, test.initializationErr) | ||
return | ||
} | ||
require.NoError(t, err, "Failed to initialize disk scraper: %v", err) | ||
defer func() { assert.NoError(t, scraper.Close(context.Background())) }() | ||
|
||
metrics, err := scraper.ScrapeMetrics(context.Background()) | ||
if test.expectedErr != "" { | ||
assert.EqualError(t, err, test.expectedErr) | ||
return | ||
} | ||
|
||
require.NoError(t, err, "Failed to scrape metrics: %v", err) | ||
|
||
assertDiskMetricValid(t, metrics.At(0), diskIODescriptor, test.expectedStartTime) | ||
assertDiskMetricValid(t, metrics.At(1), diskOpsDescriptor, test.expectedStartTime) | ||
assertDiskMetricValid(t, metrics.At(2), diskTimeDescriptor, test.expectedStartTime) | ||
|
||
if runtime.GOOS == "linux" { | ||
assertDiskMetricValid(t, metrics.At(3), diskMergedDescriptor, test.expectedStartTime) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.