diff --git a/cmd/windows_exporter/main.go b/cmd/windows_exporter/main.go index fa20d3c0..24ca3191 100644 --- a/cmd/windows_exporter/main.go +++ b/cmd/windows_exporter/main.go @@ -235,7 +235,6 @@ func run(ctx context.Context, args []string) int { mux := http.NewServeMux() mux.Handle("GET /health", httphandler.NewHealthHandler()) - mux.Handle("GET /version", httphandler.NewVersionHandler()) mux.Handle("GET "+*metricsPath, httphandler.New(logger, collectors, &httphandler.Options{ DisableExporterMetrics: *disableExporterMetrics, TimeoutMargin: *timeoutMargin, diff --git a/internal/httphandler/version.go b/internal/httphandler/version.go deleted file mode 100644 index ca94063b..00000000 --- a/internal/httphandler/version.go +++ /dev/null @@ -1,62 +0,0 @@ -// 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 httphandler - -import ( - "encoding/json" - "fmt" - "net/http" - - "github.com/prometheus/common/version" -) - -type VersionHandler struct{} - -// Same struct prometheus uses for their /version endpoint. -// Separate copy to avoid pulling all of prometheus as a dependency. -type prometheusVersion struct { - Version string `json:"version"` - Revision string `json:"revision"` - Branch string `json:"branch"` - BuildUser string `json:"buildUser"` - BuildDate string `json:"buildDate"` - GoVersion string `json:"goVersion"` -} - -// Interface guard. -var _ http.Handler = (*VersionHandler)(nil) - -func NewVersionHandler() VersionHandler { - return VersionHandler{} -} - -func (h VersionHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request) { - // we can't use "version" directly as it is a package, and not an object that - // can be serialized. - err := json.NewEncoder(w).Encode(prometheusVersion{ - Version: version.Version, - Revision: version.Revision, - Branch: version.Branch, - BuildUser: version.BuildUser, - BuildDate: version.BuildDate, - GoVersion: version.GoVersion, - }) - if err != nil { - http.Error(w, fmt.Sprintf("error encoding JSON: %s", err), http.StatusInternalServerError) - } -} diff --git a/internal/httphandler/version_test.go b/internal/httphandler/version_test.go deleted file mode 100644 index d7ccfed6..00000000 --- a/internal/httphandler/version_test.go +++ /dev/null @@ -1,45 +0,0 @@ -// 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 httphandler_test - -import ( - "encoding/json" - "net/http" - "net/http/httptest" - "testing" - - "github.com/prometheus-community/windows_exporter/internal/httphandler" - "github.com/prometheus/common/version" - "github.com/stretchr/testify/require" -) - -func TestVersionHandler(t *testing.T) { - t.Parallel() - - response := httptest.NewRecorder() - httphandler.NewVersionHandler().ServeHTTP(response, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/version", nil)) - require.Equal(t, http.StatusOK, response.Code) - - var got map[string]string - require.NoError(t, json.Unmarshal(response.Body.Bytes(), &got)) - require.Equal(t, map[string]string{ - "version": version.Version, "revision": version.Revision, - "branch": version.Branch, "buildUser": version.BuildUser, - "buildDate": version.BuildDate, "goVersion": version.GoVersion, - }, got) -}