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

build: add pika_exporter to pika #1388

Merged
merged 11 commits into from
May 9, 2023
Merged
28 changes: 28 additions & 0 deletions .github/workflows/pika_exporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Pika_exporter

on:
push:
branches: [ "unstable" ]
pull_request:
branches: [ "unstable" ]
paths:
- 'pika-tools/pika_exporter/**'

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Build
run: |
cd pika-tools/pika_exporter && make -j
- name: Test
run: |
cd pika-tools/pika_exporter && make -j
21 changes: 21 additions & 0 deletions pika-tools/pika_exporter/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 frank-ding

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
112 changes: 112 additions & 0 deletions pika-tools/pika_exporter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# ifeq "$(GOPATH)" ""
# $(error Please set the environment variable GOPATH before running `make`)
# endif

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

# for mac
BRANCH := $(shell git branch | sed 's/* \(.*\)/\1/p')
# for Linux
# BRANCH := $(shell git branch | sed --quiet 's/* \(.*\)/\1/p')
GITREV := $(shell git rev-parse --short HEAD)
BUILDTIME := $(shell date '+%F %T %Z')
COMPILERVERSION := $(subst go version ,,$(shell go version))
PROJNAME := pika_exporter

define GENERATE_VERSION_CODE
cat << EOF | gofmt > version.go
package main

const (
BuildVersion = "$(BRANCH)"
BuildCommitSha = "$(GITREV)"
BuildDate = "$(BUILDTIME)"
GoVersion = "$(COMPILERVERSION)"
)
EOF
endef
export GENERATE_VERSION_CODE

PACKAGES := $$(go list ./...| grep -vE 'vendor')
FILES := $$(find . -name '*.go' | grep -vE 'vendor')

define TEST_COVER
#!/bin/bash

set -e

which gocov >/dev/null || go get -v -u github.com/axw/gocov/gocov

COV_FILE=coverage.txt
COV_TMP_FILE=coverage_tmp.txt

rm -f $$COV_FILE
rm -f $$COV_TMP_FILE
touch $$COV_TMP_FILE

echo "mode: count" > $$COV_FILE

for pkg in $(PACKAGES); do
go test -v $$pkg -covermode=count -coverprofile=$$COV_TMP_FILE
tail -n +2 $$COV_TMP_FILE >> $$COV_FILE || (echo "Unable to append coverage for $$pkg" && exit 1)
done

gocov convert $$COV_FILE | gocov report | grep 'Total Coverage'

rm -f $$COV_FILE
rm -f $$COV_TMP_FILE

endef
export TEST_COVER

all: build

build: deps
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/$(PROJNAME)

deps: generateVer
@mkdir -p bin

generateVer:
@echo "$$GENERATE_VERSION_CODE" | bash

test:
@echo "$$TEST_COVER" | bash

race:
go test -v -race $(PACKAGES)

check:
which golint >/dev/null || go get -v -u github.com/golang/lint/golint
@echo "vet"
@go tool vet $(FILES) 2>&1 | awk '{print} END{if(NR>0) {exit 1}}'
@echo "vet --shadow"
@go tool vet --shadow $(FILES) 2>&1 | awk '{print} END{if(NR>0) {exit 1}}'
@echo "golint"
ifdef LINTEXCEPTION
@golint $(PACKAGES) | grep -vE'$(LINTEXCEPTION)' | awk '{print} END{if(NR>0) {exit 1}}'
else
@golint $(PACKAGES) | awk '{print} END{if(NR>0) {exit 1}}'
endif

errcheck:
which errcheck >/dev/null || go get -v -u github.com/kisielk/errcheck
errcheck -blank $(PACKAGES)

clean:
@rm -rf bin
@go clean -i ./...

dev: check test race build

update:
which glide >/dev/null || curl https://glide.sh/get | sh
which glide-vc || go get -v -u github.com/sgotti/glide-vc
rm -r vendor
ifdef PKG
glide get -v --skip-test $(PKG)
else
glide update -v -u --skip-test
endif
@echo "removing test files"
glide vc --only-code --no-tests --use-lock-file
152 changes: 152 additions & 0 deletions pika-tools/pika_exporter/README.md

Large diffs are not rendered by default.

Binary file added pika-tools/pika_exporter/contrib/base_info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading