Skip to content

Commit d8757fe

Browse files
vlagent: support logs collection
1 parent c4f8482 commit d8757fe

File tree

16 files changed

+701
-32
lines changed

16 files changed

+701
-32
lines changed

api/operator/v1/vlagent_types.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ type VLAgentSpec struct {
7373
// +optional
7474
SyslogSpec *SyslogServerSpec `json:"syslogSpec,omitempty"`
7575

76+
// K8sCollector configures VLAgent logs collection from K8s pods
77+
K8sCollector VLAgentK8sCollector `json:"k8sCollector,omitempty"`
78+
7679
// ServiceAccountName is the name of the ServiceAccount to use to run the pods
7780
// +optional
7881
ServiceAccountName string `json:"serviceAccountName,omitempty"`
@@ -82,6 +85,38 @@ type VLAgentSpec struct {
8285
vmv1beta1.CommonApplicationDeploymentParams `json:",inline,omitempty"`
8386
}
8487

88+
type VLAgentK8sCollector struct {
89+
// Enabled switches VLAgent to log collection mode.
90+
// Note, for this purpose operator uses DaemonSet, while by default VLAgent uses StatefulSet.
91+
// It means that switching this option will drop all persisted data.
92+
Enabled bool `json:"enabled,omitempty"`
93+
94+
// LogsPath configures root for logs path
95+
// By default VLAgent collects logs from /var/log/containers
96+
LogsPath string `json:"logsPath,omitempty"`
97+
98+
// CheckpointsPath configures path where logs checkpoints are stored
99+
CheckpointsPath string `json:"checkpointsPath,omitempty"`
100+
101+
// TenantID defines default tenant ID to use for logs collected from pods in format: <accountID>:<projectID>
102+
TenantID string `json:"tenantID,omitempty"`
103+
104+
// IgnoreFields defines fields to ignore across logs ingested from Kubernetes
105+
IgnoreFields []string `json:"ignoreFields,omitempty"`
106+
107+
// DecolorizeFields defines fields to remove ANSI color codes across logs ingested from Kubernetes
108+
DecolorizeFields []string `json:"decolorizeFields,omitempty"`
109+
110+
// MsgField defines fields that may contain the _msg field
111+
MsgFields []string `json:"msgFields,omitempty"`
112+
113+
// TimeFields defines fields that may contain the _time field
114+
TimeFields []string `json:"timeFields,omitempty"`
115+
116+
// ExtraFields defines extra fields to add to each collected log line
117+
ExtraFields string `json:"extraFields,omitempty"`
118+
}
119+
85120
// SetLastSpec implements objectWithLastAppliedState interface
86121
func (cr *VLAgent) SetLastSpec(prevSpec VLAgentSpec) {
87122
cr.ParsedLastAppliedSpec = &prevSpec
@@ -298,6 +333,11 @@ func (cr *VLAgent) FinalAnnotations() map[string]string {
298333
return v
299334
}
300335

336+
// AsCRDOwner implements interface
337+
func (*VLAgent) AsCRDOwner() []metav1.OwnerReference {
338+
return vmv1beta1.GetCRDAsOwner(vmv1beta1.VLAgentCRD)
339+
}
340+
301341
// SelectorLabels returns selector labels for querying any vlagent related resources
302342
func (cr *VLAgent) SelectorLabels() map[string]string {
303343
return map[string]string{
@@ -402,6 +442,10 @@ func (cr *VLAgent) ProbePort() string {
402442
return cr.Spec.Port
403443
}
404444

445+
func (cr *VLAgent) GetClusterRoleName() string {
446+
return fmt.Sprintf("monitoring:%s:vlagent-%s", cr.Namespace, cr.Name)
447+
}
448+
405449
// ProbeNeedLiveness implements build.probeCRD interface
406450
func (*VLAgent) ProbeNeedLiveness() bool {
407451
return true

api/operator/v1/zz_generated.deepcopy.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/operator/v1beta1/owner.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
type CRDName int
1414

1515
const (
16-
Agent CRDName = iota
16+
VMAgentCRD CRDName = iota
17+
VLAgentCRD
1718
)
1819

1920
func (c CRDName) String() string {
@@ -39,7 +40,9 @@ func Init(ctx context.Context, rclient client.Client) error {
3940
var n CRDName
4041
switch item.Name {
4142
case "vmagents.operator.victoriametrics.com":
42-
n = Agent
43+
n = VMAgentCRD
44+
case "vlagents.operator.victoriametrics.com":
45+
n = VLAgentCRD
4346
default:
4447
continue
4548
}

api/operator/v1beta1/vmagent_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ func (cr *VMAgent) AsURL() string {
788788

789789
// AsCRDOwner implements interface
790790
func (*VMAgent) AsCRDOwner() []metav1.OwnerReference {
791-
return GetCRDAsOwner(Agent)
791+
return GetCRDAsOwner(VMAgentCRD)
792792
}
793793

794794
func (cr *VMAgent) Probe() *EmbeddedProbes {

config/crd/overlay/crd.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,58 @@ spec:
736736
type: object
737737
x-kubernetes-preserve-unknown-fields: true
738738
type: array
739+
k8sCollector:
740+
description: K8sCollector configures VLAgent logs collection from
741+
K8s pods
742+
properties:
743+
checkpointsPath:
744+
description: CheckpointsPath configures path where logs checkpoints
745+
are stored
746+
type: string
747+
decolorizeFields:
748+
description: DecolorizeFields defines fields to remove ANSI color
749+
codes across logs ingested from Kubernetes
750+
items:
751+
type: string
752+
type: array
753+
enabled:
754+
description: |-
755+
Enabled switches VLAgent to log collection mode.
756+
Note, for this purpose operator uses DaemonSet, while by default VLAgent uses StatefulSet.
757+
It means that switching this option will drop all persisted data.
758+
type: boolean
759+
extraFields:
760+
description: ExtraFields defines extra fields to add to each collected
761+
log line
762+
type: string
763+
ignoreFields:
764+
description: IgnoreFields defines fields to ignore across logs
765+
ingested from Kubernetes
766+
items:
767+
type: string
768+
type: array
769+
logsPath:
770+
description: |-
771+
LogsPath configures root for logs path
772+
By default VLAgent collects logs from /var/log/containers
773+
type: string
774+
msgFields:
775+
description: MsgField defines fields that may contain the _msg
776+
field
777+
items:
778+
type: string
779+
type: array
780+
tenantID:
781+
description: 'TenantID defines default tenant ID to use for logs
782+
collected from pods in format: <accountID>:<projectID>'
783+
type: string
784+
timeFields:
785+
description: TimeFields defines fields that may contain the _time
786+
field
787+
items:
788+
type: string
789+
type: array
790+
type: object
739791
livenessProbe:
740792
description: LivenessProbe that will be added CRD pod
741793
type: object
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: operator.victoriametrics.com/v1
2+
kind: VLAgent
3+
metadata:
4+
name: example
5+
spec:
6+
replicaCount: 2
7+
resources:
8+
requests:
9+
cpu: "50m"
10+
memory: "350Mi"
11+
limits:
12+
cpu: "500m"
13+
memory: "850Mi"
14+
persistentVolumeClaimRetentionPolicy:
15+
whenDeleted: Delete
16+
k8sCollector:
17+
enabled: true
18+
remoteWrite:
19+
- url: "http://vlsingle-example-0.default.svc:9428/internal/insert"
20+
maxDiskUsage: 10GB
21+
remoteWriteSettings:
22+
# ~ 5GB in bytes
23+
maxBlockSize: 30MB

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ aliases:
1414
## tip
1515

1616
* FEATURE: [vmagent](https://docs.victoriametrics.com/operator/resources/vmagent/): support `namespace` parameter in `attach_metadata` section for all scrape configurations. See [#1654](https://github.com/VictoriaMetrics/operator/issues/1654).
17+
* FEATURE: [vlagen](https://docs.victoriametrics.com/operator/resources/vlagent): support logs collection. See [#1501](https://github.com/VictoriaMetrics/operator/issues/1501).
1718

1819
## [v0.66.1](https://github.com/VictoriaMetrics/operator/releases/tag/v0.66.1)
1920

docs/api.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ VLAgent - is a tiny but brave agent, which helps you collect logs from various s
170170
| spec<a href="#vlagent-spec" id="vlagent-spec">#</a><br/>_[VLAgentSpec](#vlagentspec)_ | _(Required)_<br/> |
171171

172172

173+
#### VLAgentK8sCollector
174+
175+
176+
177+
178+
179+
Appears in: [VLAgentSpec](#vlagentspec)
180+
181+
| Field | Description |
182+
| --- | --- |
183+
| checkpointsPath<a href="#vlagentk8scollector-checkpointspath" id="vlagentk8scollector-checkpointspath">#</a><br/>_string_ | _(Required)_<br/>CheckpointsPath configures path where logs checkpoints are stored |
184+
| decolorizeFields<a href="#vlagentk8scollector-decolorizefields" id="vlagentk8scollector-decolorizefields">#</a><br/>_string array_ | _(Required)_<br/>DecolorizeFields defines fields to remove ANSI color codes across logs ingested from Kubernetes |
185+
| enabled<a href="#vlagentk8scollector-enabled" id="vlagentk8scollector-enabled">#</a><br/>_boolean_ | _(Required)_<br/>Enabled switches VLAgent to log collection mode.<br />Note, for this purpose operator uses DaemonSet, while by default VLAgent uses StatefulSet.<br />It means that switching this option will drop all persisted data. |
186+
| extraFields<a href="#vlagentk8scollector-extrafields" id="vlagentk8scollector-extrafields">#</a><br/>_string_ | _(Required)_<br/>ExtraFields defines extra fields to add to each collected log line |
187+
| ignoreFields<a href="#vlagentk8scollector-ignorefields" id="vlagentk8scollector-ignorefields">#</a><br/>_string array_ | _(Required)_<br/>IgnoreFields defines fields to ignore across logs ingested from Kubernetes |
188+
| logsPath<a href="#vlagentk8scollector-logspath" id="vlagentk8scollector-logspath">#</a><br/>_string_ | _(Required)_<br/>LogsPath configures root for logs path<br />By default VLAgent collects logs from /var/log/containers |
189+
| msgFields<a href="#vlagentk8scollector-msgfields" id="vlagentk8scollector-msgfields">#</a><br/>_string array_ | _(Required)_<br/>MsgField defines fields that may contain the _msg field |
190+
| tenantID<a href="#vlagentk8scollector-tenantid" id="vlagentk8scollector-tenantid">#</a><br/>_string_ | _(Required)_<br/>TenantID defines default tenant ID to use for logs collected from pods in format: <accountID>:<projectID> |
191+
| timeFields<a href="#vlagentk8scollector-timefields" id="vlagentk8scollector-timefields">#</a><br/>_string array_ | _(Required)_<br/>TimeFields defines fields that may contain the _time field |
192+
193+
173194
#### VLAgentRemoteWriteSettings
174195

175196

@@ -236,6 +257,7 @@ Appears in: [VLAgent](#vlagent)
236257
| image<a href="#vlagentspec-image" id="vlagentspec-image">#</a><br/>_[Image](#image)_ | _(Optional)_<br/>Image - docker image settings<br />if no specified operator uses default version from operator config |
237258
| imagePullSecrets<a href="#vlagentspec-imagepullsecrets" id="vlagentspec-imagepullsecrets">#</a><br/>_[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#localobjectreference-v1-core) array_ | _(Optional)_<br/>ImagePullSecrets An optional list of references to secrets in the same namespace<br />to use for pulling images from registries<br />see https://kubernetes.io/docs/concepts/containers/images/#referring-to-an-imagepullsecrets-on-a-pod |
238259
| initContainers<a href="#vlagentspec-initcontainers" id="vlagentspec-initcontainers">#</a><br/>_[Container](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#container-v1-core) array_ | _(Optional)_<br/>InitContainers allows adding initContainers to the pod definition.<br />Any errors during the execution of an initContainer will lead to a restart of the Pod.<br />More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ |
260+
| k8sCollector<a href="#vlagentspec-k8scollector" id="vlagentspec-k8scollector">#</a><br/>_[VLAgentK8sCollector](#vlagentk8scollector)_ | _(Required)_<br/>K8sCollector configures VLAgent logs collection from K8s pods |
239261
| logFormat<a href="#vlagentspec-logformat" id="vlagentspec-logformat">#</a><br/>_string_ | _(Optional)_<br/>LogFormat for VLAgent to be configured with. |
240262
| logLevel<a href="#vlagentspec-loglevel" id="vlagentspec-loglevel">#</a><br/>_string_ | _(Optional)_<br/>LogLevel for VLAgent to be configured with.<br />INFO, WARN, ERROR, FATAL, PANIC |
241263
| managedMetadata<a href="#vlagentspec-managedmetadata" id="vlagentspec-managedmetadata">#</a><br/>_[ManagedObjectsMetadata](#managedobjectsmetadata)_ | _(Required)_<br/>ManagedMetadata defines metadata that will be added to the all objects<br />created by operator for the given CustomResource |

docs/env.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
| Environment variables |
22
| --- |
33
| VM_METRICS_VERSION: `v1.131.0` <a href="#variables-vm-metrics-version" id="variables-vm-metrics-version">#</a> |
4-
| VM_LOGS_VERSION: `v1.36.1` <a href="#variables-vm-logs-version" id="variables-vm-logs-version">#</a> |
4+
| VM_LOGS_VERSION: `v1.40.0` <a href="#variables-vm-logs-version" id="variables-vm-logs-version">#</a> |
55
| VM_ANOMALY_VERSION: `v1.26.1` <a href="#variables-vm-anomaly-version" id="variables-vm-anomaly-version">#</a> |
66
| VM_TRACES_VERSION: `v0.5.0` <a href="#variables-vm-traces-version" id="variables-vm-traces-version">#</a> |
77
| VM_OPERATOR_VERSION: `v0.65.0` <a href="#variables-vm-operator-version" id="variables-vm-operator-version">#</a> |

docs/resources/vlagent.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ then `VLAgent` pods will be created without resource requests and limits.
136136

137137
Also, you can specify requests without limits - in this case default values for limits will not be used.
138138

139+
## K8s logs collection
140+
141+
VLAgent supports collecting logs from K8s pods. To enable it it's required to set `spec.k8sCollector.enabled: true`.
142+
With this setting operator:
143+
- switches VLAgent to DaemonSet mode
144+
- mounts host paths, where k8s logs are stored
145+
- adds RBAC to be able to get pods, namespaces and nodes information using K8s API
146+
139147
## Storage management
140148

141149
In case of errors sending logs to `remoteWrite`,

0 commit comments

Comments
 (0)