httphandler: remove /version endpoint (#2660)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-10 19:37:24 +02:00
committed by GitHub
co-authored by Claude Fable 5
parent d25d2328f2
commit 55ebc3c09b
3 changed files with 0 additions and 108 deletions
-62
View File
@@ -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)
}
}
-45
View File
@@ -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)
}