-
Notifications
You must be signed in to change notification settings - Fork 160
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
Add Azure OpenAI mixin #1092
Draft
mshahzeb
wants to merge
6
commits into
master
Choose a base branch
from
shahzeb/add-azure-openai-mixin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add Azure OpenAI mixin #1092
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
00ab277
Add azure open AI mixin
mshahzeb 4d98e91
Update directory name
mshahzeb ff87ef8
Add alerts
mshahzeb 8439a3d
Remove unneeded annotations
mshahzeb 5baabe9
Merge branch 'master' into shahzeb/add-azure-openai-mixin
mshahzeb eb92ba1
Fix fmt
mshahzeb 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 |
---|---|---|
@@ -0,0 +1,166 @@ | ||
# Hello world observ lib | ||
|
||
This lib can be used as a starter template of modular observ lib. | ||
|
||
|
||
## Import | ||
|
||
```sh | ||
jb init | ||
jb install https://github.com/grafana/jsonnet-libs/helloworld-observ-lib | ||
``` | ||
|
||
## Modular observability lib format | ||
|
||
```jsonnet | ||
|
||
{ | ||
config: { | ||
//common options | ||
}, | ||
|
||
grafana: { | ||
|
||
// grafana templated variables to reuse across mutltiple dashboards | ||
variables: { | ||
datasources: { | ||
prometheus: {}, | ||
loki: {}, | ||
}, | ||
multiInstance: [], | ||
singleInstace: [], | ||
queriesSelector: "", | ||
}, | ||
|
||
// grafana targets (queries) to attach to panels | ||
targets: { | ||
target1: <target1>, | ||
target3: <target2>, | ||
... | ||
targetN: <targetN>, | ||
}, | ||
|
||
// grafana panels | ||
panels: { | ||
panel1: <panel1>, | ||
panel2: <panel2>, | ||
... | ||
panelN: <panelN>, | ||
}, | ||
|
||
// grafana dashboards | ||
dashboards: { | ||
dashboard1: <dashboard1>, | ||
dashboard2: <dashboard2>, | ||
... | ||
dashboardN: <dashboardN>, | ||
}, | ||
|
||
// grafana annotations | ||
annotations: { | ||
annotation1: <annotation1>, | ||
... | ||
}, | ||
|
||
// grafana dashboard links | ||
links: { | ||
//common dashobard links | ||
}, | ||
}, | ||
|
||
prometheus: { | ||
alerts: {}, | ||
rules: {}, | ||
}, | ||
} | ||
|
||
``` | ||
|
||
## Pros of using modular observabilty format | ||
|
||
- Uses (grafonnet)[https://monitoring.mixins.dev] | ||
- Highly customizable and flexible: | ||
|
||
Any object like `panel`, `target` (query) can be easily referenced by key and then overriden before output of the lib is provided by using jsonnet (patching)[https://tanka.dev/tutorial/environments#patching] technique: | ||
|
||
```jsonnet | ||
local helloworldlib = import './main.libsonnet'; | ||
|
||
local helloworld = | ||
helloworldlib.new( | ||
filteringSelector='job="integrations/helloworld"', | ||
uid='myhelloworld', | ||
groupLabels=['environment', 'cluster'], | ||
instanceLabels=['host'], | ||
) | ||
+ | ||
{ | ||
grafana+: { | ||
panels+: { | ||
panel1+: | ||
g.panel.timeSeries.withDescription("My new description for panel1") | ||
} | ||
} | ||
}; | ||
``` | ||
|
||
- Due to high decomposition level, not only dashboards but single panels can be imported ('cherry-picked) from the library to be used in other dashboards | ||
- Format introduces mandatory arguments that each library should have: `filteringSelector`, `instanceLabels`, `groupLabels`, `uid`. Proper use of those parameters ensures library can be used to instantiate multiple copies of the observability package in the same enviroment without `ids` conflicts or timeSeries overlapping. | ||
|
||
## Examples | ||
|
||
### Monitoring-Mixin example | ||
|
||
You can use lib to fill in [monitoring-mixin](https://monitoring.mixins.dev/) structure: | ||
|
||
```jsonnet | ||
// mixin.libsonnet file | ||
|
||
local helloworldlib = import './main.libsonnet'; | ||
|
||
local helloworld = | ||
helloworldlib.new( | ||
filteringSelector='job="integrations/helloworld"', | ||
uid='myhelloworld', | ||
groupLabels=['environment', 'cluster'], | ||
instanceLabels=['host'], | ||
); | ||
|
||
// populate monitoring-mixin: | ||
{ | ||
grafanaDashboards+:: helloworld.grafana.dashboards, | ||
prometheusAlerts+:: helloworld.prometheus.alerts, | ||
prometheusRules+:: helloworld.prometheus.recordingRules, | ||
} | ||
``` | ||
|
||
### Logs collection | ||
|
||
Grafana Loki is used to populate logs dashboard and also for quering annotations. | ||
|
||
To opt-out, you can set `enableLokiLogs: false` in config: | ||
|
||
``` | ||
local helloworldlib = import './main.libsonnet'; | ||
|
||
local helloworld = | ||
helloworldlib.new( | ||
filteringSelector='job="integrations/helloworld"', | ||
uid='myhelloworld', | ||
groupLabels=['environment', 'cluster'], | ||
instanceLabels=['host'], | ||
) | ||
+ helloworldlib.withConfigMixin( | ||
{ | ||
// disable loki logs | ||
enableLokiLogs: false, | ||
} | ||
); | ||
|
||
// populate monitoring-mixin: | ||
{ | ||
grafanaDashboards+:: helloworld.grafana.dashboards, | ||
prometheusAlerts+:: helloworld.prometheus.alerts, | ||
prometheusRules+:: helloworld.prometheus.recordingRules, | ||
} | ||
``` |
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,44 @@ | ||||||
{ | ||||||
new(this): { | ||||||
|
||||||
groups: [ | ||||||
{ | ||||||
name: 'alerts-' + this.config.uid, | ||||||
rules: [ | ||||||
{ | ||||||
alert: 'HighLatency', | ||||||
expr: ||| | ||||||
100 - (avg (rate(azure_microsoft_cognitiveservices_accounts_latency{%(filteringSelector)s}[5m])) * 100) > %(alertsThresholdLatency)s | ||||||
||| % this.config, | ||||||
'for': '5m', | ||||||
labels: { | ||||||
severity: 'warning', | ||||||
}, | ||||||
annotations: { | ||||||
summary: 'High latency for Azure OpenAI calls.', | ||||||
description: ||| | ||||||
Latency for Azure OpenAI calls on {{ $labels.resourceName }} is greater than %(alertsThresholdLatency)s%%. The currect value is {{ $value | printf "%%.2f" }}. | ||||||
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
|
||||||
||| % this.config, | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
alert: 'HighErrorRate', | ||||||
expr: ||| | ||||||
100 - (avg (rate(azure_microsoft_cognitiveservices_accounts_successrate_average_percent{%(filteringSelector)s}[5m])) * 100) > %(alertsThresholdErrorRate)s | ||||||
||| % this.config, | ||||||
'for': '5m', | ||||||
labels: { | ||||||
severity: 'warning', | ||||||
}, | ||||||
annotations: { | ||||||
summary: 'High error for Azure OpenAI calls.', | ||||||
description: ||| | ||||||
Error rate for Azure OpenAI calls on {{ $labels.resourceName }} is greater than %(alertsThresholdErrorRate)s%%. The currect value is {{ $value | printf "%%.2f" }}. | ||||||
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
|
||||||
||| % this.config, | ||||||
}, | ||||||
}, | ||||||
], | ||||||
}, | ||||||
], | ||||||
}, | ||||||
} |
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,11 @@ | ||
local commonlib = import 'common-lib/common/main.libsonnet'; | ||
|
||
{ | ||
new(this): | ||
local grafana = this.grafana; | ||
local instanceLabels = this.config.instanceLabels; | ||
local groupLabels = this.config.groupLabels; | ||
{ | ||
|
||
}, | ||
} |
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,57 @@ | ||
local g = import './g.libsonnet'; | ||
local logslib = import 'github.com/grafana/jsonnet-libs/logs-lib/logs/main.libsonnet'; | ||
{ | ||
local root = self, | ||
new(this): | ||
local prefix = this.config.dashboardNamePrefix; | ||
local links = this.grafana.links; | ||
local tags = this.config.dashboardTags; | ||
local uid = g.util.string.slugify(this.config.uid); | ||
local vars = this.grafana.variables; | ||
local annotations = this.grafana.annotations; | ||
local refresh = this.config.dashboardRefresh; | ||
local period = this.config.dashboardPeriod; | ||
local timezone = this.config.dashboardTimezone; | ||
local panels = this.grafana.panels; | ||
local stat = g.panel.stat; | ||
{ | ||
'azure-openai-overview.json': | ||
g.dashboard.new(prefix + 'Overview') | ||
+ g.dashboard.withPanels( | ||
g.util.grid.wrapPanels( | ||
[ | ||
g.panel.row.new('Overview'), | ||
panels.totalCalls, | ||
panels.successCalls, | ||
panels.successRate, | ||
panels.totalErrors, | ||
panels.errorsRate, | ||
g.panel.row.new('Tokens overview'), | ||
panels.generatedTokens, | ||
panels.tokenTransactions, | ||
panels.processedPromptTokens, | ||
panels.processedInferenceTokens, | ||
g.panel.row.new('Troubleshooting'), | ||
panels.rateLimitedCalls, | ||
panels.blockedCalls, | ||
panels.clientErrors, | ||
panels.fineTunedTrainingHours, | ||
panels.dataIn, | ||
panels.dataOut, | ||
], 4, 3 | ||
) | ||
) | ||
+ root.applyCommon(vars.singleInstance, uid + '-overview', tags, links { backToOverview+:: {} }, annotations, timezone, refresh, period), | ||
}, | ||
//Apply common options(uids, tags, annotations etc..) to all dashboards above | ||
applyCommon(vars, uid, tags, links, annotations, timezone, refresh, period): | ||
g.dashboard.withTags(tags) | ||
+ g.dashboard.withUid(uid) | ||
+ g.dashboard.withLinks(std.objectValues(links)) | ||
+ g.dashboard.withTimezone(timezone) | ||
+ g.dashboard.withRefresh(refresh) | ||
+ g.dashboard.time.withFrom(period) | ||
+ g.dashboard.withVariables(vars) | ||
+ g.dashboard.withAnnotations(std.objectValues(annotations)), | ||
|
||
} |
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 @@ | ||
import 'github.com/grafana/grafonnet/gen/grafonnet-v10.0.0/main.libsonnet' |
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,33 @@ | ||
{ | ||
"version": 1, | ||
"dependencies": [ | ||
{ | ||
"source": { | ||
"git": { | ||
"remote": "https://github.com/grafana/jsonnet-libs.git", | ||
"subdir": "common-lib" | ||
} | ||
}, | ||
"version": "master" | ||
}, | ||
{ | ||
"source": { | ||
"git": { | ||
"remote": "https://github.com/grafana/grafonnet.git", | ||
"subdir": "gen/grafonnet-v10.0.0" | ||
} | ||
}, | ||
"version": "main" | ||
}, | ||
{ | ||
"source": { | ||
"git": { | ||
"remote": "https://github.com/grafana/jsonnet-libs.git", | ||
"subdir": "logs-lib" | ||
} | ||
}, | ||
"version": "master" | ||
} | ||
], | ||
"legacyImports": true | ||
} |
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,61 @@ | ||
local alerts = import './alerts.libsonnet'; | ||
local annotations = import './annotations.libsonnet'; | ||
local dashboards = import './dashboards.libsonnet'; | ||
local datasources = import './datasources.libsonnet'; | ||
local g = import './g.libsonnet'; | ||
local panels = import './panels.libsonnet'; | ||
local targets = import './targets.libsonnet'; | ||
local variables = import './variables.libsonnet'; | ||
|
||
{ | ||
withConfigMixin(config): { | ||
config+: config, | ||
}, | ||
new( | ||
filteringSelector, | ||
groupLabels=['job'], | ||
instanceLabels=['instance'], | ||
dashboardNamePrefix='', | ||
dashboardTags=[uid], | ||
uid, | ||
): { | ||
|
||
local this = self, | ||
config: { | ||
groupLabels: groupLabels, | ||
instanceLabels: instanceLabels, | ||
filteringSelector: filteringSelector, | ||
dashboardTags: dashboardTags, | ||
uid: uid, | ||
dashboardNamePrefix: dashboardNamePrefix, | ||
|
||
// additional params can be added if needed | ||
criticalEvents: '90', | ||
alertsThresholdLatency: '10', | ||
alertsThresholdErrorRate: '5', | ||
dashboardPeriod: 'now-1h', | ||
dashboardTimezone: 'default', | ||
dashboardRefresh: '1m', | ||
}, | ||
|
||
grafana: { | ||
variables: variables.new(this, varMetric='azure_microsoft_cognitiveservices_accounts_totalcalls_total_count'), | ||
targets: targets.new(this), | ||
annotations: annotations.new(this), | ||
// common dashboards links here | ||
links: { | ||
}, | ||
|
||
panels: panels.new(this), | ||
dashboards: dashboards.new(this), | ||
|
||
}, | ||
|
||
prometheus: { | ||
alerts: alerts.new(this), | ||
recordingRules: {}, | ||
}, | ||
|
||
}, | ||
|
||
} |
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.
Consider to add prefix all alerts with some prefix like AzureOpenAI?