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

feat: enable vector API #1433

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.22 as builder
FROM golang:1.22 AS builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ vector-test: ## Run vector tests
@echo Generating test files for Vector tests
$(eval TMP := $(shell mktemp -d))
VECTOR_TEST_FILES=true OUTPUT_PATH=$(TMP) go test -v ./pkg/telemetry -run=TestGenerateTomlTestFiles
VECTOR_TEST_FILES=false OUTPUT_PATH=$(TMP) go test -v ./pkg/telemetry -run=TestBuildCustomVectorTomlWithApiConfig
@echo Running vector test files
OUTPUT_PATH=$(TMP) VECTOR=$(VECTOR) scripts/run-vector-tests.sh
rm -rf $(TMP)
Expand Down
5 changes: 5 additions & 0 deletions apis/telemetry/v1alpha1/telemetry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ type VectorSpec struct {
ScrapeInterval *metav1.Duration `json:"scrapeInterval,omitempty"`

Components *VectorComponentsSpec `json:"components,omitempty"`
Api *ApiConfig `json:"api,omitempty"`
}

type ApiConfig struct {
Enabled *bool `json:"enabled,omitempty"`
}

type VectorComponentsSpec struct {
Expand Down
25 changes: 25 additions & 0 deletions apis/telemetry/v1alpha1/zz_generated.deepcopy.go

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

45 changes: 45 additions & 0 deletions charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13599,6 +13599,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -14144,6 +14149,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -16630,6 +16640,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -25536,6 +25551,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -29040,6 +29060,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -30803,6 +30828,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -35137,6 +35167,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -38523,6 +38558,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -39053,6 +39093,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down
30 changes: 30 additions & 0 deletions config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13537,6 +13537,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -14082,6 +14087,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -16568,6 +16578,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -25474,6 +25489,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -28978,6 +28998,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -30741,6 +30766,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/reaper.k8ssandra.io_reapers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2565,6 +2565,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/stargate.k8ssandra.io_stargates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down Expand Up @@ -3525,6 +3530,11 @@ spec:
type: object
vector:
properties:
api:
properties:
enabled:
type: boolean
type: object
components:
properties:
sinks:
Expand Down
6 changes: 6 additions & 0 deletions pkg/telemetry/vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ Clean:

func BuildCustomVectorToml(telemetrySpec *telemetry.TelemetrySpec) string {
vectorConfigToml := ""

if telemetrySpec.Vector.Api != nil && telemetrySpec.Vector.Api.Enabled != nil && *telemetrySpec.Vector.Api.Enabled {
vectorConfigToml += "[api]\n"
vectorConfigToml += "enabled = true\n"
}

for _, source := range telemetrySpec.Vector.Components.Sources {
vectorConfigToml += fmt.Sprintf("\n[sources.%s]\n", source.Name)
vectorConfigToml += fmt.Sprintf("type = \"%s\"\n", source.Type)
Expand Down
73 changes: 73 additions & 0 deletions pkg/telemetry/vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,76 @@ assert!(exists(.class))

assert.NoError(os.WriteFile(fmt.Sprintf("%s/vector-emptyline.toml", outputDir), []byte(b.String()), 0644))
}

func TestBuildCustomVectorTomlWithApiConfig(t *testing.T) {
tests := []struct {
name string
tspec *telemetry.TelemetrySpec
want string
}{
{
"API enabled",
&telemetry.TelemetrySpec{
Vector: &telemetry.VectorSpec{
Enabled: ptr.To(true),
Api: &telemetry.ApiConfig{
Enabled: ptr.To(true),
},
Components: &telemetry.VectorComponentsSpec{
Sinks: []telemetry.VectorSinkSpec{
{
Name: "console",
Type: "console",
Inputs: []string{
"test",
"test2",
},
},
},
},
},
},
`[api]
enabled = true

[sinks.console]
type = "console"
inputs = ["test", "test2"]
`,
},
{
"API disabled",
&telemetry.TelemetrySpec{
Vector: &telemetry.VectorSpec{
Enabled: ptr.To(true),
Api: &telemetry.ApiConfig{
Enabled: ptr.To(false),
},
Components: &telemetry.VectorComponentsSpec{
Sinks: []telemetry.VectorSinkSpec{
{
Name: "console",
Type: "console",
Inputs: []string{
"test",
"test2",
},
},
},
},
},
},
`
[sinks.console]
type = "console"
inputs = ["test", "test2"]
`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := BuildCustomVectorToml(tt.tspec)
assert.Equal(t, tt.want, got)
})
}
}
Loading