Skip to content

Commit acc9c7f

Browse files
vmanomaly: support ui preset mode (#1539)
* vmanomaly: support ui preset mode * added changelog entry
1 parent b210a02 commit acc9c7f

File tree

10 files changed

+79
-11
lines changed

10 files changed

+79
-11
lines changed

api/operator/v1/vmanomaly_types.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@ type VMAnomalyMonitoringSpec struct {
218218
// VMAnomalyMonitoringPullSpec defines pull monitoring configuration
219219
// which is enabled by default and served at POD_IP:8490/metrics
220220
type VMAnomalyMonitoringPullSpec struct {
221-
// Addr changes listen addr, default is 0.0.0.0
222-
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
223221
// Port defines a port for metrics scrape
224222
Port string `json:"port"`
225223
}
@@ -365,7 +363,7 @@ func (cr *VMAnomaly) GetServiceScrape() *vmv1beta1.VMServiceScrapeSpec {
365363
return cr.Spec.ServiceScrapeSpec
366364
}
367365

368-
// Port returns port for accessing anomaly
366+
// Port returns port for accessing anomaly UI
369367
func (cr *VMAnomaly) Port() string {
370368
return cr.Spec.Port
371369
}

config/crd/overlay/crd.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21123,9 +21123,6 @@ spec:
2112321123
VMAnomalyMonitoringPullSpec defines pull monitoring configuration
2112421124
which is enabled by default and served at POD_IP:8490/metrics
2112521125
properties:
21126-
addr:
21127-
description: Addr changes listen addr, default is 0.0.0.0
21128-
type: string
2112921126
port:
2113021127
description: Port defines a port for metrics scrape
2113121128
type: string

docs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ aliases:
1616
* Dependency: [vmoperator](https://docs.victoriametrics.com/operator/): Updated default versions for VM apps to [v1.126.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.126.0) version
1717
* Dependency: [vmoperator](https://docs.victoriametrics.com/operator/): Updated default versions for VL apps to [v1.35.0](https://github.com/VictoriaMetrics/VictoriaLogs/releases/tag/v1.35.0).
1818

19+
* FEATURE: [vmanomaly](https://docs.victoriametrics.com/anomaly-detection/): support ui preset mode, support `vlogs` reader type. See [#1532](https://github.com/VictoriaMetrics/operator/issues/1538).
20+
1921
* BUGFIX: [vmoperator](https://docs.victoriametrics.com/operator/): fix an issue where the return value from a couple of controllers was always `nil`. See [#1532](https://github.com/VictoriaMetrics/operator/pull/1532) for details.
2022

2123
## [v0.63.0](https://github.com/VictoriaMetrics/operator/releases/tag/v0.63.0)

internal/controller/operator/factory/build/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func addVMAnomalyDefaults(objI any) {
281281
if cr.Spec.Monitoring == nil {
282282
cr.Spec.Monitoring = &vmv1.VMAnomalyMonitoringSpec{
283283
Pull: &vmv1.VMAnomalyMonitoringPullSpec{
284-
Port: cr.Port(),
284+
Port: "8080",
285285
},
286286
}
287287
}

internal/controller/operator/factory/vmanomaly/config/config.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type config struct {
2929
Monitoring *monitoring `yaml:"monitoring,omitempty"`
3030
Preset string `yaml:"preset,omitempty"`
3131
Settings *settings `yaml:"settings,omitempty"`
32+
Server *server `yaml:"server,omitempty"`
3233
}
3334

3435
type settings struct {
@@ -38,6 +39,43 @@ type settings struct {
3839
}
3940

4041
func (c *config) override(cr *vmv1.VMAnomaly, ac *build.AssetsCache) error {
42+
c.Preset = strings.ToLower(c.Preset)
43+
if strings.HasPrefix(c.Preset, "ui:") {
44+
c.Reader = &reader{
45+
Class: "noop",
46+
}
47+
c.Writer = &writer{
48+
Class: "noop",
49+
}
50+
c.Schedulers = map[string]*scheduler{
51+
"noop": {
52+
validatable: &noopScheduler{
53+
Class: "noop",
54+
},
55+
},
56+
}
57+
c.Models = map[string]*model{
58+
"placeholder": {
59+
anomalyModel: &zScoreModel{
60+
commonModelParams: commonModelParams{
61+
Class: "zscore",
62+
Schedulers: []string{"noop"},
63+
},
64+
},
65+
},
66+
}
67+
c.Server = &server{
68+
Addr: "0.0.0.0",
69+
Port: cr.Port(),
70+
}
71+
c.Monitoring = &monitoring{
72+
Pull: &server{
73+
Addr: "0.0.0.0",
74+
Port: cr.Spec.Monitoring.Pull.Port,
75+
},
76+
}
77+
return nil
78+
}
4179
if cr.Spec.Reader == nil {
4280
return fmt.Errorf("reader is required for anomaly name=%s/%s", cr.Namespace, cr.Name)
4381
}
@@ -172,6 +210,12 @@ func (c *config) marshal() yaml.MapSlice {
172210
if c.Settings != nil {
173211
output = append(output, yaml.MapItem{Key: "settings", Value: c.Settings})
174212
}
213+
if c.Server != nil {
214+
output = append(output, yaml.MapItem{Key: "server", Value: c.Server})
215+
}
216+
if c.Preset != "" {
217+
output = append(output, yaml.MapItem{Key: "preset", Value: c.Preset})
218+
}
175219
return output
176220
}
177221

internal/controller/operator/factory/vmanomaly/config/monitoring.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package config
22

33
type monitoring struct {
4-
Pull *pullMonitoring `yaml:"pull,omitempty"`
4+
Pull *server `yaml:"pull,omitempty"`
55
Push *pushMonitoring `yaml:"push,omitempty"`
66
}
77

88
func (m *monitoring) validate() error {
99
return nil
1010
}
1111

12-
type pullMonitoring struct {
12+
type server struct {
1313
Addr string `yaml:"addr,omitempty"`
1414
Port string `yaml:"port,omitempty"`
1515
}

internal/controller/operator/factory/vmanomaly/config/readers.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package config
22

33
import (
44
"fmt"
5+
"slices"
56
"strconv"
7+
"strings"
68
"time"
79
)
810

@@ -22,7 +24,10 @@ type reader struct {
2224
}
2325

2426
func (r *reader) validate() error {
25-
if r.Class != "reader.vm.VmReader" && r.Class != "vm" && r.Class != "reader.synthetic.SyntheticVmReader" && r.Class != "synthetic_vm" {
27+
if strings.ToLower(r.Class) == "noop" {
28+
return nil
29+
}
30+
if !slices.Contains([]string{"reader.vm.VmReader", "vm", "reader.synthetic.SyntheticVmReader", "synthetic_vm", "vlogs", "reader.vlogs.VLogsReader"}, r.Class) {
2631
return fmt.Errorf("anomaly reader class=%q is not supported", r.Class)
2732
}
2833
if len(r.Queries) == 0 {

internal/controller/operator/factory/vmanomaly/config/schedulers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ func (s *scheduler) MarshalYAML() (any, error) {
4545
return s.validatable, nil
4646
}
4747

48+
type noopScheduler struct {
49+
Class string `yaml:"class"`
50+
}
51+
52+
func (s *noopScheduler) validate() error {
53+
return nil
54+
}
55+
4856
type periodicScheduler struct {
4957
Class string `yaml:"class"`
5058
FitEvery *duration `yaml:"fit_every,omitempty"`

internal/controller/operator/factory/vmanomaly/config/writers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"fmt"
5+
"slices"
56
"strings"
67
)
78

@@ -14,7 +15,10 @@ type writer struct {
1415
}
1516

1617
func (w *writer) validate() error {
17-
if w.Class != "writer.vm.VmReader" && w.Class != "vm" {
18+
if strings.ToLower(w.Class) == "noop" {
19+
return nil
20+
}
21+
if !slices.Contains([]string{"writer.vm.VmWriter", "vm"}, w.Class) {
1822
return fmt.Errorf("anomaly writer class=%q is not supported", w.Class)
1923
}
2024
if w.MetricFormat != nil {

internal/controller/operator/factory/vmanomaly/pod.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,22 @@ func newPodSpec(cr *vmv1.VMAnomaly, ac *build.AssetsCache) (*corev1.PodSpec, err
4040
args = append(args, fmt.Sprintf("--loggerLevel=%s", strings.ToUpper(cr.Spec.LogLevel)))
4141
}
4242

43+
monitoringPort, err := strconv.ParseInt(cr.Spec.Monitoring.Pull.Port, 10, 32)
44+
if err != nil {
45+
return nil, fmt.Errorf("cannot reconcile vmanomaly: failed to parse monitoring port: %w", err)
46+
}
47+
4348
ports := []corev1.ContainerPort{
4449
{
4550
Name: "http",
4651
ContainerPort: int32(port),
4752
Protocol: corev1.ProtocolTCP,
4853
},
54+
{
55+
Name: "monitoring-http",
56+
ContainerPort: int32(monitoringPort),
57+
Protocol: corev1.ProtocolTCP,
58+
},
4959
}
5060

5161
volumes := []corev1.Volume{

0 commit comments

Comments
 (0)