Skip to content

Commit

Permalink
chore: go vet
Browse files Browse the repository at this point in the history
  • Loading branch information
hashworks committed Jul 3, 2024
1 parent 6fefc26 commit 1702b8c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,25 @@ type group struct {

var (
groups = []group{
group{name: "backend", prefixes: []string{
{name: "backend", prefixes: []string{
"vbe.",
}},
group{name: "mempool", prefixes: []string{
{name: "mempool", prefixes: []string{
"mempool.",
}},
group{name: "lck", prefixes: []string{
{name: "lck", prefixes: []string{
"lck.",
}},
group{name: "sma", prefixes: []string{
{name: "sma", prefixes: []string{
"sma.",
}},
group{name: "smf", prefixes: []string{
{name: "smf", prefixes: []string{
"smf.",
}},
group{name: "mgt", prefixes: []string{
{name: "mgt", prefixes: []string{
"mgt.",
}},
group{name: "main", prefixes: []string{
{name: "main", prefixes: []string{
"main.",
}},
}
Expand All @@ -148,18 +148,18 @@ type grouping struct {

var (
fqGroupPrefixes = []*grouping{
&grouping{
{
prefix: "main_fetch",
total: "main_s_fetch",
desc: "Number of fetches",
},
&grouping{
{
newPrefix: "main_sessions",
prefix: "main_sess",
total: "main_s_sess",
desc: "Number of sessions",
},
&grouping{
{
newPrefix: "main_worker_threads",
prefix: "main_n_wrk",
total: "main_n_wrk",
Expand Down Expand Up @@ -229,7 +229,7 @@ func cleanBackendName(name string) string {
if strings.HasPrefix(name, "reload_") {
dot := strings.Index(name, ".")
if dot != -1 {
name = name[dot + 1:]
name = name[dot+1:]
}
}

Expand Down
4 changes: 2 additions & 2 deletions varnish.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func ScrapeVarnishFrom(buf []byte, ch chan<- prometheus.Metric) ([]byte, error)
)
flag, _ := stringProperty(data, "flag")

if value, ok := data["description"]; ok && vErr == nil {
if value, ok := data["description"]; ok {
if vDescription, ok = value.(string); !ok {
vErr = fmt.Errorf("%s description it not a string", vName)
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func executeVarnishstat(varnishstatExe string, params ...string) (*bytes.Buffer,
// 'VBE.reload_20191014_091124_78599' as by varnishreload in 6+
func findMostRecentVbeReloadPrefix(countersJSON map[string]interface{}) string {
var mostRecentVbeReloadPrefix string
for vName, _ := range countersJSON {
for vName := range countersJSON {
// Checking only the required ".happy" stat
if strings.HasPrefix(vName, vbeReload) && strings.HasSuffix(vName, ".happy") {
dotAfterPrefixIndex := len(vbeReload) + strings.Index(vName[len(vbeReload):], ".")
Expand Down
22 changes: 11 additions & 11 deletions varnish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ var testFileVersions = []string{"3.0.5", "4.0.5", "4.1.1", "5.2.0", "6.0.0", "6.

func Test_VarnishVersion(t *testing.T) {
tests := map[string]*varnishVersion{
"varnishstat (varnish-6.5.1 revision 1dae23376bb5ea7a6b8e9e4b9ed95cdc9469fb64)": &varnishVersion{
"varnishstat (varnish-6.5.1 revision 1dae23376bb5ea7a6b8e9e4b9ed95cdc9469fb64)": {
Major: 6, Minor: 5, Patch: 1, Revision: "1dae23376bb5ea7a6b8e9e4b9ed95cdc9469fb64",
},
"varnishstat (varnish-6.0.0 revision a068361dff0d25a0d85cf82a6e5fdaf315e06a7d)": &varnishVersion{
"varnishstat (varnish-6.0.0 revision a068361dff0d25a0d85cf82a6e5fdaf315e06a7d)": {
Major: 6, Minor: 0, Patch: 0, Revision: "a068361dff0d25a0d85cf82a6e5fdaf315e06a7d",
},
"varnishstat (varnish-5.2.0 revision 4c4875cbf)": &varnishVersion{
"varnishstat (varnish-5.2.0 revision 4c4875cbf)": {
Major: 5, Minor: 2, Patch: 0, Revision: "4c4875cbf",
},
"varnishstat (varnish-4.1.10 revision 1d090c5a08f41c36562644bafcce9d3cb85d824f)": &varnishVersion{
"varnishstat (varnish-4.1.10 revision 1d090c5a08f41c36562644bafcce9d3cb85d824f)": {
Major: 4, Minor: 1, Patch: 10, Revision: "1d090c5a08f41c36562644bafcce9d3cb85d824f",
},
"varnishstat (varnish-4.1.0 revision 3041728)": &varnishVersion{
"varnishstat (varnish-4.1.0 revision 3041728)": {
Major: 4, Minor: 1, Patch: 0, Revision: "3041728",
},
"varnishstat (varnish-4 revision)": &varnishVersion{
"varnishstat (varnish-4 revision)": {
Major: 4, Minor: -1, Patch: -1,
},
"varnishstat (varnish-3.0.5 revision 1a89b1f)": &varnishVersion{
"varnishstat (varnish-3.0.5 revision 1a89b1f)": {
Major: 3, Minor: 0, Patch: 5, Revision: "1a89b1f",
},
"varnish 2.0": &varnishVersion{
"varnish 2.0": {
Major: 2, Minor: 0, Patch: -1,
},
"varnish 1": &varnishVersion{
"varnish 1": {
Major: 1, Minor: -1, Patch: -1,
},
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func Test_VarnishBackendNames(t *testing.T) {
vIdentifier string
vErr error
)
if value, ok := data["description"]; ok && vErr == nil {
if value, ok := data["description"]; ok {
if vDescription, ok = value.(string); !ok {
vErr = fmt.Errorf("%s description it not a string", vName)
}
Expand Down Expand Up @@ -266,7 +266,7 @@ func (tc *testCollector) Describe(ch chan<- *prometheus.Desc) {
}

func (tc *testCollector) Collect(ch chan<- prometheus.Metric) {
buf, err := ioutil.ReadFile(tc.filepath)
buf, err := os.ReadFile(tc.filepath)
if err != nil {
tc.t.Fatal(err.Error())
}
Expand Down

0 comments on commit 1702b8c

Please sign in to comment.