This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
681b3a3
commit 61ddcc7
Showing
18 changed files
with
592 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Docs: <https://docs.codecov.io/docs/commit-status> | ||
|
||
ignore: | ||
- "pkg/hostsfile/hostname_validator.go" # generated file | ||
|
||
coverage: | ||
# coverage lower than 50 is red, higher than 90 green | ||
range: 30..80 | ||
|
||
status: | ||
project: | ||
default: | ||
# Choose a minimum coverage ratio that the commit must meet to be considered a success. | ||
# | ||
# `auto` will use the coverage from the base commit (pull request base or parent commit) coverage to compare | ||
# against. | ||
target: auto | ||
|
||
# Allow the coverage to drop by X%, and posting a success status. | ||
threshold: 5% | ||
|
||
# Resulting status will pass no matter what the coverage is or what other settings are specified. | ||
informational: true | ||
|
||
patch: | ||
default: | ||
target: auto | ||
threshold: 5% | ||
informational: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Package metrics contains HTTP handler for application metrics (prometheus format) generation. | ||
package metrics | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
// NewHandler creates metrics handler. | ||
func NewHandler(registry prometheus.Gatherer) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
promhttp.HandlerFor(registry, promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError}).ServeHTTP(w, r) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package metrics_test | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/tarampampam/mikrotik-hosts-parser/v4/internal/pkg/http/handlers/metrics" | ||
) | ||
|
||
func TestNewHandlerError(t *testing.T) { | ||
var ( | ||
req, _ = http.NewRequest(http.MethodGet, "http://testing?foo=bar", http.NoBody) | ||
rr = httptest.NewRecorder() | ||
registry = prometheus.NewRegistry() | ||
testMetric = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Namespace: "foo", | ||
Subsystem: "bar", | ||
Name: "test", | ||
Help: "Test metric.", | ||
}, | ||
[]string{"foo"}, | ||
) | ||
) | ||
|
||
registry.MustRegister(testMetric) | ||
testMetric.WithLabelValues("bar").Set(1) | ||
|
||
metrics.NewHandler(registry)(rr, req) | ||
|
||
assert.Equal(t, rr.Code, http.StatusOK) | ||
assert.Equal(t, 200, rr.Code) | ||
assert.Equal(t, `# HELP foo_bar_test Test metric. | ||
# TYPE foo_bar_test gauge | ||
foo_bar_test{foo="bar"} 1 | ||
`, rr.Body.String()) | ||
assert.Regexp(t, "^text/plain.*$", rr.Header().Get("Content-Type")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.