Skip to content

Commit

Permalink
Run IIS tests in workflow & Fix IIS metrics (#9358)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrod1598 authored Apr 18, 2022
1 parent df42db3 commit 96cf7cb
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 75 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-and-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
- name: Run Unit tests
# use default Go build tags from Makefile.common
run: go test --tags containers_image_openpgp,exclude_graphdriver_btrfs,exclude_graphdriver_devicemapper ./...
- name: Run IIS Unit Tests
run: cd receiver/iisreceiver && go test --tags containers_image_openpgp,exclude_graphdriver_btrfs,exclude_graphdriver_devicemapper ./...
- name: GitHub Issue Generator
if: ${{ failure() && github.ref == 'ref/head/main' }}
run: |
Expand Down
5 changes: 3 additions & 2 deletions receiver/iisreceiver/config_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func getScraperCfgs() []windowsapi.ObjectConfig {
Name: "iis.network.blocked",
},

Name: "Total blocked bandwidth bytes",
Name: "Total blocked bandwidth bytes.",
},
{
MetricRep: windowsapi.MetricRep{
Expand All @@ -170,7 +170,8 @@ func getScraperCfgs() []windowsapi.ObjectConfig {
},
},
{
Object: "HTTP Service Request Queues",
Object: "HTTP Service Request Queues",
Instances: []string{"*"},
Counters: []windowsapi.CounterConfig{
{
MetricRep: windowsapi.MetricRep{
Expand Down
16 changes: 11 additions & 5 deletions receiver/iisreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.opentelemetry.io/collector/model/pdata"
"go.opentelemetry.io/collector/receiver/scrapererror"
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/winperfcounters"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/iisreceiver/internal/metadata"
Expand All @@ -40,12 +41,12 @@ type iisReceiver struct {
metricBuilder *metadata.MetricsBuilder
}

// new returns a iisReceiver
// newIisReceiver returns an iisReceiver
func newIisReceiver(params component.ReceiverCreateSettings, cfg *Config, consumer consumer.Metrics) *iisReceiver {
return &iisReceiver{params: params, config: cfg, consumer: consumer, metricBuilder: metadata.NewMetricsBuilder(cfg.Metrics)}
}

// Start creates and starts the prometheus receiver.
// start builds the paths to the watchers
func (rcvr *iisReceiver) start(ctx context.Context, host component.Host) error {
rcvr.watchers = []winperfcounters.PerfCounterWatcher{}

Expand All @@ -64,25 +65,30 @@ func (rcvr *iisReceiver) start(ctx context.Context, host component.Host) error {
return errors.Combine()
}

// scrape pulls counter values from the watchers
func (rcvr *iisReceiver) scrape(ctx context.Context) (pdata.Metrics, error) {
var errs error
now := pdata.NewTimestampFromTime(time.Now())

for _, watcher := range rcvr.watchers {
counterValues, err := watcher.ScrapeData()
if err != nil {
errs = multierr.Append(errs, err)
rcvr.params.Logger.Warn("some performance counters could not be scraped; ", zap.Error(err))
continue
}
var metricRep winperfcounters.MetricRep
value := 0.0
for _, counterValue := range counterValues {
rcvr.metricBuilder.RecordAny(now, counterValue.Value, counterValue.MetricRep.Name, counterValue.MetricRep.Attributes)
value += counterValue.Value
metricRep = counterValue.MetricRep
}
rcvr.metricBuilder.RecordAny(now, value, metricRep.Name, metricRep.Attributes)
}

return rcvr.metricBuilder.Emit(), errs
}

// Shutdown stops the underlying Prometheus receiver.
// shutdown closes the watchers
func (rcvr iisReceiver) shutdown(ctx context.Context) error {
var errs error
for _, watcher := range rcvr.watchers {
Expand Down
20 changes: 16 additions & 4 deletions receiver/iisreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest/observer"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/scrapertest"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/scrapertest/golden"
Expand All @@ -49,7 +52,6 @@ func TestScrape(t *testing.T) {
require.NoError(t, err)

expectedFile := filepath.Join("testdata", "scraper", "expected.json")
golden.WriteMetrics(expectedFile, actualMetrics)
expectedMetrics, err := golden.ReadMetrics(expectedFile)
require.NoError(t, err)

Expand All @@ -59,8 +61,13 @@ func TestScrape(t *testing.T) {
func TestScrapeFailure(t *testing.T) {
cfg := createDefaultConfig().(*Config)

core, obs := observer.New(zapcore.WarnLevel)
logger := zap.New(core)
rcvrSettings := componenttest.NewNopReceiverCreateSettings()
rcvrSettings.Logger = logger

scraper := newIisReceiver(
componenttest.NewNopReceiverCreateSettings(),
rcvrSettings,
cfg,
consumertest.NewNop(),
)
Expand All @@ -70,8 +77,13 @@ func TestScrapeFailure(t *testing.T) {
newMockPerfCounter(fmt.Errorf(expectedError), 1, winperfcounters.MetricRep{Name: "iis.uptime"}),
}

_, err := scraper.scrape(context.Background())
require.EqualError(t, err, expectedError)
scraper.scrape(context.Background())

require.Equal(t, 1, obs.Len())
log := obs.All()[0]
require.Equal(t, log.Level, zapcore.WarnLevel)
require.Equal(t, "error", log.Context[0].Key)
require.EqualError(t, log.Context[0].Interface.(error), expectedError)
}

type mockPerfCounter struct {
Expand Down
127 changes: 87 additions & 40 deletions receiver/iisreceiver/testdata/integration/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"dataPoints": [
{
"asInt": "0",
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
}
]
},
Expand All @@ -27,9 +27,9 @@
"aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE",
"dataPoints": [
{
"asInt": "1",
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"asInt": "5",
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
}
],
"isMonotonic": true
Expand All @@ -43,15 +43,31 @@
"aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE",
"dataPoints": [
{
"asInt": "1",
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"asInt": "3",
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
}
],
"isMonotonic": true
},
"unit": "{attempts}"
},
{
"description": "Number of bytes blocked due to bandwidth throttling.",
"name": "iis.network.blocked",
"sum": {
"aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE",
"dataPoints": [
{
"asInt": "0",
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
}
],
"isMonotonic": true
},
"unit": "By"
},
{
"description": "Number of transmitted files.",
"name": "iis.network.file.count",
Expand All @@ -68,11 +84,11 @@
}
}
],
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
},
{
"asInt": "1",
"asInt": "4",
"attributes": [
{
"key": "direction",
Expand All @@ -81,8 +97,8 @@
}
}
],
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
}
],
"isMonotonic": true
Expand All @@ -96,7 +112,7 @@
"aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE",
"dataPoints": [
{
"asInt": "57",
"asInt": "1934",
"attributes": [
{
"key": "direction",
Expand All @@ -105,11 +121,11 @@
}
}
],
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
},
{
"asInt": "940",
"asInt": "106804",
"attributes": [
{
"key": "direction",
Expand All @@ -118,8 +134,8 @@
}
}
],
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
}
],
"isMonotonic": true
Expand All @@ -142,11 +158,11 @@
}
}
],
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
},
{
"asInt": "1",
"asInt": "5",
"attributes": [
{
"key": "request",
Expand All @@ -155,8 +171,8 @@
}
}
],
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
},
{
"asInt": "0",
Expand All @@ -168,8 +184,8 @@
}
}
],
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
},
{
"asInt": "0",
Expand All @@ -181,8 +197,8 @@
}
}
],
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
},
{
"asInt": "0",
Expand All @@ -194,8 +210,8 @@
}
}
],
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
},
{
"asInt": "0",
Expand All @@ -207,8 +223,8 @@
}
}
],
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
},
{
"asInt": "0",
Expand All @@ -220,8 +236,39 @@
}
}
],
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
}
],
"isMonotonic": true
},
"unit": "{requests}"
},
{
"description": "Current number of requests in the queue.",
"name": "iis.request.queue.count",
"sum": {
"aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE",
"dataPoints": [
{
"asInt": "0",
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
}
]
},
"unit": "{requests}"
},
{
"description": "Total number of requests rejected.",
"name": "iis.request.rejected",
"sum": {
"aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE",
"dataPoints": [
{
"asInt": "0",
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
}
],
"isMonotonic": true
Expand All @@ -235,9 +282,9 @@
"aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE",
"dataPoints": [
{
"asInt": "4659",
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"asInt": "4724",
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
}
]
},
Expand All @@ -248,9 +295,9 @@
"gauge": {
"dataPoints": [
{
"asInt": "525146",
"startTimeUnixNano": "1649790968352648900",
"timeUnixNano": "1649790968352648900"
"asInt": "1029516",
"startTimeUnixNano": "1650295321014331300",
"timeUnixNano": "1650295321456400500"
}
]
},
Expand Down
Loading

0 comments on commit 96cf7cb

Please sign in to comment.