Skip to content

Commit

Permalink
fix makefile and log (OpenAtomFoundation#1714)
Browse files Browse the repository at this point in the history
* fix makefile and log

* fix makefile and log

* fix makefile
  • Loading branch information
luky116 authored Jul 11, 2023
1 parent 999a4fd commit ceeef9b
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 21 deletions.
19 changes: 14 additions & 5 deletions tools/pika_exporter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

# export PATH := $(PATH):$(GOPATH)/bin

UNAME := $(shell uname)
OS := $(shell uname)
ARCH := $(shell uname -m)
# for mac
BRANCH := $(shell git branch | sed 's/* \(.*\)/\1/p')
# for Linux
Expand Down Expand Up @@ -63,10 +64,18 @@ export TEST_COVER
all: build

build: deps
ifeq ($(UNAME), Linux)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/$(PROJNAME)
else ifeq ($(UNAME), Darwin)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/$(PROJNAME)
ifeq ($(OS), Linux)
ifeq ($(ARCH), x86_64)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/$(PROJNAME)
else ifeq ($(ARCH), arm6411)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/$(PROJNAME)
endif
else ifeq ($(OS), Darwin)
ifeq ($(ARCH), x86_64)
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o bin/$(PROJNAME)
else ifeq ($(ARCH), arm64)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/$(PROJNAME)
endif
endif

deps: generateVer
Expand Down
2 changes: 1 addition & 1 deletion tools/pika_exporter/exporter/metrics/command_exec_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var collectCommandExecCountMetrics = map[string]MetricConfig{
Parser: &regexParser{
name: "command_exec_count_command",
source: "commands_count",
reg: regexp.MustCompile(`(\r|\n)*(?P<command>[^:]+):(?P<count>[\d]*)`),
reg: regexp.MustCompile(`(\r|\n)*(?P<command>[^:]+):(?P<count>[\d]*)`),
Parser: &normalParser{},
},
},
Expand Down
5 changes: 3 additions & 2 deletions tools/pika_exporter/exporter/metrics/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (p *timeParser) Parse(m MetricMeta, c Collector, opt ParseOption) {
} else {
t, err := convertTimeToUnix(v)
if err != nil {
log.Warnf("time is '0' and cannot be parsed", err)
log.Warnf("time is '0' and cannot be parsed", err)
}
metric.Value = float64(t)
}
Expand Down Expand Up @@ -264,7 +264,8 @@ func mustNewVersionConstraint(version string) *semver.Constraints {
func convertTimeToUnix(ts string) (int64, error) {
t, err := time.Parse(time.RFC3339, ts)
if err != nil {
return 0, err
log.Warnf("format time failed, ts: %d, err: %v", ts, err)
return 0, nil
}
return t.Unix(), nil
}
6 changes: 4 additions & 2 deletions tools/pika_exporter/exporter/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package exporter

import (
"fmt"
"testing"

"github.com/Masterminds/semver"
"github.com/stretchr/testify/assert"

"github.com/OpenAtomFoundation/pika/tools/pika_exporter/exporter/metrics"
"github.com/OpenAtomFoundation/pika/tools/pika_exporter/exporter/test"
"github.com/stretchr/testify/assert"
"testing"
)

func mustNewVersionConstraint(version string) *semver.Constraints {
Expand Down
3 changes: 2 additions & 1 deletion tools/pika_exporter/exporter/pika.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (

"github.com/OpenAtomFoundation/pika/tools/pika_exporter/discovery"

"github.com/OpenAtomFoundation/pika/tools/pika_exporter/exporter/metrics"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"

"github.com/OpenAtomFoundation/pika/tools/pika_exporter/exporter/metrics"
)

type dbKeyPair struct {
Expand Down
6 changes: 4 additions & 2 deletions tools/pika_exporter/exporter/pika_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package exporter

import (
"github.com/OpenAtomFoundation/pika/tools/pika_exporter/discovery"
"testing"

"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"testing"

"github.com/OpenAtomFoundation/pika/tools/pika_exporter/discovery"
)

type fakeDiscovery struct {
Expand Down
2 changes: 1 addition & 1 deletion tools/pika_exporter/exporter/test/v3.3.5_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ db0 Strings_keys=83922112, expires=0, invalid_keys=0
db0 Hashes_keys=4887344, expires=0, invalid_keys=0
db0 Lists_keys=1, expires=0, invalid_keys=0
db0 Zsets_keys=1, expires=0, invalid_keys=0
db0 Sets_keys=0, expires=0, invalid_keys=1`
db0 Sets_keys=0, expires=0, invalid_keys=1`
2 changes: 1 addition & 1 deletion tools/pika_exporter/exporter/test/v3.3.5_slave.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ db0 Strings_keys=1000, expires=0, invalid_keys=0
db0 Hashes_keys=0, expires=0, invalid_keys=0
db0 Lists_keys=0, expires=0, invalid_keys=0
db0 Zsets_keys=0, expires=100, invalid_keys=0
db0 Sets_keys=0, expires=0, invalid_keys=0`
db0 Sets_keys=0, expires=0, invalid_keys=0`
2 changes: 1 addition & 1 deletion tools/pika_exporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/sys v0.10.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 2 additions & 2 deletions tools/pika_exporter/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
Expand Down
15 changes: 12 additions & 3 deletions tools/pika_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"os"
"strconv"
"time"

"github.com/OpenAtomFoundation/pika/tools/pika_exporter/discovery"
"github.com/OpenAtomFoundation/pika/tools/pika_exporter/exporter"
Expand All @@ -28,7 +29,7 @@ var (
listenAddress = flag.String("web.listen-address", getEnv("PIKA_EXPORTER_WEB_LISTEN_ADDRESS", ":9121"), "Address to listen on for web interface and telemetry.")
metricPath = flag.String("web.telemetry-path", getEnv("PIKA_EXPORTER_WEB_TELEMETRY_PATH", "/metrics"), "Path under which to expose metrics.")
logLevel = flag.String("log.level", getEnv("PIKA_EXPORTER_LOG_LEVEL", "info"), "Log level, valid options: panic fatal error warn warning info debug.")
logFormat = flag.String("log.format", getEnv("PIKA_EXPORTER_LOG_FORMAT", "json"), "Log format, valid options: txt and json.")
logFormat = flag.String("log.format", getEnv("PIKA_EXPORTER_LOG_FORMAT", "text"), "Log format, valid options: txt and json.")
showVersion = flag.Bool("version", false, "Show version information and exit.")
)

Expand Down Expand Up @@ -63,9 +64,17 @@ func main() {
log.SetLevel(level)
switch *logFormat {
case "json":
log.SetFormatter(&log.JSONFormatter{})
log.SetFormatter(&log.JSONFormatter{
TimestampFormat: "2006-01-02 15:04:05.999999",
PrettyPrint: true,
})
default:
log.SetFormatter(&log.TextFormatter{})
log.SetFormatter(&log.TextFormatter{
ForceColors: true,
ForceQuote: true,
TimestampFormat: time.RFC3339,
FullTimestamp: true,
})
}

var dis discovery.Discovery
Expand Down

0 comments on commit ceeef9b

Please sign in to comment.