// SPDX-License-Identifier: Apache-2.0 // // Copyright The Prometheus 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. //go:build windows package service import ( "fmt" "log/slog" "os" "regexp" "slices" "strings" "testing" "time" "unsafe" "github.com/prometheus-community/windows_exporter/internal/scrapecache" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/sys/windows" "golang.org/x/sys/windows/svc/mgr" ) type serviceMetricCollector struct { t assert.TestingT collector *Collector } func (c serviceMetricCollector) Describe(ch chan<- *prometheus.Desc) { prometheus.DescribeByCollect(c, ch) } func (c serviceMetricCollector) Collect(ch chan<- prometheus.Metric) { // Collect within a scrape of the caches, as the collection does. cacheScrape := scrapecache.Begin(c.collector) err := c.collector.Collect(ch, 0) cacheScrape.End(err) assert.NoError(c.t, err) } // serviceMetrics scrapes the collector and returns the value of each series of // the service as "{