-
Notifications
You must be signed in to change notification settings - Fork 321
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
Showing
11 changed files
with
341 additions
and
42 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,3 @@ | ||
```release-note:enhancement | ||
Expose prometheus scrape metrics on sync-catalog pods | ||
``` |
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,67 @@ | ||
package metrics | ||
|
||
import ( | ||
"strconv" | ||
|
||
metricsutil "github.com/hashicorp/consul-k8s/control-plane/subcommand/common" | ||
) | ||
|
||
const ( | ||
defaultScrapePort = 20200 | ||
defaultScrapePath = "/metrics" | ||
) | ||
|
||
type Config struct { | ||
// EnableSyncCatalogMetrics indicates whether or not SyncCatalog metrics should be enabled | ||
// by default on a deployed consul-sync-catalog, passed from the helm chart via command-line flags to our controller. | ||
EnableSyncCatalogMetrics bool | ||
|
||
// The default path to use for scraping prometheus metrics, passed from the helm chart via command-line flags to our controller. | ||
DefaultPrometheusScrapePath string | ||
|
||
// The default port to use for scraping prometheus metrics, passed from the helm chart via command-line flags to our controller. | ||
DefaultPrometheusScrapePort int | ||
|
||
// Configures the retention time for metrics in the metrics store, passed from the helm chart via command-line flags to our controller. | ||
PrometheusMetricsRetentionTime string | ||
} | ||
|
||
func syncCatalogMetricsEnabled(path string) bool { | ||
if enabled, isSet := metricsutil.GetMetricsEnabled(path); isSet { | ||
return enabled | ||
} | ||
|
||
// otherwise, fallback to the global helm setting | ||
return false | ||
} | ||
|
||
func syncCatalogMetricsPort(portString string) int { | ||
port, err := strconv.Atoi(portString) | ||
if err != nil { | ||
return defaultScrapePort | ||
} | ||
|
||
if port < 1024 || port > 65535 { | ||
// if we requested a privileged port, use the default | ||
return defaultScrapePort | ||
} | ||
|
||
return port | ||
} | ||
|
||
func syncCatalogMetricsPath(path string) string { | ||
if path, isSet := metricsutil.GetScrapePath(path); isSet { | ||
return path | ||
} | ||
|
||
// otherwise, fallback to the global helm setting | ||
return defaultScrapePath | ||
} | ||
|
||
func SyncCatalogMetricsConfig(enableMetrics, metricsPort, metricsPath string) Config { | ||
return Config{ | ||
EnableSyncCatalogMetrics: syncCatalogMetricsEnabled(enableMetrics), | ||
DefaultPrometheusScrapePort: syncCatalogMetricsPort(metricsPort), | ||
DefaultPrometheusScrapePath: syncCatalogMetricsPath(metricsPath), | ||
} | ||
} |
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
Oops, something went wrong.