Skip to content

Commit 421a633

Browse files
shalper2Fiery-Fenix
authored andcommitted
[receiver/splunkenterprise] 36330 add build info as attribute (open-telemetry#37508)
#### Description Adds a new attribute which optionally includes build and/or version info for the Splunk host being monitored. Also removed the use of `context` module in the client calls used by the scrape functions. #### Link to tracking issue Fixes [36330](open-telemetry#36330) #### Testing unit tests updated and passing #### Documentation README.md was updated to include new configuration field
1 parent 644f1b6 commit 421a633

15 files changed

+947
-365
lines changed

.chloggen/36330-bi-as-attrs.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: 'breaking'
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: splunkenterprisereceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "added new attributes to the receiver and modified config"
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [36330]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/splunkenterprisereceiver/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The following settings are optional:
3434

3535
* `collection_interval` (default: 10m): The time between scrape attempts.
3636
* `timeout` (default: 60s): The time the scrape function will wait for a response before returning empty.
37+
* `build_version_info` (default: false): Elect to run an additional scrape which will retrieve build and version info for the configured endpoints and attach this as attributes to the selected metrics. A value of false will report an empty string as the attribute value but will speed up the receiver slightly.
3738

3839
Example:
3940

receiver/splunkenterprisereceiver/client.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type splunkEntClient struct {
3636
}
3737

3838
// The splunkEntClient is made up of a number of splunkClients defined for each configured endpoint
39-
type splunkClientMap map[any]splunkClient
39+
type splunkClientMap map[string]splunkClient
4040

4141
// The client does not carry the endpoint that is configured with it and golang does not support mixed
4242
// type arrays so this struct contains the pair: the client configured for the endpoint and the endpoint
@@ -92,12 +92,8 @@ func newSplunkEntClient(ctx context.Context, cfg *Config, h component.Host, s co
9292
}
9393

9494
// For running ad hoc searches only
95-
func (c *splunkEntClient) createRequest(ctx context.Context, sr *searchResponse) (req *http.Request, err error) {
96-
// get endpoint type from the context
97-
eptType := ctx.Value(endpointType("type"))
98-
if eptType == nil {
99-
return nil, errCtxMissingEndpointType
100-
}
95+
func (c *splunkEntClient) createRequest(eptType string, sr *searchResponse) (req *http.Request, err error) {
96+
ctx := context.WithValue(context.Background(), endpointType("type"), eptType)
10197

10298
// Running searches via Splunk's REST API is a two step process: First you submit the job to run
10399
// this returns a jobid which is then used in the second part to retrieve the search results
@@ -137,14 +133,9 @@ func (c *splunkEntClient) createRequest(ctx context.Context, sr *searchResponse)
137133
}
138134

139135
// forms an *http.Request for use with Splunk built-in API's (like introspection).
140-
func (c *splunkEntClient) createAPIRequest(ctx context.Context, apiEndpoint string) (req *http.Request, err error) {
136+
func (c *splunkEntClient) createAPIRequest(eptType string, apiEndpoint string) (req *http.Request, err error) {
141137
var u string
142-
143-
// get endpoint type from the context
144-
eptType := ctx.Value(endpointType("type"))
145-
if eptType == nil {
146-
return nil, errCtxMissingEndpointType
147-
}
138+
ctx := context.WithValue(context.Background(), endpointType("type"), eptType)
148139

149140
if e, ok := c.clients[eptType]; ok {
150141
u = e.endpoint.String() + apiEndpoint
@@ -167,7 +158,16 @@ func (c *splunkEntClient) makeRequest(req *http.Request) (*http.Response, error)
167158
if eptType == nil {
168159
return nil, errCtxMissingEndpointType
169160
}
170-
if sc, ok := c.clients[eptType]; ok {
161+
162+
var endpointType string
163+
switch t := eptType.(type) {
164+
case string:
165+
endpointType = t
166+
default:
167+
endpointType = fmt.Sprintf("%v", eptType)
168+
}
169+
170+
if sc, ok := c.clients[endpointType]; ok {
171171
res, err := sc.client.Do(req)
172172
if err != nil {
173173
return nil, err

receiver/splunkenterprisereceiver/client_test.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,9 @@ func TestClientCreateRequest(t *testing.T) {
126126
},
127127
}
128128

129-
ctx := context.Background()
130-
ctx = context.WithValue(ctx, endpointType("type"), typeIdx)
131129
for _, test := range tests {
132130
t.Run(test.desc, func(t *testing.T) {
133-
req, err := test.client.createRequest(ctx, test.sr)
131+
req, err := test.client.createRequest(typeIdx, test.sr)
134132
require.NoError(t, err)
135133
// have to test specific parts since individual fields are pointers
136134
require.Equal(t, test.expected.URL, req.URL)
@@ -165,9 +163,7 @@ func TestAPIRequestCreate(t *testing.T) {
165163

166164
require.NoError(t, err)
167165

168-
ctx := context.Background()
169-
ctx = context.WithValue(ctx, endpointType("type"), typeIdx)
170-
req, err := client.createAPIRequest(ctx, "/test/endpoint")
166+
req, err := client.createAPIRequest(typeIdx, "/test/endpoint")
171167
require.NoError(t, err)
172168

173169
// build the expected request

receiver/splunkenterprisereceiver/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Config struct {
2727
IdxEndpoint confighttp.ClientConfig `mapstructure:"indexer"`
2828
SHEndpoint confighttp.ClientConfig `mapstructure:"search_head"`
2929
CMEndpoint confighttp.ClientConfig `mapstructure:"cluster_master"`
30+
VersionInfo bool `mapstructure:"build_version_info"`
3031
}
3132

3233
func (cfg *Config) Validate() (errors error) {

0 commit comments

Comments
 (0)