mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Performance: Add preallocation for some slices (#59593)
This commit is contained in:
parent
8bda8b8272
commit
90badc8729
@ -1,6 +1,7 @@
|
||||
package conditions
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
@ -10,8 +11,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/tsdb/legacydata/interval"
|
||||
"github.com/grafana/grafana/pkg/tsdb/prometheus"
|
||||
|
||||
gocontext "context"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/null"
|
||||
@ -61,7 +60,7 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext, requestHandler lega
|
||||
// matches represents all the series that violate the alert condition
|
||||
var matches []*alerting.EvalMatch
|
||||
// allMatches capture all evaluation matches irregardless on whether the condition is met or not
|
||||
var allMatches []*alerting.EvalMatch
|
||||
allMatches := make([]*alerting.EvalMatch, 0, len(seriesList))
|
||||
|
||||
for _, series := range seriesList {
|
||||
reducedValue := c.Reducer.Reduce(series)
|
||||
|
@ -144,6 +144,7 @@ func (gcn *GoogleChatNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
}
|
||||
|
||||
// add a text paragraph widget for the fields
|
||||
//nolint:prealloc // break block
|
||||
var fields []textParagraphWidget
|
||||
fieldLimitCount := 4
|
||||
for index, evt := range evalContext.EvalMatches {
|
||||
|
@ -110,7 +110,7 @@ func (auth *AuthProxy) IsAllowedIP(ip string) error {
|
||||
}
|
||||
|
||||
proxies := strings.Split(auth.cfg.AuthProxyWhitelist, ",")
|
||||
var proxyObjs []*net.IPNet
|
||||
proxyObjs := make([]*net.IPNet, 0, len(proxies))
|
||||
for _, proxy := range proxies {
|
||||
result, err := coerceProxyAddress(proxy)
|
||||
if err != nil {
|
||||
|
@ -118,7 +118,7 @@ func (out *RemoteWriteFrameOutput) sample(timeSeries []prompb.TimeSeries) []prom
|
||||
sample.Samples = append(sample.Samples, filteredSamples...)
|
||||
samples[name] = sample
|
||||
}
|
||||
var toReturn []prompb.TimeSeries
|
||||
toReturn := make([]prompb.TimeSeries, 0, len(samples))
|
||||
for _, ts := range samples {
|
||||
toReturn = append(toReturn, ts)
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ func (f *StorageRuleBuilder) BuildRules(ctx context.Context, orgID int64) ([]*Li
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var rules []*LiveChannelRule
|
||||
rules := make([]*LiveChannelRule, 0, len(channelRules))
|
||||
|
||||
for _, ruleConfig := range channelRules {
|
||||
rule := &LiveChannelRule{
|
||||
|
@ -430,7 +430,7 @@ func (am *Alertmanager) applyConfig(cfg *apimodels.PostableUserConfig, rawConfig
|
||||
am.dispatcher = dispatch.NewDispatcher(am.alerts, am.route, routingStage, am.marker, am.timeoutFunc, &nilLimits{}, am.logger, am.dispatcherMetrics)
|
||||
|
||||
// Check which receivers are active and create the receiver stage.
|
||||
var receivers []*notify.Receiver
|
||||
receivers := make([]*notify.Receiver, 0, len(integrationsMap))
|
||||
activeReceivers := am.getActiveReceiversMap(am.route)
|
||||
for name := range integrationsMap {
|
||||
stage := am.createReceiverStage(name, integrationsMap[name], am.waitFunc, am.notificationLog)
|
||||
@ -479,7 +479,7 @@ func (am *Alertmanager) buildIntegrationsMap(receivers []*apimodels.PostableApiR
|
||||
|
||||
// buildReceiverIntegrations builds a list of integration notifiers off of a receiver config.
|
||||
func (am *Alertmanager) buildReceiverIntegrations(receiver *apimodels.PostableApiReceiver, tmpl *template.Template) ([]*notify.Integration, error) {
|
||||
var integrations []*notify.Integration
|
||||
integrations := make([]*notify.Integration, 0, len(receiver.GrafanaManagedReceivers))
|
||||
for i, r := range receiver.GrafanaManagedReceivers {
|
||||
n, err := am.buildReceiverIntegration(r, tmpl)
|
||||
if err != nil {
|
||||
|
@ -203,10 +203,10 @@ func (am *Alertmanager) GetReceivers(ctx context.Context) []apimodels.Receiver {
|
||||
am.reloadConfigMtx.RLock()
|
||||
defer am.reloadConfigMtx.RUnlock()
|
||||
|
||||
var apiReceivers []apimodels.Receiver
|
||||
apiReceivers := make([]apimodels.Receiver, 0, len(am.receivers))
|
||||
for _, rcv := range am.receivers {
|
||||
// Build integrations slice for each receiver.
|
||||
var integrations []*models.Integration
|
||||
integrations := make([]*models.Integration, 0, len(rcv.Integrations()))
|
||||
for _, integration := range rcv.Integrations() {
|
||||
name := integration.Name()
|
||||
sendResolved := integration.SendResolved()
|
||||
|
@ -222,7 +222,6 @@ func (c *cache) getAll(orgID int64) []*State {
|
||||
}
|
||||
|
||||
func (c *cache) getStatesForRuleUID(orgID int64, alertRuleUID string) []*State {
|
||||
var result []*State
|
||||
c.mtxStates.RLock()
|
||||
defer c.mtxStates.RUnlock()
|
||||
orgRules, ok := c.states[orgID]
|
||||
@ -233,6 +232,7 @@ func (c *cache) getStatesForRuleUID(orgID int64, alertRuleUID string) []*State {
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
result := make([]*State, 0, len(rs.states))
|
||||
for _, state := range rs.states {
|
||||
result = append(result, state)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user