-
Notifications
You must be signed in to change notification settings - Fork 3k
[receiver/oracledb] Add service.instance.id resource attribute to metrics and logs #42421
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
base: main
Are you sure you want to change the base?
Changes from 81 commits
14fef66
9dae10e
5c41bae
ae28536
5e18297
7481e69
1c300a9
5400baf
7e5b5b4
d258f51
5099908
74e948b
4e2be2d
8668f73
5c6a451
b40e443
0f2f58a
1f145fc
425797d
dcf0ada
c3f9ff5
7e263c6
5fd856a
59c8520
0b61051
a207210
72ecc74
8bd1571
eede7b6
95da33b
65835db
b60a3e9
43645d5
05a9d00
52ef2c8
bed9ef0
92e9736
d9a9d6d
f8d9ebe
819a345
dded7b5
a466a0e
b734b81
eefae2e
2160cdc
fde3f2d
cde522f
edb64c6
78e445a
baa59cc
ab6ad10
1bd1d49
c9a42d4
4f7d16c
f91ba9d
cd5c712
775fa1d
455b0d5
34f29e7
0e32ad5
fdb70cd
17afc8d
6674daa
c0424c6
a837002
3a48ed4
a2f992b
999e0de
901bc83
ef1b272
8a51a74
6b56b29
041e4ee
98bbc5c
ef87cd2
aa0b9eb
ea60e09
3df3c2b
d7b3a9c
47b4443
5719fbd
349978b
56108ea
c3c9abd
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,29 @@ | ||
# 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: oracledbreceiver | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: service.instance.id attribute is added in resourceAttributes of all metrics and logs in oracledbreceiver | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [42402] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | | ||
The `service.instance.id` attribute is added in the format `<host>:<port>` to uniquely identify | ||
Oracle db hosts. | ||
|
||
# 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.
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 |
---|---|---|
|
@@ -11,6 +11,8 @@ import ( | |
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net" | ||
"os" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
|
@@ -131,6 +133,7 @@ type oracleScraper struct { | |
topQueryCollectCfg TopQueryCollection | ||
obfuscator *obfuscator | ||
querySampleCfg QuerySample | ||
serviceInstanceID string | ||
} | ||
|
||
func newScraper(metricsBuilder *metadata.MetricsBuilder, metricsBuilderConfig metadata.MetricsBuilderConfig, scrapeCfg scraperhelper.ControllerConfig, logger *zap.Logger, providerFunc dbProviderFunc, clientProviderFunc clientProviderFunc, instanceName, hostName string) (scraper.Metrics, error) { | ||
|
@@ -164,6 +167,7 @@ func newLogsScraper(logsBuilder *metadata.LogsBuilder, logsBuilderConfig metadat | |
querySampleCfg: querySampleCfg, | ||
hostName: hostName, | ||
obfuscator: newObfuscator(), | ||
serviceInstanceID: getInstanceID(hostName, logger), | ||
} | ||
return scraper.NewLogs(s.scrapeLogs, scraper.WithShutdown(s.shutdown), scraper.WithStart(s.start)) | ||
} | ||
|
@@ -502,9 +506,8 @@ func (s *oracleScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { | |
} | ||
} | ||
|
||
rb := s.mb.NewResourceBuilder() | ||
rb.SetOracledbInstanceName(s.instanceName) | ||
rb.SetHostName(s.hostName) | ||
rb := s.setupResourceBuilder(s.mb.NewResourceBuilder()) | ||
|
||
out := s.mb.Emit(metadata.WithResource(rb.Emit())) | ||
s.logger.Debug("Done scraping") | ||
if len(scrapeErrors) > 0 { | ||
|
@@ -634,9 +637,7 @@ func (s *oracleScraper) collectTopNMetricData(ctx context.Context, logs plog.Log | |
hits = s.obfuscateCacheHits(hits) | ||
childAddressToPlanMap := s.getChildAddressToPlanMap(ctx, hits) | ||
|
||
rb := s.lb.NewResourceBuilder() | ||
rb.SetOracledbInstanceName(s.instanceName) | ||
rb.SetHostName(s.hostName) | ||
rb := s.setupResourceBuilder(s.lb.NewResourceBuilder()) | ||
|
||
for _, hit := range hits { | ||
planBytes, err := json.Marshal(childAddressToPlanMap[hit.childAddress]) | ||
|
@@ -717,9 +718,7 @@ func (s *oracleScraper) collectQuerySamples(ctx context.Context, logs plog.Logs) | |
scrapeErrors = append(scrapeErrors, fmt.Errorf("error executing %s: %w", samplesQuery, err)) | ||
} | ||
|
||
rb := s.lb.NewResourceBuilder() | ||
rb.SetOracledbInstanceName(s.instanceName) | ||
rb.SetHostName(s.hostName) | ||
rb := s.setupResourceBuilder(s.lb.NewResourceBuilder()) | ||
|
||
for _, row := range rows { | ||
if row[sqlText] == "" { | ||
|
@@ -828,3 +827,24 @@ func (s *oracleScraper) shutdown(_ context.Context) error { | |
} | ||
return s.db.Close() | ||
} | ||
|
||
func (s *oracleScraper) setupResourceBuilder(rb *metadata.ResourceBuilder) *metadata.ResourceBuilder { | ||
rb.SetOracledbInstanceName(s.instanceName) | ||
rb.SetHostName(s.hostName) | ||
rb.SetServiceInstanceID(s.serviceInstanceID) | ||
return rb | ||
} | ||
|
||
func getInstanceID(hostString string, logger *zap.Logger) string { | ||
host, port, err := net.SplitHostPort(hostString) | ||
if err == nil && (strings.EqualFold(host, "localhost") || net.ParseIP(host).IsLoopback()) { | ||
host, err = os.Hostname() | ||
} | ||
|
||
if err != nil { | ||
logger.Warn("Failed to compute service.instance.id", zap.Error(err)) | ||
return "unknown:1521" | ||
} | ||
|
||
return host + ":" + port | ||
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. should this also have the DB name? 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. The host+port combination should supply enough context to identify the db instance. |
||
} |
Uh oh!
There was an error while loading. Please reload this page.