This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 170
Add telemetry for metrics_ingestion_path
& json_endpoint_used
#1695
Open
Harkishen-Singh
wants to merge
1
commit into
timescale:master
Choose a base branch
from
Harkishen-Singh:more_telemetry_points
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -24,34 +24,8 @@ import ( | |
"github.com/timescale/promscale/pkg/pgclient" | ||
"github.com/timescale/promscale/pkg/rules/adapters" | ||
"github.com/timescale/promscale/pkg/telemetry" | ||
"github.com/timescale/promscale/pkg/util" | ||
) | ||
|
||
var ( | ||
// These metrics are used to track telemetry by registering | ||
// in telemetryEngine.RegisterDynamicMetadata() | ||
rulesEnabled = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Namespace: util.PromNamespace, | ||
Subsystem: "rules", | ||
Name: "enabled", | ||
Help: "Promscale rules is enabled or not.", | ||
}, | ||
) | ||
alertingEnabled = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Namespace: util.PromNamespace, | ||
Subsystem: "alerting", | ||
Name: "enabled", | ||
Help: "Promscale alerting is enabled or not.", | ||
}, | ||
) | ||
) | ||
|
||
func init() { | ||
prometheus.MustRegister(rulesEnabled, alertingEnabled) | ||
} | ||
|
||
type Manager struct { | ||
ctx context.Context | ||
rulesManager *prom_rules.Manager | ||
|
@@ -98,14 +72,9 @@ func NewManager(ctx context.Context, r prometheus.Registerer, client *pgclient.C | |
return manager, manager.getReloader(cfg), nil | ||
} | ||
|
||
func RegisterForTelemetry(t telemetry.Engine) error { | ||
if err := t.RegisterDynamicMetadata("rules_enabled", rulesEnabled); err != nil { | ||
return fmt.Errorf("register dynamic 'promscale_rules_enabled' metric for telemetry: %w", err) | ||
} | ||
if err := t.RegisterDynamicMetadata("alerting_enabled", alertingEnabled); err != nil { | ||
return fmt.Errorf("register dynamic 'promscale_alerting_enabled' metric for telemetry: %w", err) | ||
} | ||
return nil | ||
func InitTelemetry() { | ||
telemetry.Registry.Update("rules_enabled", "0") | ||
telemetry.Registry.Update("alerting_enabled", "0") | ||
} | ||
|
||
func (m *Manager) getReloader(cfg *Config) func() error { | ||
|
@@ -124,17 +93,17 @@ func (m *Manager) getReloader(cfg *Config) func() error { | |
|
||
func (m *Manager) updateTelemetry(cfg *Config) { | ||
if cfg.ContainsRules() { | ||
rulesEnabled.Set(1) | ||
telemetry.Registry.Update("rules_enabled", "1") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure how I feel about these hardcoded strings in various places |
||
if cfg.ContainsAlertingConfig() { | ||
alertingEnabled.Set(1) | ||
telemetry.Registry.Update("alerting_enabled", "1") | ||
} else { | ||
log.Debug("msg", "Alerting configuration not present in the given Prometheus configuration file. Alerting will not be initialized") | ||
alertingEnabled.Set(0) | ||
telemetry.Registry.Update("alerting_enabled", "0") | ||
} | ||
return | ||
} | ||
log.Debug("msg", "Rules files not found. Rules and alerting configuration will not be initialized") | ||
rulesEnabled.Set(0) | ||
telemetry.Registry.Update("rules_enabled", "0") | ||
} | ||
|
||
func (m *Manager) WithPostRulesProcess(f prom_rules.RuleGroupPostProcessFunc) { | ||
|
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,27 @@ | ||
// This file and its contents are licensed under the Apache License 2.0. | ||
// Please see the included NOTICE for copyright information and | ||
// LICENSE for a copy of the license. | ||
|
||
package telemetry | ||
|
||
import "sync" | ||
|
||
type reg struct { | ||
r sync.Map | ||
} | ||
|
||
func (r *reg) Update(telemetryName, value string) { | ||
r.r.Store(telemetryName, value) | ||
} | ||
|
||
func (r *reg) metadata() (m Metadata) { | ||
m = Metadata{} | ||
r.r.Range(func(telemetryName, value interface{}) bool { | ||
m[telemetryName.(string)] = value.(string) | ||
return true | ||
}) | ||
return m | ||
} | ||
|
||
// Registry is a telemetry holder that is mutable and can be filled from anywhere in Promscale. | ||
var Registry reg |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
unknown
seems better