-
-
Notifications
You must be signed in to change notification settings - Fork 98
feat: Provide support for batch scraping #2459
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
Merged
tomkerkhove
merged 136 commits into
tomkerkhove:master
from
hkfgo:feat/enable-batch-scraping
Oct 7, 2024
Merged
Changes from 116 commits
Commits
Show all changes
136 commits
Select commit
Hold shift + click to select a range
163713d
define batch scrape definition model
hkfgo d0f4c73
implement skeleton batch scraping flow
hkfgo 2552197
complete mapping logic between YAML and scraper domain
hkfgo 975eef7
start grouping logic implementation via compound keys
hkfgo 40289da
flesh out definiion batching logic
hkfgo e9e385a
implement scraper batch function + hashcode/equals for grouping
hkfgo d6fe4ff
implement scraper batch function + hashcode/equals for grouping
hkfgo 55b88f9
Merge branch 'master' into feat/enable-batch-scraping
tomkerkhove 6647ef1
github action image build
hkfgo 77640a7
github action image build
hkfgo 3b4ce25
Merge branch 'master' into feat/enable-batch-scraping
tomkerkhove 9e7c0cd
code batch query client initialization
hkfgo c9bd29b
refactor resource query subroutines as extension methods
hkfgo 43882d6
refactor single resource query subroutine as extension
hkfgo ff14367
code batch query execution and result processing
hkfgo 3e3ef54
make some compile errors go away
hkfgo e290f90
make some compile errors go away
hkfgo c7a3fff
record batch size as histogram metric
hkfgo f35fce4
restrict batch scraping to only Azure Monitor scraper for now + defin…
hkfgo e8cf5e1
return resource ID tagged measure metrics in scrape path
hkfgo 10f1599
cache resource info and use cache for hydration
hkfgo a5966fa
obtain testable build
hkfgo 83761b2
unit test batch property hashcode and equality implementations
hkfgo 94120b5
fix bug in MetricConfiguration to unique string implementation
hkfgo ca59552
move resource batching routines as separate static class
hkfgo 106bfbd
unit test scrape definition batching logic
hkfgo cad0752
Move batching to runtime configuration
hkfgo 30b535f
fix test
hkfgo 963b71a
configure CI to do batch scraping
hkfgo e1a8365
add logging
hkfgo a93f065
add logging
hkfgo 4342ae2
add logging on scraper
hkfgo 6b0dcbb
add logging on scraper
hkfgo f773058
add logging on scraper
hkfgo c3aa159
log exception details
hkfgo 3539362
add more logging on query tasks
hkfgo 3cc8359
make region configurable
hkfgo 7a8fc27
try fixing regional metrics URL
hkfgo bb71f0d
fix batch API URL formatting
hkfgo c79750d
fix batch API URL formatting
hkfgo 5a1fc33
debug query range
hkfgo be7b18b
use different time range instantiation
hkfgo a58318f
use different time range instantiation
hkfgo 187459c
lower case aggregations
hkfgo fdabad9
do not use size when filter not present
hkfgo b2cfd79
log filter
hkfgo dd9d248
log more query params
hkfgo a90bf15
log outgoing requests
hkfgo f2d51f2
try without time range first, because Azure SDK is buggy :(
hkfgo 6406cbe
log ID resposne
hkfgo be8638c
try new regex for resource ID parsing
hkfgo 3e8e095
process metrics results as IGroup
hkfgo 694a856
log resource definition cache
hkfgo 63d9a03
log resource definition cache
hkfgo 71fb195
log individual resource definitions
hkfgo f02eaaa
fill out cached resource definitions
hkfgo 6a0d2bf
fix fix
hkfgo 78bf03c
correct aggregation interval processing
hkfgo 7e583a9
try range query again
hkfgo 802a9d2
try modify date range on outgoing requests
hkfgo b26c9aa
try modify date range on outgoing requests
hkfgo e85c255
try modify date range on outgoing requests
hkfgo 0dba964
try modify date range on outgoing requests
hkfgo 604ad76
run single resource scraping for comparison
hkfgo 5b0b4cd
run single resource scraping for comparison
hkfgo cb1b696
go back to batch scraping CI
hkfgo 834819d
create GitHub Action to build image under personal account(will revert)
hkfgo a3410b8
implement LogAnalytics batch scraping by composing single-resource sc…
hkfgo 70e4a3f
fix bug writing histogram as gauge
hkfgo de785df
don't throw in OpenTelemetry sink
hkfgo 0b463e7
don't throw in OpenTelemetry sink
hkfgo 082a6e6
set better buckets for batch size
hkfgo beab4e6
correct logic to determine LogAnalytics aggregation interval
hkfgo 6c721ab
add more debug logging
hkfgo 5d8b5ef
handle single dimension in batching logic
hkfgo fc0362d
account for limit
hkfgo 4dff71b
add debug logging for resource ID metrics
hkfgo cbc7e06
add forward slash in front of resource ID
hkfgo 30aa153
improve regex matching
hkfgo 2a42416
Merge branch 'master' into feat/enable-batch-scraping
hkfgo b77903d
add more debug logging
hkfgo a2da4a5
use configured max batch size
hkfgo 124acbc
use cached resource definition
hkfgo c5fd2be
go back
hkfgo 51e589f
go back
hkfgo 3760629
use an older collector version
hkfgo 4853b3e
use different string matching
hkfgo e2a013f
run prom exporter on localhost
hkfgo c29399a
try insecure flag
hkfgo 027254b
fix style issues
hkfgo d0c7b41
use associated resource definition during processing
hkfgo 46931e8
don't use resource-specific filters
hkfgo d4a0545
Merge branch 'master' into feat/enable-batch-scraping
tomkerkhove 8a0e380
Merge branch 'master' into feat/enable-batch-scraping
tomkerkhove d88c53b
fix style issues
hkfgo a853c26
fix style
hkfgo 430c725
Address comments
hkfgo 11d765c
more style fixes
hkfgo 5d38684
consolidate some logging
hkfgo b3eb049
more style fixes :(
hkfgo 9073887
add null check
hkfgo e1c96b1
avoid naming collision
hkfgo 172cd33
fix fix style
hkfgo 299ec6e
make config settable
hkfgo b2d3458
get rid of some redundant code
hkfgo 47672d6
Fighting resharper
hkfgo 06e404d
Fighting resharper
hkfgo af638b0
add null check
hkfgo 4573300
add null check
hkfgo 9f25804
add simple unit test
hkfgo 943e437
Revert CI workflow changes
hkfgo 88f43cc
get rid of excessive logging
hkfgo c790b54
add a link to docs
hkfgo ce56dbb
close ref
hkfgo 04ff115
do not initialize batch client under single-resource scraping
hkfgo 31669c5
handle windows time
hkfgo b82b73d
(temporary) change GitHub action to build another Linux image
hkfgo c4b1041
revert back GitHub Action chagnes
hkfgo fa2fc3f
ci changes
hkfgo 216812b
add logging
hkfgo c7a4a6a
add logging
hkfgo e27d581
add logging
hkfgo f1a2c48
add logging
hkfgo c72bda1
disable ReSharper when modifying outgoing URL
hkfgo 206e155
remove some more logging + add null checks
hkfgo 67bf0a5
remove some more logging + add null checks
hkfgo f04cb87
remove some more logging + add null checks
hkfgo 377bdfd
remove some more logging + add null checks
hkfgo 431f37d
remove some more logging + add null checks
hkfgo 86b4ddd
do not run batch mode in CI
hkfgo eb6d676
trigger CI again
hkfgo f2e0087
Modify workflow file again
hkfgo fedf814
revert GitHubaction
hkfgo 988da9b
remove more debug logging
hkfgo fd14f63
retry-ci
hkfgo 1face30
retry-ci
hkfgo 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
39 changes: 39 additions & 0 deletions
39
src/Promitor.Core.Scraping/Batching/AzureResourceDefinitionBatching.cs
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Promitor.Core.Contracts; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics; | ||
|
||
namespace Promitor.Core.Scraping.Batching | ||
{ | ||
public static class AzureResourceDefinitionBatching | ||
{ | ||
/// <summary> | ||
/// groups scrape definitions based on following conditions: | ||
/// 1. Definitions in a batch must target the same resource type | ||
/// 2. Definitions in a batch must target the same Azure metric with identical dimensions | ||
/// 3. Definitions in a batch must have the same time granularity | ||
/// 4. Batch size cannot exceed configured maximum | ||
/// <see href="https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/migrate-to-batch-api?tabs=individual-response#batching-restrictions"/> | ||
/// </summary> | ||
public static List<BatchScrapeDefinition<IAzureResourceDefinition>> GroupScrapeDefinitions(IEnumerable<ScrapeDefinition<IAzureResourceDefinition>> allScrapeDefinitions, int maxBatchSize) | ||
{ | ||
hkfgo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return allScrapeDefinitions.GroupBy(def => def.BuildScrapingBatchInfo()) | ||
.ToDictionary(group => group.Key, group => group.ToList()) // first pass to build batches that could exceed max | ||
.ToDictionary(group => group.Key, group => SplitScrapeDefinitionBatch(group.Value, maxBatchSize)) // split to right-sized batches | ||
.SelectMany(group => group.Value.Select(batch => new BatchScrapeDefinition<IAzureResourceDefinition>(group.Key, batch))) | ||
.ToList(); // flatten | ||
} | ||
|
||
/// <summary> | ||
/// splits the "raw" batch according to max batch size configured | ||
/// </summary> | ||
private static List<List<ScrapeDefinition<IAzureResourceDefinition>>> SplitScrapeDefinitionBatch(List<ScrapeDefinition<IAzureResourceDefinition>> batchToSplit, int maxBatchSize) | ||
{ | ||
hkfgo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int numNewGroups = ((batchToSplit.Count - 1) / maxBatchSize) + 1; | ||
|
||
return Enumerable.Range(0, numNewGroups) | ||
.Select(i => batchToSplit.Skip(i * maxBatchSize).Take(maxBatchSize).ToList()) | ||
.ToList(); | ||
} | ||
} | ||
} |
This file contains hidden or 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
39 changes: 39 additions & 0 deletions
39
src/Promitor.Core.Scraping/Configuration/Model/Metrics/BatchScrapeDefinition.cs
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections.Generic; | ||
using GuardNet; | ||
using Promitor.Core.Contracts; | ||
|
||
namespace Promitor.Core.Scraping.Configuration.Model.Metrics | ||
{ | ||
/// <summary> | ||
/// Defines a batch of ScrapeDefinitions to be executed in a single request | ||
/// Scrape definitions within a batch should share | ||
/// 1. The same resource type | ||
/// 2. The same Azure metric scrape target with identical dimensions | ||
/// 3. The same time granularity | ||
/// 4. The same filters | ||
/// </summary> | ||
public class BatchScrapeDefinition<TResourceDefinition> where TResourceDefinition : class, IAzureResourceDefinition | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of the <see cref="BatchScrapeDefinition{TResourceDefinition}"/> class. | ||
/// </summary> | ||
/// <param name="scrapeDefinitionBatchProperties">Shared Properties Among ScrapeDefinition's in the batch</param> | ||
/// <param name="groupedScrapeDefinitions">Scape definitions in the batch</param> | ||
public BatchScrapeDefinition(ScrapeDefinitionBatchProperties scrapeDefinitionBatchProperties, List<ScrapeDefinition<TResourceDefinition>> groupedScrapeDefinitions) | ||
{ | ||
Guard.NotNull(groupedScrapeDefinitions, nameof(groupedScrapeDefinitions)); | ||
Guard.NotLessThan(groupedScrapeDefinitions.Count, 1, nameof(groupedScrapeDefinitions)); | ||
Guard.NotNull(scrapeDefinitionBatchProperties, nameof(scrapeDefinitionBatchProperties)); | ||
|
||
ScrapeDefinitionBatchProperties = scrapeDefinitionBatchProperties; | ||
ScrapeDefinitions = groupedScrapeDefinitions; | ||
} | ||
|
||
/// <summary> | ||
/// A batch of scrape job definitions to be executed as a single request | ||
/// </summary> | ||
public List<ScrapeDefinition<TResourceDefinition>> ScrapeDefinitions { get; set; } | ||
|
||
public ScrapeDefinitionBatchProperties ScrapeDefinitionBatchProperties { get; set; } | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.