-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[chore][receiver/snowflakereceiver] #31260
Merged
dmitryax
merged 11 commits into
open-telemetry:main
from
shalper2:snowflake-scrape-refactor
Apr 4, 2024
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fe2c3d8
refactored scrape function to leverage goroutines
shalper2 6b61b8d
lint
shalper2 65090b3
refactored scrape function to leverage goroutines
shalper2 f65a380
lint
shalper2 74cd1ba
Merge remote-tracking branch 'upstream/main' into snowflake-scrape-re…
shalper2 5ae1d51
Merge remote-tracking branch 'upstream/main' into snowflake-scrape-re…
shalper2 717f289
Merge remote-tracking branch 'upstream/main' into snowflake-scrape-re…
shalper2 7d1657b
Merge remote-tracking branch 'upstream/main' into snowflake-scrape-re…
shalper2 18cbbc0
Merge remote-tracking branch 'upstream/main' into snowflake-scrape-re…
shalper2 196e68a
simplified error routine
shalper2 6d8d358
Merge remote-tracking branch 'upstream/main' into snowflake-scrape-re…
shalper2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ package snowflakereceiver // import "github.com/open-telemetry/opentelemetry-col | |||||
|
||||||
import ( | ||||||
"context" | ||||||
"sync" | ||||||
"time" | ||||||
|
||||||
"go.opentelemetry.io/collector/component" | ||||||
|
@@ -48,34 +49,76 @@ func (s *snowflakeMetricsScraper) shutdown(_ context.Context) (err error) { | |||||
return err | ||||||
} | ||||||
|
||||||
func errorListener(ctx context.Context, eQueue <-chan error, eOut chan<- *scrapererror.ScrapeErrors) { | ||||||
errs := &scrapererror.ScrapeErrors{} | ||||||
|
||||||
for { | ||||||
select { | ||||||
case <-ctx.Done(): | ||||||
eOut <- errs | ||||||
return | ||||||
case err, ok := <-eQueue: | ||||||
if err == nil || !ok { | ||||||
eOut <- errs | ||||||
return | ||||||
} | ||||||
errs.Add(err) | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
// wrapper for all of the sub-scraping tasks, implements the scraper interface for | ||||||
// snowflakeMetricsScraper | ||||||
func (s *snowflakeMetricsScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { | ||||||
errs := &scrapererror.ScrapeErrors{} | ||||||
var wg sync.WaitGroup | ||||||
var errs *scrapererror.ScrapeErrors | ||||||
|
||||||
now := pcommon.NewTimestampFromTime(time.Now()) | ||||||
metricScrapes := []func(context.Context, pcommon.Timestamp, chan<- error){ | ||||||
s.scrapeBillingMetrics, | ||||||
s.scrapeWarehouseBillingMetrics, | ||||||
s.scrapeLoginMetrics, | ||||||
s.scrapeHighLevelQueryMetrics, | ||||||
s.scrapeDBMetrics, | ||||||
s.scrapeSessionMetrics, | ||||||
s.scrapeSnowpipeMetrics, | ||||||
s.scrapeStorageMetrics, | ||||||
} | ||||||
|
||||||
// each client call has its own scrape function | ||||||
errChan := make(chan error, len(metricScrapes)) | ||||||
errOut := make(chan *scrapererror.ScrapeErrors) | ||||||
|
||||||
s.scrapeBillingMetrics(ctx, now, *errs) | ||||||
s.scrapeWarehouseBillingMetrics(ctx, now, *errs) | ||||||
s.scrapeLoginMetrics(ctx, now, *errs) | ||||||
s.scrapeHighLevelQueryMetrics(ctx, now, *errs) | ||||||
s.scrapeDBMetrics(ctx, now, *errs) | ||||||
s.scrapeSessionMetrics(ctx, now, *errs) | ||||||
s.scrapeSnowpipeMetrics(ctx, now, *errs) | ||||||
s.scrapeStorageMetrics(ctx, now, *errs) | ||||||
go func() { | ||||||
errorListener(ctx, errChan, errOut) | ||||||
}() | ||||||
|
||||||
now := pcommon.NewTimestampFromTime(time.Now()) | ||||||
|
||||||
for _, fn := range metricScrapes { | ||||||
wg.Add(1) | ||||||
go func( | ||||||
fn func(context.Context, pcommon.Timestamp, chan<- error), | ||||||
ctx context.Context, | ||||||
now pcommon.Timestamp, | ||||||
errs chan<- error, | ||||||
) { | ||||||
defer wg.Done() | ||||||
fn(ctx, now, errs) | ||||||
}(fn, ctx, now, errChan) | ||||||
} | ||||||
|
||||||
wg.Wait() | ||||||
errChan <- nil | ||||||
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.
Suggested change
|
||||||
errs = <-errOut | ||||||
rb := s.mb.NewResourceBuilder() | ||||||
rb.SetSnowflakeAccountName(s.conf.Account) | ||||||
return s.mb.Emit(metadata.WithResource(rb.Emit())), errs.Combine() | ||||||
} | ||||||
|
||||||
func (s *snowflakeMetricsScraper) scrapeBillingMetrics(ctx context.Context, t pcommon.Timestamp, errs scrapererror.ScrapeErrors) { | ||||||
func (s *snowflakeMetricsScraper) scrapeBillingMetrics(ctx context.Context, t pcommon.Timestamp, errs chan<- error) { | ||||||
billingMetrics, err := s.client.FetchBillingMetrics(ctx) | ||||||
|
||||||
if err != nil { | ||||||
errs.Add(err) | ||||||
errs <- err | ||||||
return | ||||||
} | ||||||
|
||||||
|
@@ -86,11 +129,11 @@ func (s *snowflakeMetricsScraper) scrapeBillingMetrics(ctx context.Context, t pc | |||||
} | ||||||
} | ||||||
|
||||||
func (s *snowflakeMetricsScraper) scrapeWarehouseBillingMetrics(ctx context.Context, t pcommon.Timestamp, errs scrapererror.ScrapeErrors) { | ||||||
func (s *snowflakeMetricsScraper) scrapeWarehouseBillingMetrics(ctx context.Context, t pcommon.Timestamp, errs chan<- error) { | ||||||
warehouseBillingMetrics, err := s.client.FetchWarehouseBillingMetrics(ctx) | ||||||
|
||||||
if err != nil { | ||||||
errs.Add(err) | ||||||
errs <- err | ||||||
return | ||||||
} | ||||||
|
||||||
|
@@ -101,11 +144,11 @@ func (s *snowflakeMetricsScraper) scrapeWarehouseBillingMetrics(ctx context.Cont | |||||
} | ||||||
} | ||||||
|
||||||
func (s *snowflakeMetricsScraper) scrapeLoginMetrics(ctx context.Context, t pcommon.Timestamp, errs scrapererror.ScrapeErrors) { | ||||||
func (s *snowflakeMetricsScraper) scrapeLoginMetrics(ctx context.Context, t pcommon.Timestamp, errs chan<- error) { | ||||||
loginMetrics, err := s.client.FetchLoginMetrics(ctx) | ||||||
|
||||||
if err != nil { | ||||||
errs.Add(err) | ||||||
errs <- err | ||||||
return | ||||||
} | ||||||
|
||||||
|
@@ -114,11 +157,11 @@ func (s *snowflakeMetricsScraper) scrapeLoginMetrics(ctx context.Context, t pcom | |||||
} | ||||||
} | ||||||
|
||||||
func (s *snowflakeMetricsScraper) scrapeHighLevelQueryMetrics(ctx context.Context, t pcommon.Timestamp, errs scrapererror.ScrapeErrors) { | ||||||
func (s *snowflakeMetricsScraper) scrapeHighLevelQueryMetrics(ctx context.Context, t pcommon.Timestamp, errs chan<- error) { | ||||||
highLevelQueryMetrics, err := s.client.FetchHighLevelQueryMetrics(ctx) | ||||||
|
||||||
if err != nil { | ||||||
errs.Add(err) | ||||||
errs <- err | ||||||
return | ||||||
} | ||||||
|
||||||
|
@@ -130,11 +173,11 @@ func (s *snowflakeMetricsScraper) scrapeHighLevelQueryMetrics(ctx context.Contex | |||||
} | ||||||
} | ||||||
|
||||||
func (s *snowflakeMetricsScraper) scrapeDBMetrics(ctx context.Context, t pcommon.Timestamp, errs scrapererror.ScrapeErrors) { | ||||||
func (s *snowflakeMetricsScraper) scrapeDBMetrics(ctx context.Context, t pcommon.Timestamp, errs chan<- error) { | ||||||
DBMetrics, err := s.client.FetchDbMetrics(ctx) | ||||||
|
||||||
if err != nil { | ||||||
errs.Add(err) | ||||||
errs <- err | ||||||
return | ||||||
} | ||||||
|
||||||
|
@@ -161,11 +204,11 @@ func (s *snowflakeMetricsScraper) scrapeDBMetrics(ctx context.Context, t pcommon | |||||
} | ||||||
} | ||||||
|
||||||
func (s *snowflakeMetricsScraper) scrapeSessionMetrics(ctx context.Context, t pcommon.Timestamp, errs scrapererror.ScrapeErrors) { | ||||||
func (s *snowflakeMetricsScraper) scrapeSessionMetrics(ctx context.Context, t pcommon.Timestamp, errs chan<- error) { | ||||||
sessionMetrics, err := s.client.FetchSessionMetrics(ctx) | ||||||
|
||||||
if err != nil { | ||||||
errs.Add(err) | ||||||
errs <- err | ||||||
return | ||||||
} | ||||||
|
||||||
|
@@ -174,11 +217,11 @@ func (s *snowflakeMetricsScraper) scrapeSessionMetrics(ctx context.Context, t pc | |||||
} | ||||||
} | ||||||
|
||||||
func (s *snowflakeMetricsScraper) scrapeSnowpipeMetrics(ctx context.Context, t pcommon.Timestamp, errs scrapererror.ScrapeErrors) { | ||||||
func (s *snowflakeMetricsScraper) scrapeSnowpipeMetrics(ctx context.Context, t pcommon.Timestamp, errs chan<- error) { | ||||||
snowpipeMetrics, err := s.client.FetchSnowpipeMetrics(ctx) | ||||||
|
||||||
if err != nil { | ||||||
errs.Add(err) | ||||||
errs <- err | ||||||
return | ||||||
} | ||||||
|
||||||
|
@@ -187,11 +230,11 @@ func (s *snowflakeMetricsScraper) scrapeSnowpipeMetrics(ctx context.Context, t p | |||||
} | ||||||
} | ||||||
|
||||||
func (s *snowflakeMetricsScraper) scrapeStorageMetrics(ctx context.Context, t pcommon.Timestamp, errs scrapererror.ScrapeErrors) { | ||||||
func (s *snowflakeMetricsScraper) scrapeStorageMetrics(ctx context.Context, t pcommon.Timestamp, errs chan<- error) { | ||||||
storageMetrics, err := s.client.FetchStorageMetrics(ctx) | ||||||
|
||||||
if err != nil { | ||||||
errs.Add(err) | ||||||
errs <- err | ||||||
return | ||||||
} | ||||||
|
||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to send nil to the channel, just close the
eQueue
instead.