Skip to content
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

Bugfixes #1746

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,014 changes: 554 additions & 460 deletions internal/cortex/config/validation/limits.pb.go

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion internal/cortex/config/validation/limits.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import "github.com/rancher/opni/internal/codegen/cli/cli.proto";
import "google/protobuf/duration.proto";
option go_package = "github.com/rancher/opni/internal/cortex/config/validation";
option (cli.generator) = { generate: true, generate_deepcopy: true };
message DisabledRuleGroup {
// namespace in which the rule group belongs
optional string namespace = 1 [(cli.flag) = { skip: true }];
// name of the rule group
optional string name = 2 [(cli.flag) = { skip: true }];
}
message Limits {
// Per-user ingestion rate limit in samples per second.
optional double ingestion_rate = 1 [(cli.flag) = { default: "25000" }];
Expand Down Expand Up @@ -116,7 +122,7 @@ message Limits {
optional bool alertmanager_receivers_firewall_block_private_addresses = 54 [(cli.flag) = { default: "false" }];
// Per-user rate limit for sending notifications from Alertmanager in notifications/sec. 0 = rate limit disabled. Negative value = no notifications are allowed.
optional double alertmanager_notification_rate_limit = 55 [(cli.flag) = { default: "0" }];
// Per-integration notification rate limits. Value is a map, where each key is integration name and value is a rate-limit (float). On command line, this map is given in JSON format. Rate limit has the same meaning as -alertmanager.notification-rate-limit, but only applies for specific integration. Allowed integration names: webhook, email, pagerduty, opsgenie, wechat, slack, victorops, pushover, sns, telegram, discord, webex.
// Per-integration notification rate limits. Value is a map, where each key is integration name and value is a rate-limit (float). On command line, this map is given in JSON format. Rate limit has the same meaning as -alertmanager.notification-rate-limit, but only applies for specific integration. Allowed integration names: webhook, email, pagerduty, opsgenie, wechat, slack, victorops, pushover, sns, telegram, discord, webex, msteams.
map<string, double> alertmanager_notification_rate_limit_per_integration = 56 [(cli.flag) = { default: "{}" }];
// Maximum size of configuration file for Alertmanager that tenant can upload via Alertmanager API. 0 = no limit.
optional int32 alertmanager_max_config_size_bytes = 57 [(cli.flag) = { default: "0" }];
Expand All @@ -130,6 +136,8 @@ message Limits {
optional int32 alertmanager_max_alerts_count = 61 [(cli.flag) = { default: "0" }];
// Maximum total size of alerts that a single user can have, alert size is the sum of the bytes of its labels, annotations and generatorURL. Inserting more alerts will fail with a log message and metric increment. 0 = no limit.
optional int32 alertmanager_max_alerts_size_bytes = 62 [(cli.flag) = { default: "0" }];
// list of rule groups to disable
repeated DisabledRuleGroup disabled_rule_groups = 63 [(cli.flag) = { skip: true }];
}
message RelabelConfig {
repeated string source_labels = 1;
Expand Down
11 changes: 10 additions & 1 deletion internal/cortex/config/validation/limits_cli.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions pkg/clients/stats_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,9 @@ type ConnStats struct {
Raw unix.TCPInfo
}

// Computes the tx/rx throughput by comparing against a previous snapshot.
func (c *ConnStats) CalcThroughput(since ConnStats) (txRate uint64, rxRate uint64) {
dt := c.Timestamp.Sub(since.Timestamp).Seconds()
if dt <= 0 {
return 0, 0
}
dsent := (c.Raw.Bytes_sent - since.Raw.Bytes_sent)
drecvd := (c.Raw.Bytes_received - since.Raw.Bytes_received)
txRate = uint64(float64(dsent) / dt)
rxRate = uint64(float64(drecvd) / dt)
return
// Returns the socket throughput in bytes per second
func (c *ConnStats) DeliveryRate() uint64 {
return c.Raw.Delivery_rate
}

func (c *ConnStats) RTT() time.Duration {
Expand Down
13 changes: 4 additions & 9 deletions pkg/update/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func (conf SyncConfig) DoSync(ctx context.Context) error {
statsDone := make(chan struct{})
go func() {
defer close(statsDone)
var prevStats *clients.ConnStats
startTime := time.Now()
var printStats func(string)
if conf.StatsClient == nil {
Expand All @@ -60,24 +59,20 @@ func (conf SyncConfig) DoSync(ctx context.Context) error {
lg.With(zap.Error(err)).Warn("failed to query connection stats")
return
}
if prevStats == nil {
prevStats = &stats
return
rate, err := util.Humanize(stats.DeliveryRate())
if err != nil {
rate = "0"
}
_, rx := stats.CalcThroughput(*prevStats)
rxStr, _ := util.Humanize(rx)
recvdStr := stats.HumanizedBytesReceived()
elapsedTime := time.Since(startTime)
mins := elapsedTime / time.Minute
elapsedTime -= mins * time.Minute
secs := elapsedTime / time.Second
elapsedTime -= secs * time.Second
millis := elapsedTime / time.Millisecond
lg.Debugf("%s%s | %sB/s | %02d:%02d.%03d", msg, recvdStr, rxStr, mins, secs, millis)
prevStats = &stats
lg.Debugf("%s%sB | %sB/s | %02d:%02d.%03d", msg, recvdStr, rate, mins, secs, millis)
}
}
printStats("")
for {
select {
case <-ticker.C:
Expand Down
22 changes: 21 additions & 1 deletion plugins/metrics/apis/cortexops/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,27 @@ func init() {

for _, preset := range presets.Items {
if preset.GetId().GetId() == fromPreset {
_, err := client.SetConfiguration(cmd.Context(), preset.GetSpec())
spec := preset.GetSpec()
if cmd.Flags().Lookup("interactive").Value.String() == "true" {
drr, err := client.DryRun(cmd.Context(), &DryRunRequest{
Target: driverutil.Target_ActiveConfiguration,
Action: driverutil.Action_Set,
Spec: spec,
})
if err != nil {
return err
}
modified := drr.GetModified()
comments := []string{}
for _, err := range drr.GetValidationErrors() {
comments = append(comments, err.GetMessage())
}
if modified, err = cliutil.EditInteractive(modified, comments...); err != nil {
return err
}
spec = modified
}
_, err := client.SetConfiguration(cmd.Context(), spec)
return err
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ func (methods) FillConfigFromObject(obj *opnicorev1beta1.MonitoringCluster, conf
}

// FillObjectFromConfig implements crds.ValueStoreMethods.
func (methods) FillObjectFromConfig(obj *opnicorev1beta1.MonitoringCluster, conf *cortexops.CapabilityBackendConfigSpec) {
func (m methods) FillObjectFromConfig(obj *opnicorev1beta1.MonitoringCluster, conf *cortexops.CapabilityBackendConfigSpec) {
obj.Spec.Cortex.Enabled = conf.Enabled
obj.Spec.Cortex.CortexConfig = conf.CortexConfig
obj.Spec.Cortex.CortexWorkloads = conf.CortexWorkloads
obj.Spec.Grafana.GrafanaConfig = conf.Grafana
obj.Spec.Gateway.Name = m.controllerRef.GetName()
}

func NewOpniManagerClusterDriver(options OpniManagerClusterDriverOptions) (*OpniManager, error) {
Expand Down