-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Splunkenterprisereceiver add health metric (#36695) #36695
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
Changes from 4 commits
0c5c347
2ae137c
785e065
0969300
9c18781
b24f34c
8f9cac5
a6039c7
af8f5f1
113cb9d
d849127
8c5c99d
795f32c
1d5f484
072fa35
c4e1814
db85aca
32cb7b3
12aff97
e746970
820843c
b92d82d
958c7ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: 'enhancement' | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: 'splunkenterprisereceiver' | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: "Added a new `splunk.health` metric." | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [36695] | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,7 @@ func (s *splunkScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { | |
s.scrapeIndexerAvgRate, | ||
s.scrapeKVStoreStatus, | ||
s.scrapeSearchArtifacts, | ||
s.scrapeHealth, | ||
} | ||
errChan := make(chan error, len(metricScrapes)) | ||
|
||
|
@@ -1075,12 +1076,12 @@ func unmarshallSearchReq(res *http.Response, sr *searchResponse) error { | |
|
||
body, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
return fmt.Errorf("Failed to read response: %w", err) | ||
return fmt.Errorf("failed to read response: %w", err) | ||
} | ||
|
||
err = xml.Unmarshal(body, &sr) | ||
if err != nil { | ||
return fmt.Errorf("Failed to unmarshall response: %w", err) | ||
return fmt.Errorf("failed to unmarshall response: %w", err) | ||
} | ||
|
||
return nil | ||
|
@@ -1733,3 +1734,55 @@ func (s *splunkScraper) scrapeSearchArtifacts(ctx context.Context, now pcommon.T | |
} | ||
} | ||
} | ||
|
||
// Scrape Health Introspection Endpoint | ||
func (s *splunkScraper) scrapeHealth(ctx context.Context, now pcommon.Timestamp, errs chan error) { | ||
if !s.conf.MetricsBuilderConfig.Metrics.SplunkHealth.Enabled { | ||
return | ||
} | ||
|
||
ctx = context.WithValue(ctx, endpointType("type"), typeCm) | ||
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. Do you mind expanding on why there is values being stored inside the context here? 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. This context value (which is defined in each scrape) is used to route the request to the correct api endpoint |
||
|
||
ept := apiDict[`SplunkHealth`] | ||
var ha HealthArtifacts | ||
|
||
req, err := s.splunkClient.createAPIRequest(ctx, ept) | ||
if err != nil { | ||
errs <- err | ||
return | ||
} | ||
|
||
res, err := s.splunkClient.makeRequest(req) | ||
if err != nil { | ||
errs <- err | ||
return | ||
} | ||
defer res.Body.Close() | ||
|
||
if err := json.NewDecoder(res.Body).Decode(&ha); err != nil { | ||
errs <- err | ||
return | ||
} | ||
|
||
s.settings.Logger.Debug(fmt.Sprintf("Features: %s", ha.Entries)) | ||
for _, details := range ha.Entries { | ||
s.traverseHealthDetailFeatures(details.Content, now) | ||
} | ||
} | ||
|
||
func (s *splunkScraper) traverseHealthDetailFeatures(details HealthDetails, now pcommon.Timestamp) { | ||
if details.Features == nil { | ||
return | ||
} | ||
|
||
for k, feature := range details.Features { | ||
if feature.Health != "red" { | ||
s.settings.Logger.Debug(feature.Health) | ||
s.mb.RecordSplunkHealthDataPoint(now, 1, k, feature.Health) | ||
} else { | ||
s.settings.Logger.Debug(feature.Health) | ||
s.mb.RecordSplunkHealthDataPoint(now, 0, k, feature.Health) | ||
} | ||
s.traverseHealthDetailFeatures(feature, now) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.