Skip to content

Commit 6273485

Browse files
committed
http: adding metric to display information about the visus binary.
The following metrics have been added: visus_info, visus_start_seconds.
1 parent 4523cd8 commit 6273485

File tree

6 files changed

+139
-2
lines changed

6 files changed

+139
-2
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# vendor/
1616
scripts/
1717
tmp/
18-
*.sh
1918
certs
2019
visus
2120
visus-*

internal/cmd/collection/testdata/invalid_scope.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2025 Cockroach Labs Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
name: query_count
216
enabled: true
317
scope: invalid

internal/cmd/collection/testdata/malformed.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2025 Cockroach Labs Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
name: query_count
216
enabled: true
317
scope: node

internal/cmd/histogram/testdata/malformed.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2025 Cockroach Labs Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
enabled: true
216
name: latency
317
bins: wrong

internal/http/server.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"net/http"
2222
_ "net/http/pprof" // enabling debugging
2323
"net/url"
24+
"runtime/debug"
2425

2526
"github.com/NYTimes/gziphandler"
2627
"github.com/cockroachdb/field-eng-powertools/stopper"
@@ -34,6 +35,10 @@ import (
3435
log "github.com/sirupsen/logrus"
3536
)
3637

38+
// Version of the visus binary, set using:
39+
// `-ldflags="-X github.com/cockroachlabs/visus/internal/http.Version=..."`
40+
var Version string
41+
3742
type serverImpl struct {
3843
clientTLSConfig *clientTLSConfig
3944
config *server.Config
@@ -143,7 +148,7 @@ func (s *serverImpl) Start(ctx *stopper.Context) error {
143148
})
144149

145150
http.Handle(s.config.Endpoint, gziphandler.GzipHandler(handler))
146-
151+
s.debugInfo()
147152
ctx.Go(func(ctx *stopper.Context) error {
148153
var err error
149154
if !s.config.Insecure {
@@ -183,6 +188,37 @@ func (s *serverImpl) errorResponse(w http.ResponseWriter, msg string, err error)
183188
}
184189
}
185190

191+
func (s *serverImpl) debugInfo() {
192+
if bi, ok := debug.ReadBuildInfo(); ok {
193+
labels := prometheus.Labels{
194+
"go_version": bi.GoVersion,
195+
"module": bi.Path,
196+
}
197+
for _, setting := range bi.Settings {
198+
switch setting.Key {
199+
case "vcs.revision":
200+
labels["commit"] = setting.Value
201+
case "vcs.time":
202+
labels["build_time"] = setting.Value
203+
}
204+
}
205+
labels["version"] = Version
206+
g := prometheus.NewGauge(prometheus.GaugeOpts{
207+
Name: "visus_info",
208+
Help: "information about the visus binary",
209+
ConstLabels: labels,
210+
})
211+
g.Set(1)
212+
s.registry.Register(g)
213+
}
214+
g := prometheus.NewGauge(prometheus.GaugeOpts{
215+
Name: "visus_start_seconds",
216+
Help: "the wall time at which visus was started",
217+
})
218+
g.SetToCurrentTime()
219+
s.registry.Register(g)
220+
}
221+
186222
// refresh the server configuration
187223
func (s *serverImpl) refresh(ctx *stopper.Context) error {
188224
if err := s.keyPair.load(); err != nil {

release.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
# Copyright 2025 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
17+
version=`git describe --exact-match --tags`
18+
19+
if [[ -z "$version" ]]
20+
then
21+
echo "not tag found. Run this command within a git tag"
22+
echo "Create a tag for vX.Y.Z and push it to github. Run:"
23+
echo "git tag vX.Y.Z"
24+
echo "git push origin vX.Y.Z"
25+
echo "current tags:"
26+
git tag
27+
exit -1
28+
fi
29+
30+
go clean
31+
32+
amdfile=visus-${version}.linux-amd64.tgz
33+
armfile=visus-${version}.linux-arm64.tgz
34+
35+
echo "Checking for license"
36+
go run github.com/google/addlicense -check .
37+
38+
echo "Running test"
39+
go clean -testcache
40+
go test ./...
41+
42+
echo "Running lint"
43+
go run github.com/cockroachdb/crlfmt .
44+
go run golang.org/x/lint/golint -set_exit_status ./...
45+
go run honnef.co/go/tools/cmd/staticcheck -checks all ./...
46+
47+
VERSION="github.com/cockroachlabs/visus/internal/http.Version=$version"
48+
GOOS=linux go build -v -ldflags="-X '$VERSION'" -o visus
49+
50+
tar cvfz $amdfile visus examples
51+
52+
shasum -a 256 $amdfile
53+
GOOS=linux GOARCH=arm64 go build -v -ldflags="-X '$VERSION'" -o visus
54+
55+
tar cvfz $armfile visus examples
56+
shasum -a 256 $armfile
57+
58+
go build -ldflags="-X '$VERSION'" -o visus
59+
60+
echo "Upload binaries $amdfile and $armfile to release"

0 commit comments

Comments
 (0)