Skip to content

Conversation

vimalk78
Copy link
Contributor

@vimalk78 vimalk78 commented Oct 29, 2021

Description

PR to generate bare minimal vector.toml

  • all Sources are read (container logs, journal logs, audit logs)
  • adds basic transformation of raw logs to adjust log level, and add some metadata
  • adds basic routing
    • splits container logs into app and infra
    • source to input ("application", "infrastructure", "audit")
    • input to pipeline
    • pipeline to outputs
    • some nodes in the generated pipeline are no-op, these are there just to rename the stream to get names as per API
  • kafka output is supported (sasl username/password not supported, key/cert supported)

Sample Conf:

# Logs from containers (including openshift containers)
[sources.raw_container_logs]
type = "kubernetes_logs"
auto_partial_merge = true
exclude_paths_glob_patterns = ["/var/log/pods/openshift-logging_collector-*/*/*.log", "/var/log/pods/openshift-logging_elasticsearch-*/*/*.log", "/var/log/pods/openshift-logging_kibana-*/*/*.log"]

[sources.raw_journal_logs]
type = "journald"

# Logs from host audit
[sources.host_audit_logs]
type = "file"
ignore_older_secs = 600
include = ["/var/log/audit/audit.log"]

# Logs from kubernetes audit
[sources.k8s_audit_logs]
type = "file"
ignore_older_secs = 600
include = ["/var/log/kube-apiserver/audit.log"]

# Logs from openshift audit
[sources.openshift_audit_logs]
type = "file"
ignore_older_secs = 600
include = ["/var/log/oauth-apiserver.audit.log"]

[transforms.container_logs]
type = "remap"
inputs = ["raw_container_logs"]
source = '''
  level = "unknown"
  if match(.message,r'(Warning|WARN|W[0-9]+|level=warn|Value:warn|"level":"warn")'){
	level = "warn"
  } else if match(.message, r'Info|INFO|I[0-9]+|level=info|Value:info|"level":"info"'){
	level = "info"
  } else if match(.message, r'Error|ERROR|E[0-9]+|level=error|Value:error|"level":"error"'){
	level = "error"
  } else if match(.message, r'Debug|DEBUG|D[0-9]+|level=debug|Value:debug|"level":"debug"'){
	level = "debug"
  }
  .level = level

  .pipeline_metadata.collector.name = "vector"
  .pipeline_metadata.collector.version = "0.14.1"
  ip4, err = get_env_var("NODE_IPV4")
  .pipeline_metadata.collector.ipaddr4 = ip4
  received, err = format_timestamp(now(),"%+")
  .pipeline_metadata.collector.received_at = received
  .pipeline_metadata.collector.error = err
 '''

[transforms.journal_logs]
type = "remap"
inputs = ["raw_journal_logs"]
source = '''
  level = "unknown"
  if match(.message,r'(Warning|WARN|W[0-9]+|level=warn|Value:warn|"level":"warn")'){
	level = "warn"
  } else if match(.message, r'Info|INFO|I[0-9]+|level=info|Value:info|"level":"info"'){
	level = "info"
  } else if match(.message, r'Error|ERROR|E[0-9]+|level=error|Value:error|"level":"error"'){
	level = "error"
  } else if match(.message, r'Debug|DEBUG|D[0-9]+|level=debug|Value:debug|"level":"debug"'){
	level = "debug"
  }
  .level = level

  .pipeline_metadata.collector.name = "vector"
  .pipeline_metadata.collector.version = "0.14.1"
  ip4, err = get_env_var("NODE_IPV4")
  .pipeline_metadata.collector.ipaddr4 = ip4
  received, err = format_timestamp(now(),"%+")
  .pipeline_metadata.collector.received_at = received
  .pipeline_metadata.collector.error = err
 '''


[transforms.route_container_logs]
type = "route"
inputs = ["container_logs"]
route.app = '!(starts_with!(.kubernetes.pod_namespace,"kube") && starts_with!(.kubernetes.pod_namespace,"openshift") && .kubernetes.pod_namespace == "default")'
route.infra = 'starts_with!(.kubernetes.pod_namespace,"kube") || starts_with!(.kubernetes.pod_namespace,"openshift") || .kubernetes.pod_namespace == "default"'


# Rename log stream to "application"
[transforms.application]
type = "remap"
inputs = ["route_container_logs.app"]
source = """
.
"""


# Rename log stream to "infrastructure"
[transforms.infrastructure]
type = "remap"
inputs = ["route_container_logs.infra","journal_logs"]
source = """
.
"""


# Rename log stream to "audit"
[transforms.audit]
type = "remap"
inputs = ["host_audit_logs","k8s_audit_logs","openshift_audit_logs"]
source = """
.
"""


[transforms.pipeline]
type = "remap"
inputs = ["application","infrastructure","audit"]
source = """
.
"""

# Kafka config
[sinks.kafka_receiver]
type = "kafka"
inputs = ["pipeline"]
bootstrap_servers = "broker1-kafka.svc.messaging.cluster.local:9092"
topic = "topic"

[sinks.kafka_receiver.encoding]
codec = "json"
timestamp_format = "rfc3339"

