Skip to content

Commit ce9e048

Browse files
update logic for setting metric
1 parent eaf55fe commit ce9e048

File tree

8 files changed

+47
-36
lines changed

8 files changed

+47
-36
lines changed

receiver/splunkenterprisereceiver/documentation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ The status of a rolling restart.
417417

418418
| Name | Description | Values |
419419
| ---- | ----------- | ------ |
420-
| splunk.searchable.restart | String that indicates if a searchable rolling restart/upgrade in progress.t | Any Str |
421-
| splunk.rollingorrestart | String that indicates if there is a rolling restart or rolling upgrade in progress. | Any Str |
420+
| splunk.searchable.restart | Boolean that indicates if a searchable rolling restart/upgrade in progress.t | Any Bool |
421+
| splunk.rollingorrestart | Boolean that indicates if there is a rolling restart or rolling upgrade in progress. | Any Bool |
422422

423423
### splunk.indexer.throughput
424424

receiver/splunkenterprisereceiver/internal/metadata/generated_metrics.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/splunkenterprisereceiver/internal/metadata/generated_metrics_test.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/splunkenterprisereceiver/metadata.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ attributes:
4646
description: The Health (in color form) of a Splunk Feature from the Splunk Health Introspection Endpoint
4747
type: string
4848
splunk.searchable.restart:
49-
description: String that indicates if a searchable rolling restart/upgrade in progress.t
50-
type: string
49+
description: Boolean that indicates if a searchable rolling restart/upgrade in progress.t
50+
type: bool
5151
splunk.rollingorrestart:
52-
description: String that indicates if there is a rolling restart or rolling upgrade in progress.
53-
type: string
52+
description: Boolean that indicates if there is a rolling restart or rolling upgrade in progress.
53+
type: bool
5454

5555
metrics:
5656
splunk.license.index.usage:

receiver/splunkenterprisereceiver/scraper.go

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func (s *splunkScraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
102102
s.scrapeKVStoreStatus,
103103
s.scrapeSearchArtifacts,
104104
s.scrapeHealth,
105+
s.scrapeIndexerClusterManagerStatus,
105106
}
106107
errChan := make(chan error, len(metricScrapes))
107108

