Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Don't expose 'instance' label on metrics. This label added automatica…
Browse files Browse the repository at this point in the history
…lly by Prometheus when scraping.
  • Loading branch information
lesovsky committed Jun 9, 2021
1 parent 1bfec4e commit 4b131aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 1 addition & 7 deletions internal/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/weaponry/pgscv/internal/filter"
"github.com/weaponry/pgscv/internal/log"
"github.com/weaponry/pgscv/internal/model"
"os"
"sync"
)

Expand Down Expand Up @@ -126,13 +125,8 @@ type PgscvCollector struct {

// NewPgscvCollector accepts Factories and creates per-service instance of Collector.
func NewPgscvCollector(serviceID string, factories Factories, config Config) (*PgscvCollector, error) {
hostname, err := os.Hostname()
if err != nil {
return nil, err
}

collectors := make(map[string]Collector)
constLabels := labels{"instance": hostname, "service_id": serviceID}
constLabels := labels{"service_id": serviceID}

for key := range factories {
settings := config.Settings[key]
Expand Down
8 changes: 8 additions & 0 deletions internal/pgscv/pgscv.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func lastSendStaleness(v int64, limit time.Duration) time.Duration {
// sendClient defines worker which read metrics from local source and send metrics to remote URL.
type sendClient struct {
apiKey string // API key used for communicating with remote HTTP service
hostname string // System hostname used as value of 'instance'
readURL *url.URL // local URL for reading metrics
writeURL *url.URL // remote URL for sending metrics
timeout time.Duration
Expand All @@ -290,8 +291,14 @@ func newSendClient(config *Config) (sendClient, error) {
return sendClient{}, err
}

hostname, err := os.Hostname()
if err != nil {
return sendClient{}, err
}

return sendClient{
apiKey: config.APIKey,
hostname: hostname,
readURL: readURL,
writeURL: writeURL,
timeout: 10 * time.Second,
Expand Down Expand Up @@ -340,6 +347,7 @@ func (s *sendClient) sendMetrics(buf []byte) error {

q := req.URL.Query()
q.Add("timestamp", fmt.Sprintf("%d", time.Now().UnixNano()/1000000))
q.Add("extra_label", fmt.Sprintf("instance=%s", s.hostname))
req.URL.RawQuery = q.Encode()

ctx, cancel := context.WithTimeout(context.Background(), s.timeout)
Expand Down

0 comments on commit 4b131aa

Please sign in to comment.