-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metric to monitor JFrog Access Federation validation endpoint (#154)
* Add Access Federation Circle of Trust validation endpoint to Artifactory module * Add Access Federation validation metric * Add metric to parameter list and README * Fix SonarQube finding define constant * Refactor response and error handling in utils (#1) * Refactor utils to clean up request and error handling * Readd warning for not found, move unmarshalling to after http error handling * Only handle unmarshalling error if HTTP status not successful
- Loading branch information
Showing
7 changed files
with
218 additions
and
108 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
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,49 @@ | ||
package artifactory | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
const ( | ||
accessFederationValidateEndpoint = "access/api/v1/system/federation/validate_server" | ||
) | ||
|
||
type AccessFederationValid struct { | ||
Status bool | ||
NodeId string | ||
} | ||
|
||
// FetchAccessFederationValidStatus checks one of the federation endpoints to see if federation is enabled | ||
func (c *Client) FetchAccessFederationValidStatus() (AccessFederationValid, error) { | ||
accessFederationValid := AccessFederationValid{Status: false} | ||
|
||
// Use ping endpoint to retrieve nodeID, since this is not returned by access API | ||
resp, err := c.FetchHTTP(pingEndpoint) | ||
if err != nil { | ||
return accessFederationValid, err | ||
} | ||
accessFederationValid.NodeId = resp.NodeId | ||
|
||
jsonBody := map[string]string{ | ||
"url": c.accessFederationTarget, | ||
} | ||
jsonBytes, err := json.Marshal(jsonBody) | ||
if err != nil { | ||
c.logger.Error("issue when trying to marshal JSON body") | ||
return accessFederationValid, err | ||
} | ||
headers := map[string]string{ | ||
"Content-Type": "application/json", | ||
} | ||
c.logger.Debug( | ||
"Fetching JFrog Access Federation validation status", | ||
"endpoint", accessFederationValidateEndpoint, | ||
"target", c.accessFederationTarget, | ||
) | ||
_, err = c.PostHTTP(accessFederationValidateEndpoint, jsonBytes, &headers) | ||
if err != nil { | ||
return accessFederationValid, err | ||
} | ||
accessFederationValid.Status = true | ||
return accessFederationValid, nil | ||
} |
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,27 @@ | ||
package collector | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
func (e *Exporter) exportAccessFederationValidate(ch chan<- prometheus.Metric) error { | ||
// Fetch Federation Mirror Lags | ||
accessFederationValid, err := e.client.FetchAccessFederationValidStatus() | ||
if err != nil { | ||
e.logger.Warn( | ||
"JFrog Access Federation Circle of Trust was not successfully validated", | ||
"target", e.client.GetAccessFederationTarget(), | ||
"status", accessFederationValid.Status, | ||
"err", err.Error(), | ||
) | ||
e.totalAPIErrors.Inc() | ||
} | ||
value := convArtiToPromBool(accessFederationValid.Status) | ||
e.logger.Debug( | ||
logDbgMsgRegMetric, | ||
"metric", "accessFederationValid", | ||
"value", value, | ||
) | ||
ch <- prometheus.MustNewConstMetric(accessMetrics["accessFederationValid"], prometheus.GaugeValue, value, accessFederationValid.NodeId) | ||
return nil | ||
} |
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.