Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format makefile #63

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
flavor: |
latest=true
tags: |
type=sha,short=true
type=ref,event=pr
type=ref,event=branch
type=ref,event=tag
type=semver,pattern={{version}}
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ on:
- "go.sum"
- "go.mod"
- "**.go"
- "scripts/errcheck_excludes.txt"
- ".github/workflows/golangci-lint.yml"
- ".golangci.yml"
pull_request:
paths:
- "go.sum"
- "go.mod"
- "**.go"
- "scripts/errcheck_excludes.txt"
- ".github/workflows/golangci-lint.yml"
- ".golangci.yml"

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ concurrency:
cancel-in-progress: true

jobs:
lint:
test:
runs-on: ubuntu-latest

steps:
Expand All @@ -27,4 +27,3 @@ jobs:
- run: go install github.com/google/go-licenses@latest
- run: $(go env GOPATH)/bin/go-licenses check . --disallowed_types forbidden,restricted,unknown
- run: make test

28 changes: 12 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Ensure that 'all' is the default target otherwise it will be the first target from Makefile.common.
all::
all: build

ARCH = $(shell go env GOARCH)
OS = $(shell go env GOOS)

.PHONY: build LOCALBIN
.PHONY: build
build:
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH} go build -o .build/${OS}-${ARCH}/emqx-exporter
go build -o $(LOCALBIN)/$(PROJECT_NAME)

.PHONY: test
test:
go test -race --cover -covermode=atomic -coverpkg=./... -coverprofile=cover.out ./...
test: build
go test -v -race --cover -covermode=atomic -coverpkg=./... -coverprofile=cover.out ./...

DOCKER_IMAGE_NAME ?= emqx-exporter
.PHONY: docker-build
docker-build:
docker build -t ${DOCKER_IMAGE_NAME} .
.PHONY: docker
docker:
docker build -t $(PROJECT_NAME) .

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/.build/${OS}-${ARCH}
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
PROJECT_NAME := emqx-exporter
LOCALBIN ?= $(PROJECT_DIR)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
mkdir -p $(LOCALBIN)
47 changes: 9 additions & 38 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
"testing"
"time"

"github.com/prometheus/procfs"
)

var (
binary = filepath.Join(os.Getenv("GOPATH"), "bin/emqx-exporter")
)

const (
address = "localhost:19100"
address = "localhost:19100"
binary = "bin/emqx-exporter"
configFile = "config/example/config.yaml"
)

func TestFileDescriptorLeak(t *testing.T) {
if _, err := os.Stat(binary); err != nil {
t.Skipf("emqx-exporter binary not available, try to run `make build` first: %s", err)
// t.Skipf("emqx-exporter binary not available, try to run `make build` first: %s", err)
t.Errorf("emqx-exporter binary not available, try to run `make build` first: %s", err)
}

fs, err := procfs.NewDefaultFS()
if err != nil {
t.Skipf("proc filesystem is not available, but currently required to read number of open file descriptors: %s", err)
// t.Skipf("proc filesystem is not available, but currently required to read number of open file descriptors: %s", err)
t.Errorf("proc filesystem is not available, but currently required to read number of open file descriptors: %s", err)
}
if _, err := fs.Stat(); err != nil {
t.Errorf("unable to read process stats: %s", err)
}

exporter := exec.Command(binary, "--web.listen-address", address)
exporter := exec.Command(binary, "--web.listen-address", address, "--config.file", configFile)
test := func(pid int) error {
if err := queryExporter(address); err != nil {
return err
Expand Down Expand Up @@ -79,35 +79,6 @@ func TestFileDescriptorLeak(t *testing.T) {
}
}

func TestHandlingOfDuplicatedMetrics(t *testing.T) {
if _, err := os.Stat(binary); err != nil {
t.Skipf("emqx-exporter binary not available, try to run `make build` first: %s", err)
}

dir, err := os.MkdirTemp("", "node-exporter")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

content := []byte("dummy_metric 1\n")
if err := os.WriteFile(filepath.Join(dir, "a.prom"), content, 0600); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "b.prom"), content, 0600); err != nil {
t.Fatal(err)
}

exporter := exec.Command(binary, "--web.listen-address", address, "--collector.textfile.directory", dir)
test := func(_ int) error {
return queryExporter(address)
}

if err := runCommandAndTests(exporter, address, test); err != nil {
t.Error(err)
}
}

func queryExporter(address string) error {
resp, err := http.Get(fmt.Sprintf("http://%s/metrics", address))
if err != nil {
Expand Down