-
Notifications
You must be signed in to change notification settings - Fork 81
Custom Metrics Fixes And Improvements #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 5 commits into
openshift:master
from
dustman9000:prom-custom-metrics
Jul 31, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
95eb5c4
Custom Metrics Fixes And Improvements
dustman9000 e526999
Disable controller-runtime metrics server
dustman9000 b29d829
Minor code optimization.
dustman9000 0f98616
Update pkg/controller/certificaterequest/issue_certificate.go
dustman9000 d6d7b1a
Update pkg/controller/certificaterequest/issue_certificate.go
dustman9000 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,115 +9,6 @@ import ( | |
| "github.com/prometheus/common/log" | ||
| ) | ||
|
|
||
| // GetListOfCertsExpiringSoon returns a list of certs expiring within the specified number of days | ||
| func GetListOfCertsExpiringSoon(domain string, durationDays int) [][]string { | ||
|
|
||
| data := [][]string{} | ||
| db, err := sql.Open("postgres", getPsqlInfo()) | ||
|
|
||
| if err != nil { | ||
| log.Error(err, "Failed to establish connection with crt.sh database") | ||
| } | ||
|
|
||
| defer db.Close() | ||
|
|
||
| today := time.Now().UTC() | ||
|
|
||
| futureDate := time.Now().UTC().AddDate(0, 0, durationDays) | ||
|
|
||
| certDuration := fmt.Sprintf("%d-%02d-%02d 00:00:00.000000", today.Year(), today.Month(), today.Day()) | ||
|
|
||
| futureDuration := fmt.Sprintf("%d-%02d-%02d 00:00:00.000000", futureDate.Year(), futureDate.Month(), futureDate.Day()) | ||
|
|
||
| rows, err := db.Query(GET_LIST_CERTS_ISSUED_BY_LE_SQL_EXPIRING_SOON, "%."+domain, certDuration, futureDuration) | ||
|
|
||
| if err != nil { | ||
| log.Error(err, "Failed to receive data from crt.sh database") | ||
| } | ||
|
|
||
| defer rows.Close() | ||
|
|
||
| for rows.Next() { | ||
| var name string | ||
| var notBefore string | ||
| var notAfter string | ||
| var row []string | ||
|
|
||
| err = rows.Scan(&name, ¬Before, ¬After) | ||
|
|
||
| if err != nil { | ||
| log.Error(err, "Error reading table") | ||
| } | ||
|
|
||
| row = append(row, name) | ||
| row = append(row, notBefore) | ||
| row = append(row, notAfter) | ||
|
|
||
| data = append(data, row) | ||
| } | ||
|
|
||
| err = rows.Err() | ||
|
|
||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| return data | ||
| } | ||
|
|
||
| // GetListOfCertsIssued returns a list of certs issued for a given domain since durationDays number of days ago | ||
| func GetListOfCertsIssued(domain string, durationDays int) [][]string { | ||
|
|
||
| data := [][]string{} | ||
|
|
||
| db, err := sql.Open("postgres", getPsqlInfo()) | ||
|
|
||
| if err != nil { | ||
| log.Error(err, "Failed to establish connection with crt.sh database") | ||
| } | ||
|
|
||
| defer db.Close() | ||
|
|
||
| t := time.Now().UTC().AddDate(0, 0, durationDays*-1) | ||
|
|
||
| certDuration := fmt.Sprintf("%d-%02d-%02d 00:00:00.000000", t.Year(), t.Month(), t.Day()) | ||
|
|
||
| rows, err := db.Query(GET_LIST_CERTS_ISSUED_BY_LE_SQL, "%."+domain, certDuration) | ||
|
|
||
| if err != nil { | ||
| log.Error(err, "Failed to receive data from crt.sh database") | ||
| } | ||
|
|
||
| defer rows.Close() | ||
|
|
||
| for rows.Next() { | ||
| var name string | ||
| var notBefore string | ||
| var notAfter string | ||
| var row []string | ||
|
|
||
| err = rows.Scan(&name, ¬Before, ¬After) | ||
|
|
||
| if err != nil { | ||
| log.Error(err, "Error reading table") | ||
| } | ||
|
|
||
| row = append(row, name) | ||
| row = append(row, notBefore) | ||
| row = append(row, notAfter) | ||
|
|
||
| data = append(data, row) | ||
| } | ||
|
|
||
| err = rows.Err() | ||
|
|
||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| return data | ||
| } | ||
|
|
||
| // GetCountOfCertsIssued returns the number of certs issued for a given domain in the last durationDays number of days | ||
| func GetCountOfCertsIssued(domain string, durationDays int) int { | ||
|
|
||
|
|
@@ -147,5 +38,5 @@ func GetCountOfCertsIssued(domain string, durationDays int) int { | |
| } | ||
|
|
||
| func getPsqlInfo() string { | ||
| return fmt.Sprintf("host=%s port=%d user=%s dbname=%s sslmode=disable", CRT_SH_PG_DB_HOSTNAME, CRT_SH_PG_DB_PORT, CRT_SH_PG_DB_USERNAME, CRT_SH_PG_DB_NAME) | ||
| return fmt.Sprintf("host=%s port=%d user=%s dbname=%s sslmode=disable binary_parameters=yes", CRT_SH_PG_DB_HOSTNAME, CRT_SH_PG_DB_PORT, CRT_SH_PG_DB_USERNAME, CRT_SH_PG_DB_NAME) | ||
|
Member
Author
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. Fix for PSQL error: |
||
| } | ||
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.