# TLS Config
[sinks.kafka_receiver.tls]
key_file = "/var/run/ocp-collector/secrets/kafka-receiver-1/tls.key"
crt_file = "/var/run/ocp-collector/secrets/kafka-receiver-1/tls.crt"
ca_file = "/var/run/ocp-collector/secrets/kafka-receiver-1/ca-bundle.crt"
enabled = true

/cc @jcantrill @ajaygupta978
/assign

Links

@vimalk78
Copy link
Contributor Author

/hold
testing in progress

@openshift-ci openshift-ci bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 29, 2021
@vimalk78 vimalk78 force-pushed the log-1491-gen-vector-conf branch from 26c4e87 to 6b42095 Compare October 29, 2021 17:27
Copy link
Contributor

@jcantrill jcantrill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 29, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jcantrill, vimalk78

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vimalk78 vimalk78 force-pushed the log-1491-gen-vector-conf branch 2 times, most recently from 18d8d50 to 8bee3cc Compare October 29, 2021 18:29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fluentd syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not exactly, passphrase is from kafka sasl config

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant it requires = sign

Copy link
Contributor Author

@vimalk78 vimalk78 Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, i updated the PR. it has an = sign now

@vimalk78 vimalk78 force-pushed the log-1491-gen-vector-conf branch from 8bee3cc to 984c997 Compare October 29, 2021 18:44
 PR to generate bare minimal vector.toml
 - all Sources are read (container logs, journal logs, audit logs)
 - adds basic transformation of raw logs to adjust log level, and add some metadata
 - adds basic routing
   - splits container logs into app and infra
   - source to input ("application", "infrastructure", "audit")
   - input to pipeline
   - pipeline to outputs
   - some nodes in the generated pipeline are no-op, these are there just to rename the stream to get names as per API
 - kafka output is supported (sasl username/password not supported, key/cert supported)
@vimalk78 vimalk78 force-pushed the log-1491-gen-vector-conf branch from 984c997 to 9efa752 Compare October 29, 2021 18:49
@vimalk78
Copy link
Contributor Author

e2e kafka test case works
Steps:

  • uncomment ENABLE_VECTOR_COLLECTOR in Dockerfile
  • set the collector type to vector in ClusterLogging spec test/helpers/clusterlogging.go

infra log message captured in kafka:

{
  "file": "/var/log/pods/openshift-kube-apiserver_kube-apiserver-crc-dzk9v-master-0_cbe6089f-177a-4598-89d7-2bd4e5bef0c1/kube-apiserver/0.log",
  "kubernetes": {
    "container_id": "cri-o://17b1bcd3f1f0a27f4f31cdd62861f8f34a0dcf65df40abd28ced7dedbc7d26c7",
    "container_image": "quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:104105f5abbd3cdc28303d8dd97dad3f05b298bdbc3fc48ca7aa66f34b59329b",
    "container_name": "kube-apiserver",
    "pod_ip": "192.168.126.11",
    "pod_ips": [
      "192.168.126.11"
    ],
    "pod_labels": {
      "apiserver": "true",
      "app": "openshift-kube-apiserver",
      "revision": "8"
    },
    "pod_name": "kube-apiserver-crc-dzk9v-master-0",
    "pod_namespace": "openshift-kube-apiserver",
    "pod_node_name": "crc-dzk9v-master-0",
    "pod_uid": "d445e1ff-4ea4-4387-9e31-efc6cbe8e389"
  },
  "level": "info",
  "message": "I1027 06:36:35.574151      19 apiaccess_count_controller.go:147] finished updating top build.openshift.io/v1, Resource=buildconfigs APIRequest counts",
  "pipeline_metadata": {
    "collector": {
      "error": null,
      "ipaddr4": "192.168.126.11",
      "name": "vector",
      "received_at": "2021-10-29T20:32:58.644812416+00:00",
      "version": "0.14.1"
    }
  },
  "source_type": "kubernetes_logs",
  "stream": "stderr",
  "timestamp": "2021-10-27T06:36:35.574216207Z"
}

the test case fails because test case framework needs to be updated to parse the vector log data model, which is still evolving

@vimalk78
Copy link
Contributor Author

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 30, 2021
@vimalk78
Copy link
Contributor Author

/retest

DescribeTable("Generate full vector.toml", f,
Entry("with complex spec", generator.ConfGenerateTest{
CLSpec: logging.ClusterLoggingSpec{
Forwarder: &logging.ForwarderSpec{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a cleanup item but this is not relevant to vector

.level = level

.pipeline_metadata.collector.name = "vector"
.pipeline_metadata.collector.version = "0.14.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In future we probably should grab this from an ENV since it is likely to change

@jcantrill
Copy link
Contributor

/hold

for 5.3 FF

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 2, 2021
@jcantrill
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 9, 2021
@jcantrill
Copy link
Contributor

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 9, 2021
@openshift-merge-robot openshift-merge-robot merged commit 37d049c into openshift:master Nov 9, 2021
pmoogi-redhat pushed a commit to pmoogi-redhat/cluster-logging-operator that referenced this pull request Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants