Skip to content

Commit

Permalink
ci: Add go1.22, remove go1.20
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Trangoni <[email protected]>
  • Loading branch information
mjtrangoni committed Feb 18, 2024
1 parent e4b1c0c commit e47faf8
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: 2.1
executors:
golang:
docker:
- image: cimg/go:1.21
- image: cimg/go:1.22

jobs:
codespell:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
build:
strategy:
matrix:
go-version: [1.20.x, 1.21.x]
go-version: [1.21.x, 1.22.x]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
Expand All @@ -27,7 +27,7 @@ jobs:
- name: Install go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x
- name: Checkout code
uses: actions/checkout@v4
- name: Install goveralls
Expand Down
2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here, go.mod, .github/workflows/build.yml,
# and .circleci/config.yml should also be updated.
version: 1.21
version: 1.22
cgo: false
repository:
path: github.com/mjtrangoni/flexlm_exporter
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GO ?= GO111MODULE=on go
GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
PROMU ?= $(GOPATH)/bin/promu
GOLINTER ?= $(GOPATH)/bin/golangci-lint
GO_VERSION ?= 1.21
GO_VERSION ?= 1.22
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
TARGET ?= flexlm_exporter
DOCKER_IMAGE_NAME ?= mjtrangoni/flexlm_exporter
Expand Down Expand Up @@ -94,4 +94,4 @@ crossbuild: promu
$(GOPATH)/bin/golangci-lint lint:
@GOOS=$(shell uname -s | tr A-Z a-z) \
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.1
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.2
6 changes: 6 additions & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ type FlexlmCollector struct {
// A new action function is needed for each collector flag because the ParseContext
// does not contain information about which flag called the action.
// See: https://github.com/alecthomas/kingpin/issues/294
//
//revive:disable:unused-parameter
func collectorFlagAction(collector string) func(ctx *kingpin.ParseContext) error {
return func(ctx *kingpin.ParseContext) error {
forcedCollectors[collector] = true
return nil
}
}

//revive:enable:unused-parameter

// NewFlexlmCollector creates a new FlexlmCollector.
func NewFlexlmCollector(logger log.Logger, filters ...string) (*FlexlmCollector, error) {
f := make(map[string]bool)
Expand Down Expand Up @@ -131,6 +135,7 @@ func NewFlexlmCollector(logger log.Logger, filters ...string) (*FlexlmCollector,
if err != nil {
return nil, err
}

collectors[key] = collector
initiatedCollectors[key] = collector
}
Expand Down Expand Up @@ -175,6 +180,7 @@ func execute(name string, c Collector, ch chan<- prometheus.Metric, logger log.L
success = 0
} else {
level.Debug(logger).Log("OK:", name, "collector succeeded after:", duration.Seconds())

success = 1
}
ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), name)
Expand Down
10 changes: 10 additions & 0 deletions collector/lmstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func parseLmstatLicenseInfoServer(outStr [][]string) map[string]*server {
} else if lmutilLicenseServerStatusRegex.MatchString(lineJoined) {
matches := lmutilLicenseServerStatusRegex.FindStringSubmatch(lineJoined)
servers[strings.ToLower(strings.Split(matches[1], ".")[0])].version = matches[4]

if matches[2] == upString {
servers[strings.ToLower(strings.Split(matches[1], ".")[0])].status = true
}
Expand Down Expand Up @@ -298,21 +299,26 @@ func parseLmstatLicenseInfoFeature(outStr [][]string, logger log.Logger) (map[st
if licUsersByFeature[featureName] == nil {
licUsersByFeature[featureName] = map[string][]*featureUserUsed{}
}

matches := reSubMatchMap(lmutilLicenseFeatureUsageUserRegex, lineJoined)
username := matches["user"]

if strings.TrimSpace(username) == "" {
level.Debug(logger).Log("username couldn't be found for '", lineJoined,
"', using lmutilLicenseFeatureUsageUser2Regex.")

matches = reSubMatchMap(lmutilLicenseFeatureUsageUser2Regex, lineJoined)
username = matches["user"]
}
if matches["ver"] != "" {
var found = -1

for i := range licUsersByFeature[featureName][username] {
if licUsersByFeature[featureName][username][i].version == matches["ver"] {
found = i
}
}

if found < 0 {
unixSince := convertLmstatTimeToUnixTime(matches["since"], logger).Unix()
sinceString := strconv.FormatInt(unixSince, 10)
Expand All @@ -325,6 +331,7 @@ func parseLmstatLicenseInfoFeature(outStr [][]string, logger log.Logger) (map[st
if err != nil {
level.Error(logger).Log("could not convert", matches["licenses"], "to integer:", err)
}

for i := range licUsersByFeature[featureName][username] {
if licUsersByFeature[featureName][username][i].version == matches["ver"] {
licUsersByFeature[featureName][username][i].num += float64(licUsed)
Expand All @@ -341,11 +348,14 @@ func parseLmstatLicenseInfoFeature(outStr [][]string, logger log.Logger) (map[st
if reservGroupByFeature[featureName] == nil {
reservGroupByFeature[featureName] = map[string]float64{}
}

matches := lmutilLicenseFeatureGroupReservRegex.FindStringSubmatch(lineJoined)

groupReserv, err := strconv.Atoi(matches[2])
if err != nil {
level.Error(logger).Log("could not convert", matches[1], "to integer:", err)
}

reservGroupByFeature[featureName][matches[4]] = float64(groupReserv)
}
}
Expand Down
1 change: 1 addition & 0 deletions collector/lmstat_feature_exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func parseLmstatLicenseFeatureExpDate(outStr [][]string, logger log.Logger) map[
// as permanent
expires = math.Inf(posInfinity)
}

index++

featuresExp[index] = &featureExp{
Expand Down
2 changes: 2 additions & 0 deletions collector/lmstat_feature_exp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func TestParseLmstatLicenseFeatureExpDate1(t *testing.T) {
feature.licenses, feature.vendor,
feature.expires)
}

found = true
}
}
Expand Down Expand Up @@ -142,6 +143,7 @@ func TestParseLmstatLicenseFeatureExpDate2(t *testing.T) {
feature.licenses, feature.vendor,
feature.expires)
}

found = true
}
}
Expand Down
2 changes: 1 addition & 1 deletion flexlm_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func main() {
}

http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *configPath, *maxRequests, logger))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte(`<html>
<head><title>FLEXlm Exporter</title></head>
<body>
Expand Down

0 comments on commit e47faf8

Please sign in to comment.