@@ -1789,7 +1790,7 @@ func (s *splunkScraper) traverseHealthDetailFeatures(details healthDetails, now
17891790

17901791
// Scrape Indexer Cluster Manger Status Endpoint
17911792
func (s *splunkScraper) scrapeIndexerClusterManagerStatus(ctx context.Context, now pcommon.Timestamp, errs chan error) {
1792-
if !s.conf.MetricsBuilderConfig.Metrics.SplunkIndexerRollingRestartStatus.Enabled {
1793+
if !s.conf.MetricsBuilderConfig.Metrics.SplunkIndexerRollingrestartStatus.Enabled {
17931794
return
17941795
}
17951796

@@ -1816,27 +1817,11 @@ func (s *splunkScraper) scrapeIndexerClusterManagerStatus(ctx context.Context, n
18161817
return
18171818
}
18181819

1819-
restartOrUpgrade := "false"
1820-
if icms.Entry.Content.RollingRestartOrUpgrade {
1821-
restartOrUpgrade = "true"
1822-
}
1823-
1824-
searchable := "false"
1825-
if icms.Entry.Content.SearchableRolling {
1826-
searchable = "true"
1827-
}
18281820

1829-
restarting := icms.Entry.Content.RollingRestartOrUpgrade || icms.Entry.Content.SearchableRolling || icms.Entry.Content.RollingRestartFlag
1830-
1831-
for _, mtsRestartOrUpgrade := range []string{"false", "true"} {
1832-
for _, mtsSearchable := range []string{"false", "true"} {
1833-
if restartOrUpgrade == mtsRestartOrUpgrade && searchable == mtsSearchable && restarting {
1834-
// If we're restarting, put a 1 in the gauge that matches the current state
1835-
s.mb.RecordSplunkIndexerRollingrestartStatusDataPoint(now, 1, mtsRestartOrUpgrade, mtsSearchable)
1836-
} else {
1837-
// Put a zero in all the other gauges
1838-
s.mb.RecordSplunkIndexerRollingrestartStatusDataPoint(now, 0, mtsRestartOrUpgrade, mtsSearchable)
1839-
}
1821+
for _, ic := range icms.Entries {
1822+
if ic.Content.RollingRestartOrUpgrade {
1823+
s.mb.RecordSplunkIndexerRollingrestartStatusDataPoint(now, 1, ic.Content.SearchableRolling, ic.Content.RollingRestartFlag)
18401824
}
1825+
s.mb.RecordSplunkIndexerRollingrestartStatusDataPoint(now, 0, ic.Content.SearchableRolling, ic.Content.RollingRestartFlag)
18411826
}
18421827
}

receiver/splunkenterprisereceiver/scraper_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ func mockDispatchArtifacts(w http.ResponseWriter, _ *http.Request) {
5454
_, _ = w.Write([]byte(`{"links":{},"origin":"https://somehost:8089/services/server/status/dispatch-artifacts","updated":"2024-10-24T04:46:47+00:00","generator":{"build":"05775df3af30","version":"9.2.2406.108"},"entry":[{"name":"result","id":"https://somehost:8089/services/server/status/dispatch-artifacts/result","updated":"1970-01-01T00:00:00+00:00","links":{"alternate":"/services/server/status/dispatch-artifacts/result","list":"/services/server/status/dispatch-artifacts/result"},"author":"system","acl":{"app":"","can_list":true,"can_write":true,"modifiable":false,"owner":"system","perms":{"read":["*"],"write":[]},"removable":false,"sharing":"system"},"content":{"adhoc_count":"7","adhoc_size_mb":"1","adhoc_subsearch_count":"0","adhoc_subsearch_size_mb":"0","cached_job_status_info_csv_size_mb":"0","cached_job_status_status_csv_size_mb":"0","cached_job_status_total_entries":"20","completed_count":"20","completed_size_mb":"2","count_summary":"1","disk_usage_MB":"2","eai:acl":null,"incomple_count":"0","incomple_size_mb":"0","invalid_count":"1","remote_count":"0","remote_mb":"0","rsa_count":"0","rsa_scheduled_count":"0","rsa_scheduled_size_mb":"0","rsa_size_mb":"0","scheduled_count":"13","scheduled_size_mb":"1","scheduled_subsearch_count":"0","scheduled_subsearch_size_mb":"0","ss_count":"7","status_cache_info_csv_size_mb":"0","status_cache_status_csv_size_mb":"0","status_cache_total_entries":"20","temp_dispatch_count":"0","temp_dispatch_size_mb":"0","top_apps":{"0":{"splunk_instrumentation":"6"},"1":{"search":"1"}},"top_named_searches":null,"top_users":{"0":{"splunk-system-user":"6"},"1":{"internal_observability":"1"}},"total_count":"7"}}],"paging":{"total":1,"perPage":30,"offset":0},"messages":[]}`))
5555
}
5656

57+
func mockIndexerClusterMangerStatus(w http.ResponseWriter, _ *http.Request) {
58+
status := http.StatusOK
59+
w.Header().Set("Content-Type", "application/json")
60+
w.WriteHeader(status)
61+
_, _ = w.Write([]byte(`{"links":{},"origin":"https://somehost:8089/services/cluster/manager/status","updated":"2025-03-27T22:21:40+00:00","generator":{"build":"b10ab43f821f","version":"9.3.2408.109"},"entry":[{"name":"master","id":"https://somehost:8089/services/cluster/manager/status/master","updated":"1970-01-01T00:00:00+00:00","links":{"alternate":"/services/cluster/manager/status/master","list":"/services/cluster/manager/status/master"},"author":"system","acl":{"app":"","can_list":true,"can_write":true,"modifiable":false,"owner":"system","perms":{"read":["admin","index-manager","internal_ops_admin","splunk-system-role"],"write":["admin","index-manager","internal_ops_admin","splunk-system-role"]},"removable":false,"sharing":"system"},"content":{"available_sites":"[site11, site12, site13]","decommission_force_timeout":"0","eai:acl":null,"ha_mode":"Disabled","maintenance_mode":false,"messages":"","multisite":true,"peers":{},"restart_inactivity_timeout":"0","restart_progress":{"done":[],"failed":[],"in_progress":[],"skipped":[],"to_be_restarted":[]},"rolling_restart_flag":false,"rolling_restart_or_upgrade":false,"rolling_restart_type":"None","searchable_rolling":false,"service_ready_flag":true}}],"paging":{"total":1,"perPage":30,"offset":0},"messages":[]}
62+
`))
63+
}
64+
5765
// mock server create
5866
func createMockServer() *httptest.Server {
5967
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -66,6 +74,8 @@ func createMockServer() *httptest.Server {
6674
mockIntrospectionQueues(w, r)
6775
case "/services/server/status/dispatch-artifacts?output_mode=json&count=-1":
6876
mockDispatchArtifacts(w, r)
77+
case "/services/cluster/manager/status?output_mode=json":
78+
mockIndexerClusterMangerStatus(w, r)
6979
default:
7080
http.NotFoundHandler().ServeHTTP(w, r)
7181
}
@@ -90,6 +100,7 @@ func TestScraper(t *testing.T) {
90100
metricsettings.Metrics.SplunkDataIndexesExtendedBucketWarmCount.Enabled = true
91101
metricsettings.Metrics.SplunkServerIntrospectionQueuesCurrent.Enabled = true
92102
metricsettings.Metrics.SplunkServerIntrospectionQueuesCurrentBytes.Enabled = true
103+
metricsettings.Metrics.SplunkIndexerRollingrestartStatus.Enabled = true
93104

94105
cfg := &Config{
95106
IdxEndpoint: confighttp.ClientConfig{

receiver/splunkenterprisereceiver/search_result.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ type dispatchArtifactContent struct {
159159
CacheTotalEntries string `json:"cached_job_status_total_entries"`
160160
}
161161

162-
// '/services/server/health/splunkd/details'
162+
// '/services/server/health/splunkd/details
163163
type healthArtifacts struct {
164164
Entries []healthArtifactEntry `json:"entry"`
165165
}
@@ -175,7 +175,7 @@ type healthDetails struct {
175175

176176
// '/services/cluster/manager/status'
177177
type indexersClusterManagerStatus struct {
178-
Entry idxClusterManagerStatusEntry
178+
Entries []idxClusterManagerStatusEntry `json:"entry"`
179179
}
180180
type idxClusterManagerStatusEntry struct {
181181
Name string `json:"name"`

receiver/splunkenterprisereceiver/testdata/scraper/expected.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ resourceMetrics:
9595
timeUnixNano: "2000000"
9696
name: splunk.data.indexes.extended.total.size
9797
unit: By
98+
- description: The status of a rolling restart.
99+
gauge:
100+
dataPoints:
101+
- asInt: "0"
102+
attributes:
103+
- key: splunk.rollingorrestart
104+
value:
105+
boolValue: false
106+
- key: splunk.searchable.restart
107+
value:
108+
boolValue: false
109+
startTimeUnixNano: "1000000"
110+
timeUnixNano: "2000000"
111+
name: splunk.indexer.rollingrestart.status
112+
unit: '{status}'
98113
- description: Gauge tracking average bytes per second throughput of indexer. *Note:** Must be pointed at specific indexer `endpoint` and gathers metrics from only that indexer.
99114
gauge:
100115
dataPoints:

0 commit comments

Comments
 (0)