Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Metrics: Ensure Stratos Metrics metadata file is optional #4801

Merged
merged 4 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function generateMetricsEndpoint() {
authTypes: [],
renderPriority: 1
},
metadata => `/endpoints/metrics/${metadata.guid}`
entity => `/endpoints/metrics/${entity.endpointId}`
);
return stratosEntityCatalog.metricsEndpoint;
}
Expand Down
40 changes: 26 additions & 14 deletions src/jetstream/plugins/metrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,24 @@ func (m *MetricsSpecification) Connect(ec echo.Context, cnsiRecord interfaces.CN

var h = m.portalProxy.GetHttpClient(cnsiRecord.SkipSSLValidation)
res, err := h.Do(req)
// Error performing the request?
if err != nil {
log.Errorf("Error performing http request - response: %v, error: %v", res, err)
errMessage := ""
if res.StatusCode == http.StatusUnauthorized {
errMessage = ": Unauthorized"
}
return nil, false, interfaces.NewHTTPShadowError(
res.StatusCode,
fmt.Sprintf("Could not connect to the endpoint%s", errMessage),
"Could not connect to the endpoint: %s", err)
}

if err == nil && res.StatusCode == http.StatusNotFound {
defer res.Body.Close()

// If we got anything other than a 200, then we did not find the Stratos Metrics metadata file
if res.StatusCode != http.StatusOK {
log.Debug("Did not find Stratos Metrics metadata file")
log.Debug("Checking if this is a prometheus endpoint")
// This could be a bosh-prometheus endpoint, verify that this is a prometheus endpoint
statusEndpoint := fmt.Sprintf("%s/api/v1/status/config", cnsiRecord.APIEndpoint)
Expand All @@ -195,28 +211,24 @@ func (m *MetricsSpecification) Connect(ec echo.Context, cnsiRecord interfaces.CN
}
m.addAuth(req, auth)

// Get for /api/v1/status/config
response, err := h.Do(req)
if err != nil {
log.Errorf("Error fetching /api/v1/status/config - response: %v, error: %v", response, err)
return nil, false, interfaces.LogHTTPError(res, err)
}

defer response.Body.Close()
if err != nil || response.StatusCode != http.StatusOK {
log.Errorf("Error performing http request - response: %v, error: %v", response, err)
if response.StatusCode != http.StatusOK {
log.Errorf("Error fetching /api/v1/status/config - response: %v, error: %v", response, err)
return nil, false, interfaces.LogHTTPError(res, err)
}

tr.Metadata, _ = m.createMetadata(cnsiRecord.APIEndpoint, h, auth)
return tr, false, nil
} else if err != nil || res.StatusCode != http.StatusOK {
log.Errorf("Error performing http request - response: %v, error: %v", res, err)
errMessage := ""
if res.StatusCode == http.StatusUnauthorized {
errMessage = ": Unauthorized"
}
return nil, false, interfaces.NewHTTPShadowError(
res.StatusCode,
fmt.Sprintf("Could not connect to the endpoint%s", errMessage),
"Could not connect to the endpoint: %s", err)
}

defer res.Body.Close()
// We read the Stratos Metadata file ok
body, _ := ioutil.ReadAll(res.Body)
// Put the body in the token metadata
tr.Metadata = string(body)
Expand Down