Skip to content
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

Splunkenterprisereceiver add health metric (#36695) #36695

Merged
merged 23 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0c5c347
Splunkenterprisereceiver add health metric (#1)
macolby42 Dec 5, 2024
2ae137c
Clarified splunk.health description
macolby42 Dec 5, 2024
785e065
Update changelog with real PR number
macolby42 Dec 5, 2024
0969300
Merge branch 'main' into main
macolby42 Dec 5, 2024
9c18781
Added colors to metric description for full clarity
macolby42 Dec 6, 2024
b24f34c
Merge branch 'main' into main
macolby42 Dec 6, 2024
8f9cac5
Merge branch 'main' into main
macolby42 Dec 9, 2024
a6039c7
Ran make generate to update
macolby42 Dec 9, 2024
af8f5f1
Merge branch 'open-telemetry:main' into main
macolby42 Dec 9, 2024
113cb9d
Merge branch 'open-telemetry:main' into main
macolby42 Jan 2, 2025
d849127
Merge branch 'open-telemetry:main' into main
macolby42 Jan 3, 2025
8c5c99d
Merge branch 'open-telemetry:main' into main
macolby42 Jan 3, 2025
795f32c
Add PR Updates (#2)
macolby42 Jan 3, 2025
1d5f484
Merge branch 'open-telemetry:main' into main
macolby42 Jan 6, 2025
072fa35
Merge branch 'open-telemetry:main' into main
macolby42 Jan 13, 2025
c4e1814
Merge branch 'open-telemetry:main' into main
macolby42 Jan 14, 2025
db85aca
Merge branch 'open-telemetry:main' into main
macolby42 Jan 21, 2025
32cb7b3
Merge branch 'open-telemetry:main' into main
macolby42 Feb 6, 2025
12aff97
Merge branch 'open-telemetry:main' into main
macolby42 Feb 6, 2025
e746970
Merge branch 'main' into main
MovieStoreGuy Feb 7, 2025
820843c
Merge branch 'open-telemetry:main' into main
macolby42 Feb 10, 2025
b92d82d
Merge branch 'open-telemetry:main' into main
macolby42 Feb 11, 2025
958c7ad
Merge branch 'main' into main
MovieStoreGuy Feb 11, 2025
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
22 changes: 22 additions & 0 deletions .chloggen/changes.yaml
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'
atoulme marked this conversation as resolved.
Show resolved Hide resolved

# 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]
15 changes: 15 additions & 0 deletions receiver/splunkenterprisereceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,21 @@ Size in bytes on disk of this index *Note:** Must be pointed at specific indexer
| ---- | ----------- | ------ |
| splunk.index.name | The name of the index reporting a specific KPI | Any Str |

### splunk.health

The status ('red', 'yellow', or 'green') of the Splunk server. Health of 'red' produces a 0 while all other colors produce a 1.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {status} | Gauge | Int |

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| splunk.feature | The Feature name from the Splunk Health Introspection Endpoint | Any Str |
| splunk.feature.health | The Health (in color form) of a Splunk Feature from the Splunk Health Introspection Endpoint | Any Str |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure you need that? you already get the status via the value right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value only indicates whether it is red or not. A value of 1 could be green or yellow. It's not ideal, but color system for splunkd what implemented long before our use of OTel.


### splunk.indexer.throughput

Gauge tracking average bytes per second throughput of indexer. *Note:** Must be pointed at specific indexer `endpoint` and gathers metrics from only that indexer.
Expand Down

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
Expand Up @@ -19,6 +19,8 @@ all_set:
enabled: true
splunk.data.indexes.extended.total.size:
enabled: true
splunk.health:
enabled: true
splunk.indexer.avg.rate:
enabled: true
splunk.indexer.cpu.time:
Expand Down Expand Up @@ -101,6 +103,8 @@ none_set:
enabled: false
splunk.data.indexes.extended.total.size:
enabled: false
splunk.health:
enabled: false
splunk.indexer.avg.rate:
enabled: false
splunk.indexer.cpu.time:
Expand Down
14 changes: 14 additions & 0 deletions receiver/splunkenterprisereceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ attributes:
splunk.searchartifacts.cache.type:
description: The search artifacts cache type
type: string
splunk.feature:
description: The Feature name from the Splunk Health Introspection Endpoint
type: string
splunk.feature.health:
description: The Health (in color form) of a Splunk Feature from the Splunk Health Introspection Endpoint
type: string

metrics:
splunk.license.index.usage:
Expand Down Expand Up @@ -345,6 +351,14 @@ metrics:
aggregation_temporality: cumulative
value_type: int
attributes: [splunk.host]
#`services/server/health/splunkd/details`
splunk.health:
enabled: false
description: The status ('red', 'yellow', or 'green') of the Splunk server. Health of 'red' produces a 0 while all other colors produce a 1.
unit: "{status}"
gauge:
value_type: int
attributes: [splunk.feature, splunk.feature.health]

tests:
config:
57 changes: 55 additions & 2 deletions receiver/splunkenterprisereceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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)
}
}
15 changes: 15 additions & 0 deletions receiver/splunkenterprisereceiver/search_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var apiDict = map[string]string{
`SplunkIntrospectionQueues`: `/services/server/introspection/queues?output_mode=json&count=-1`,
`SplunkKVStoreStatus`: `/services/kvstore/status?output_mode=json`,
`SplunkDispatchArtifacts`: `/services/server/status/dispatch-artifacts?output_mode=json&count=-1`,
`SplunkHealth`: `/services/server/health/splunkd/details?output_mode=json`,
}

type searchResponse struct {
Expand Down Expand Up @@ -156,3 +157,17 @@ type DispatchArtifactContent struct {
StatusCacheSize string `json:"cached_job_status_status_csv_size_mb"`
CacheTotalEntries string `json:"cached_job_status_total_entries"`
}

// '/services/server/health/splunkd/details
type healthArtifacts struct {
Entries []healthArtifactEntry `json:"entry"`
}

type healthArtifactEntry struct {
Content healthDetails `json:"content"`
}

type healthDetails struct {
Health string `json:"health"`
Features map[string]healthDetails `json:"features,omitempty"`
}