Skip to content
Permalink
Browse files

Godoc support and better CI process

  • Loading branch information...
Depado committed Aug 20, 2019
1 parent ce3affe commit e9cd848beeb318272e47e4f56ca07b1eeabdfc78
Showing with 59 additions and 10 deletions.
  1. +36 −1 .drone.yml
  2. +3 −3 README.md
  3. +6 −6 prom.go
  4. +14 −0 prom_test.go
@@ -10,15 +10,50 @@ steps:

- name: test
image: golang:latest
volumes:
- name: deps
path: /go
commands:
- go test -race -coverprofile=coverage.txt -covermode=atomic
environment:
GO111MODULE: "on"

- name: linter
image: golang:latest
volumes:
- name: deps
path: /go
commands:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.17.1
- ./bin/golangci-lint run
environment:
GO111MODULE: "on"

- name: coverage
image: plugins/codecov
settings:
token:
from_secret: codecov_token
files:
- coverage.txt
- coverage.txt

- name: telegram
image: appleboy/drone-telegram
settings:
to: 790376882
format: markdown
token:
from_secret: telegram_token
message: >
*{{repo.name}}*
[Build {{build.number}}]({{build.link}}) by {{commit.author}} {{#success build.status}}succeeded{{else}}failed{{/success}} in {{buildtime build.started}}
`{{truncate commit.sha 8}}`: "{{commit.message}}"
when:
status:
- success
- failure

volumes:
- name: deps
host:
path: /var/lib/cache/godeps/
@@ -2,16 +2,16 @@

Gin Prometheus metrics exporter inspired by [github.com/zsais/go-gin-prometheus](https://github.com/zsais/go-gin-prometheus)

![Go Version](https://img.shields.io/badge/go-1.9-brightgreen.svg)
![Go Version](https://img.shields.io/badge/go-1.10-brightgreen.svg)
![Go Version](https://img.shields.io/badge/go-latest-brightgreen)
[![Go Report Card](https://goreportcard.com/badge/github.com/Depado/ginprom)](https://goreportcard.com/report/github.com/Depado/ginprom)
[![Build Status](https://drone.depado.eu/api/badges/Depado/ginprom/status.svg)](https://drone.depado.eu/Depado/ginprom)
[![codecov](https://codecov.io/gh/Depado/ginprom/branch/master/graph/badge.svg)](https://codecov.io/gh/Depado/ginprom)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Depado/bfchroma/blob/master/LICENSE)
[![godoc](https://godoc.org/github.com/Depado/ginprom?status.svg)](https://godoc.org/github.com/Depado/ginprom)

## Install

Simply run :
Simply run:
`go get -u github.com/Depado/ginprom`

## Differences with go-gin-prometheus
12 prom.go
@@ -1,3 +1,6 @@
// Package ginprom is a library to instrument a gin server and expose a
// /metrics endpoint for Prometheus to scrape, keeping a low cardinality by
// preserving the path parameters name in the prometheus label
package ginprom

import (
@@ -42,8 +45,7 @@ type Prometheus struct {
PathMap pmap
}

// Path is an option allowing to set the metrics path when intializing with New.
// Example : ginprom.New(ginprom.Path("/mymetrics"))
// Path is an option allowing to set the metrics path when intializing with New
func Path(path string) func(*Prometheus) {
return func(p *Prometheus) {
p.MetricsPath = path
@@ -62,17 +64,15 @@ func Ignore(paths ...string) func(*Prometheus) {
}

// Subsystem is an option allowing to set the subsystem when intitializing
// with New.
// Example : ginprom.New(ginprom.Subsystem("my_system"))
// with New
func Subsystem(sub string) func(*Prometheus) {
return func(p *Prometheus) {
p.Subsystem = sub
}
}

// Namespace is an option allowing to set the namespace when intitializing
// with New.
// Example : ginprom.New(ginprom.Namespace("my_namespace"))
// with New
func Namespace(ns string) func(*Prometheus) {
return func(p *Prometheus) {
p.Namespace = ns
@@ -36,6 +36,13 @@ func TestPrometheus_Use(t *testing.T) {
unregister(p)
}

// Set the path (endpoint) where the metrics will be served
func ExamplePath() {
r := gin.New()
p := New(Engine(r), Path("/metrics"))
r.Use(p.Instrument())
}

func TestPath(t *testing.T) {
p := New()
assert.Equal(t, p.MetricsPath, defaultPath, "no usage of path should yield default path")
@@ -49,6 +56,13 @@ func TestPath(t *testing.T) {
}
}

// Set a secret token that is required to access the endpoint
func ExampleToken() {
r := gin.New()
p := New(Engine(r), Token("supersecrettoken"))
r.Use(p.Instrument())
}

func TestToken(t *testing.T) {
valid := []string{"token1", "token2", ""}
for _, tt := range valid {

0 comments on commit e9cd848

Please sign in to comment.
You can’t perform that action at this time.