-
-
Notifications
You must be signed in to change notification settings - Fork 740
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: handle aggregation queries sequentially follow up #8450
Merged
gastonfournier
merged 13 commits into
proposal/handle-aggregation-queries-sequentially
from
proposal/handle-aggregation-queries-sequentially-follow-up
Oct 18, 2024
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9bf5ed5
fix: move event listeners outside metric collection
gastonfournier 7b585f1
Migrate max_feature_environment_strategies
gastonfournier 8cda5cd
Migrate feature_toggles_total
gastonfournier e2cd347
Ability to execute a task immediately
gastonfournier 73f3559
Remove jitter and migrate tasks to execute immediately
gastonfournier 4806106
Add type for MetricValue
gastonfournier 05a338c
Get closer to prom-client types
gastonfournier f5cf84c
Renames to have gauge and task together
gastonfournier 5edd0f8
Split metric registration from refresh, use existing prometheus metri…
gastonfournier e7de20f
Instance stats should not rely on prometheus cause it can be disabled
gastonfournier e97f748
Replace removed method
gastonfournier add3bed
Add comment
gastonfournier 1a977fe
Move rate limits outside the refresh function as they're static
gastonfournier 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
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
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { register } from 'prom-client'; | ||
import { createTestConfig } from '../test/config/test-config'; | ||
import type { IUnleashConfig } from './types'; | ||
import { DbMetricsMonitor } from './metrics-gauge'; | ||
|
||
const prometheusRegister = register; | ||
let config: IUnleashConfig; | ||
let dbMetrics: DbMetricsMonitor; | ||
|
||
beforeAll(async () => { | ||
config = createTestConfig({ | ||
server: { | ||
serverMetrics: true, | ||
}, | ||
}); | ||
}); | ||
|
||
beforeEach(async () => { | ||
dbMetrics = new DbMetricsMonitor(config); | ||
}); | ||
|
||
test('should collect registered metrics', async () => { | ||
dbMetrics.registerGaugeDbMetric({ | ||
name: 'my_metric', | ||
help: 'This is the answer to life, the univers, and everything', | ||
labelNames: [], | ||
query: () => Promise.resolve(42), | ||
map: (result) => ({ value: result }), | ||
}); | ||
|
||
await dbMetrics.refreshDbMetrics(); | ||
|
||
const metrics = await prometheusRegister.metrics(); | ||
expect(metrics).toMatch(/my_metric 42/); | ||
}); | ||
|
||
test('should collect registered metrics with labels', async () => { | ||
dbMetrics.registerGaugeDbMetric({ | ||
name: 'life_the_universe_and_everything', | ||
help: 'This is the answer to life, the univers, and everything', | ||
labelNames: ['test'], | ||
query: () => Promise.resolve(42), | ||
map: (result) => ({ value: result, labels: { test: 'case' } }), | ||
}); | ||
|
||
await dbMetrics.refreshDbMetrics(); | ||
|
||
const metrics = await prometheusRegister.metrics(); | ||
expect(metrics).toMatch( | ||
/life_the_universe_and_everything\{test="case"\} 42/, | ||
); | ||
}); | ||
|
||
test('should collect multiple registered metrics with and without labels', async () => { | ||
dbMetrics.registerGaugeDbMetric({ | ||
name: 'my_first_metric', | ||
help: 'This is the answer to life, the univers, and everything', | ||
labelNames: [], | ||
query: () => Promise.resolve(42), | ||
map: (result) => ({ value: result }), | ||
}); | ||
|
||
dbMetrics.registerGaugeDbMetric({ | ||
name: 'my_other_metric', | ||
help: 'This is Eulers number', | ||
labelNames: ['euler'], | ||
query: () => Promise.resolve(Math.E), | ||
map: (result) => ({ value: result, labels: { euler: 'number' } }), | ||
}); | ||
|
||
await dbMetrics.refreshDbMetrics(); | ||
|
||
const metrics = await prometheusRegister.metrics(); | ||
expect(metrics).toMatch(/my_first_metric 42/); | ||
expect(metrics).toMatch(/my_other_metric\{euler="number"\} 2.71828/); | ||
}); | ||
|
||
test('should support different label and value pairs', async () => { | ||
dbMetrics.registerGaugeDbMetric({ | ||
name: 'multi_dimensional', | ||
help: 'This metric has different values for different labels', | ||
labelNames: ['version', 'range'], | ||
query: () => Promise.resolve(2), | ||
map: (result) => [ | ||
{ value: result, labels: { version: '1', range: 'linear' } }, | ||
{ | ||
value: result * result, | ||
labels: { version: '2', range: 'square' }, | ||
}, | ||
{ value: result / 2, labels: { version: '3', range: 'half' } }, | ||
], | ||
}); | ||
|
||
await dbMetrics.refreshDbMetrics(); | ||
|
||
const metrics = await prometheusRegister.metrics(); | ||
expect(metrics).toMatch( | ||
/multi_dimensional\{version="1",range="linear"\} 2\nmulti_dimensional\{version="2",range="square"\} 4\nmulti_dimensional\{version="3",range="half"\} 1/, | ||
); | ||
expect( | ||
await dbMetrics.findValue('multi_dimensional', { range: 'linear' }), | ||
).toBe(2); | ||
expect( | ||
await dbMetrics.findValue('multi_dimensional', { range: 'half' }), | ||
).toBe(1); | ||
expect( | ||
await dbMetrics.findValue('multi_dimensional', { range: 'square' }), | ||
).toBe(4); | ||
expect( | ||
await dbMetrics.findValue('multi_dimensional', { range: 'x' }), | ||
).toBeUndefined(); | ||
expect(await dbMetrics.findValue('multi_dimensional')).toBe(2); // first match | ||
expect(await dbMetrics.findValue('other')).toBeUndefined(); | ||
}); |
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.
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.
Store the result, so it can be used internally (line 261)