diff --git a/.github/workflows/build-and-test-windows.yml b/.github/workflows/build-and-test-windows.yml index bc9bc1067f66..3f093fcb90cb 100644 --- a/.github/workflows/build-and-test-windows.yml +++ b/.github/workflows/build-and-test-windows.yml @@ -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: | diff --git a/receiver/iisreceiver/config_generator.go b/receiver/iisreceiver/config_generator.go index 91e36d0d327b..456971d0819a 100644 --- a/receiver/iisreceiver/config_generator.go +++ b/receiver/iisreceiver/config_generator.go @@ -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{ @@ -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{ diff --git a/receiver/iisreceiver/scraper.go b/receiver/iisreceiver/scraper.go index f399c1bb006c..e1e5179f0dbc 100644 --- a/receiver/iisreceiver/scraper.go +++ b/receiver/iisreceiver/scraper.go @@ -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" @@ -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{} @@ -64,6 +65,7 @@ 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()) @@ -71,18 +73,22 @@ func (rcvr *iisReceiver) scrape(ctx context.Context) (pdata.Metrics, error) { 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 { diff --git a/receiver/iisreceiver/scraper_test.go b/receiver/iisreceiver/scraper_test.go index 7454159078e9..3354739dad2a 100644 --- a/receiver/iisreceiver/scraper_test.go +++ b/receiver/iisreceiver/scraper_test.go @@ -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" @@ -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) @@ -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(), ) @@ -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 { diff --git a/receiver/iisreceiver/testdata/integration/expected.json b/receiver/iisreceiver/testdata/integration/expected.json index 2145a4452435..9c1a8b194594 100644 --- a/receiver/iisreceiver/testdata/integration/expected.json +++ b/receiver/iisreceiver/testdata/integration/expected.json @@ -13,8 +13,8 @@ "dataPoints": [ { "asInt": "0", - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" } ] }, @@ -27,9 +27,9 @@ "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", "dataPoints": [ { - "asInt": "1", - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "asInt": "5", + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" } ], "isMonotonic": true @@ -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", @@ -68,11 +84,11 @@ } } ], - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" }, { - "asInt": "1", + "asInt": "4", "attributes": [ { "key": "direction", @@ -81,8 +97,8 @@ } } ], - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" } ], "isMonotonic": true @@ -96,7 +112,7 @@ "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", "dataPoints": [ { - "asInt": "57", + "asInt": "1934", "attributes": [ { "key": "direction", @@ -105,11 +121,11 @@ } } ], - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" }, { - "asInt": "940", + "asInt": "106804", "attributes": [ { "key": "direction", @@ -118,8 +134,8 @@ } } ], - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" } ], "isMonotonic": true @@ -142,11 +158,11 @@ } } ], - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" }, { - "asInt": "1", + "asInt": "5", "attributes": [ { "key": "request", @@ -155,8 +171,8 @@ } } ], - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" }, { "asInt": "0", @@ -168,8 +184,8 @@ } } ], - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" }, { "asInt": "0", @@ -181,8 +197,8 @@ } } ], - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" }, { "asInt": "0", @@ -194,8 +210,8 @@ } } ], - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" }, { "asInt": "0", @@ -207,8 +223,8 @@ } } ], - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" }, { "asInt": "0", @@ -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 @@ -235,9 +282,9 @@ "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", "dataPoints": [ { - "asInt": "4659", - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "asInt": "4724", + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" } ] }, @@ -248,9 +295,9 @@ "gauge": { "dataPoints": [ { - "asInt": "525146", - "startTimeUnixNano": "1649790968352648900", - "timeUnixNano": "1649790968352648900" + "asInt": "1029516", + "startTimeUnixNano": "1650295321014331300", + "timeUnixNano": "1650295321456400500" } ] }, diff --git a/receiver/iisreceiver/testdata/scraper/expected.json b/receiver/iisreceiver/testdata/scraper/expected.json index 57c68c2c3d79..0f715394f76d 100644 --- a/receiver/iisreceiver/testdata/scraper/expected.json +++ b/receiver/iisreceiver/testdata/scraper/expected.json @@ -13,8 +13,8 @@ "dataPoints": [ { "asInt": "1", - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ] }, @@ -28,8 +28,8 @@ "dataPoints": [ { "asInt": "1", - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ], "isMonotonic": true @@ -44,8 +44,8 @@ "dataPoints": [ { "asInt": "1", - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ], "isMonotonic": true @@ -60,8 +60,8 @@ "dataPoints": [ { "asInt": "1", - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ], "isMonotonic": true @@ -84,8 +84,8 @@ } } ], - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ], "isMonotonic": true @@ -108,8 +108,8 @@ } } ], - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ], "isMonotonic": true @@ -132,8 +132,8 @@ } } ], - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ], "isMonotonic": true @@ -146,8 +146,8 @@ "dataPoints": [ { "asInt": "1", - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ] }, @@ -162,8 +162,8 @@ "dataPoints": [ { "asInt": "1", - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ] }, @@ -177,8 +177,8 @@ "dataPoints": [ { "asInt": "1", - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ], "isMonotonic": true @@ -193,8 +193,8 @@ "dataPoints": [ { "asInt": "1", - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ] }, @@ -206,8 +206,8 @@ "dataPoints": [ { "asInt": "1", - "startTimeUnixNano": "1649797402615187400", - "timeUnixNano": "1649797402615187400" + "startTimeUnixNano": "1649969943717902800", + "timeUnixNano": "1649969943717902800" } ] },