Skip to content

Dataway Sink


The Sinker feature described here is available only in Datakit Version-1.14.0.


Dataway Sinker Features

In daily data collection, because multiple workspaces may exist, you may need to send different data to different workspaces. For example, in a shared Kubernetes cluster, the collected data may involve different teams or business departments. In this case, you can send data with specific attributes to different workspaces to achieve fine-grained collection in shared infrastructure scenarios.

The processing flow for Sink requests is as follows:

sequenceDiagram
autonumber

participant dk as DataKit

box Dataway server
participant etcd
participant dw as DataWay
participant rmatch as Rule matching
participant drop as Drop
end

box Workspaces
participant wksp1 as Workspace
participant wkspx as Default workspace
end

etcd ->> dw: pull sinker rules

activate dw
dk ->> dw: upload
deactivate dw

alt non-sink request
    dw ->> wksp1: write
else sink request
    dw ->> rmatch: matching
end

alt match ok(at lease 1 workspace)
    rmatch ->> wksp1: write
else match failed but enabled default workspace
    rmatch ->> wkspx: write
else no default workspace
    rmatch ->> drop: drop
end

Dataway 1.8.0 supports receiving both Sinker and non-Sinker requests, so you only need to deploy one Dataway.

Dataway Cascaded Mode

For SaaS users, you can deploy a Dataway locally (in your k8s cluster) dedicated to routing, and then forward the data to Openway:

Warning

In cascaded mode, the Dataway in the cluster must have the cascaded option enabled. See the environment variable description in the installation documentation.

sequenceDiagram
autonumber

participant dk as DataKit

box local Dataway server
participant etcd
participant dw1 as DataWay
end

box SAAS Dataway server
participant dw2 as DataWay
end

box Workspaces
participant wksp1 as Workspace
end

etcd ->> dw1: pull sinker rules
dk ->> dw1: upload data
dw1 ->> dw1: sink rule matching
dw1 ->> dw2: deliver request
dw2 ->> wksp1: write

Impacts of cascading:

  • Some API behavior differs. For historical reasons, the request URLs sent by Datakit differ from those on Kodo, and Dataway acts as an API translator here. In cascaded mode, the API translation feature is disabled.
  • A cascaded Dataway does not send heartbeat requests to the center because the next-level Dataway does not handle this request (hence the 404).
  • Requests received by a cascaded Dataway are not signed for the API when forwarded to the next Dataway.

Dataway Installation

See here.

Dataway Settings

In addition to the standard Dataway settings, you need to configure several additional items (located in /usr/local/cloudcare/dataflux/dataway/dataway.yaml):

# Set the address to which Dataway uploads data here. This is usually Kodo, but it can also be another Dataway
remote_host: https://kodo.guance.com

# If the upload address is a Dataway, set this to true to indicate Dataway cascading
cascaded: false

# This token is an arbitrary token set on Dataway. You need to fill it in
# the Datakit datakit.conf configuration. It must maintain a certain length and format.
secret_token: tkn_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Sinker rule settings
sinker:
  etcd: # Supports etcd
    urls:
    - http://localhost:2379
    dial_timeout: 30s
    key_space: /dw_sinker
    username: "dataway"
    password: "<PASSWORD>"

  #file: # Local file mode is also supported, often used for debugging
  #  path: /path/to/sinker.json
Warning

If secret_token is not set, any request sent by Datakit can pass, which does not cause data issues. However, if Dataway is deployed on the public network, it is still recommended to set secret_token.

Sinker Rule Settings

Dataway Sinker rules are a set of configurations in JSON format. The matching rules are written in the same way as blacklists. See here.

Two configuration sources are currently supported:

  • Specify a local JSON file, mainly for debugging Sinker rules. In this case, after updating the Sinker rules in the JSON file, you must restart Dataway for the changes to take effect
  • Etcd: Store the debugged rule file in etcd. When you need to fine-tune the rules later, you can update etcd directly, and you do not need to restart Dataway

In fact, the JSON stored in etcd has the same content as the JSON in a local file. The following only describes the etcd hosting method.

Etcd Settings

The following commands are all run on Linux.

As an etcd client, Dataway can use the following username and role settings in etcd (etcd 3.5+). See here

Create the dataway account and its corresponding role:

# Add the username; you will be prompted to enter a password
$ etcdctl user add dataway

# Add the sinker role
$ etcdctl role add sinker

# Add dataway to the role
$ etcdctl user grant-role dataway sinker

# Restrict the key permissions of the role (here /dw_sinker and /ping are the two keys used by default)
$ etcdctl role grant-permission sinker readwrite /dw_sinker
$ etcdctl role grant-permission sinker readwrite /ping       # Used to check connectivity
Why create a role?

Roles are used to control the permissions of the corresponding user on certain keys. The etcd service used here may be an existing service of the user, so it is necessary to restrict the data permissions of the Dataway user.

Warning

If etcd has authentication enabled, include the corresponding username and password when running the etcdctl command:

$ etcdctl --user name:password ...

Write Sinker Rules

Newer versions of Dataway (1.3.6) support managing Sinker rules in etcd through the dataway command.

Assume the sinker.json rule is defined as follows:

{
    "strict":true,
    "rules": [
        {
            "rules": [
                "{ host = 'my-host'}"
            ],
            "url": "https://kodo.guance.com?token=tkn_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        },
        {
            "rules": [
                "{ host = 'my-host' OR cluster = 'cluster-A' }"
            ],
            "url": "https://kodo.guance.com?token=tkn_yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
        }
     ]
}

You can write the Sinker rule configuration with the following command:

$ etcdctl --user dataway:PASSWORD put /dw_sinker "$(<sinker.json)"
OK
Marking workspace information

Because comments are not supported in sinker.json, you can add an info field to the JSON as a memo to achieve a commenting effect:

{
    "rules": [
        "{ host = 'my-host' OR cluster = 'cluster-A' }"
    ],
    "info": "This is the yyy workspace",
    "url": "https://kodo.guance.com?token=tkn_yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
}

Default Rule

Version-1.6.0

Add the as_default flag to a specific rule entry to set that rule as the default fallback rule. A fallback rule can have no matching conditions (the rules field is not configured). At the same time, it should not participate in regular rule matching. A recommended fallback rule is as follows:

{
    "as_default": true,
    "info": "This is the default fallback workspace",
    "url": "https://kodo.guance.com?token=tkn_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

Note: You should set only one fallback rule. If multiple fallback rules exist in the sinker configuration, the last one takes effect.

Token Rules

Because Datakit checks the token on Dataway, the token set here (including secret_token) must meet the following conditions:

It starts with token_ or tkn_, and the following characters are 32 in length.

If a token does not meet these conditions, Datakit installation will fail.

Datakit-side Settings

In Datakit, you need to make several settings so that it can tag collected data with specific labels for grouping.

  • Configure the global custom key list

Datakit looks for fields with these keys in the data it collects (only string-type fields) and extracts them as the basis for grouped sending.

See here

See here

  • Configure global host tags and global election tags

All data uploaded by Datakit carries these configured global tags (including tag key and tag value) as the basis for grouped sending.

See here

See here

Datakit-side Customer Key Settings

If you want the data collected by a specific Datakit to meet routing requirements, ensure the following:

  • Sinker is enabled on Datakit
  • A valid Global Customer Key is configured in Datakit

These two configurations are as follows:

# /usr/local/datakit/conf.d/datakit.conf
[dataway]

  # Specify a set of customer keys
  global_customer_keys = [
    # Example: add the two keys category and class
    # Do not configure too many keys here; generally 2 to 3 is sufficient
    "category",
    "class",
  ]

  # Enable the sinker feature
  enable_sinker = true

In addition to synthetic testing data and regular data categories, Session Replay and Profiling binary file data are also supported. Therefore, you can select any field name here. Note that do not configure non-string fields. Normal keys generally come from tags (all tag values are strings). Datakit does not use non-string fields as the basis for routing.

Impact of Global Tags

In addition to global_customer_keys, the global tags configured on Datakit (including global election tags and global host tags) also affect the routing tags. That is, if a data point contains a field that appears in the global tags (the field value must be of string type), it is also included in routing. Assume the global election tags are as follows:

# datakit.conf
[election.tags]
    cluster = "my-cluster"

For the following data point:

pi,cluster=cluster_A,app=math,other_tag=other_value value=3.14 1712796013000000000

Because the global election tags include cluster (regardless of the value configured for this tag) and the point itself also has the cluster tag, the key-value pair cluster=cluster_A is appended to the final X-Global-Tags:

X-Global-Tags: cluster=cluster_A

If app is also configured in global_customer_keys, the final routing header is as follows (the order in which the two key-value pairs appear does not matter):

X-Global-Tags: cluster=cluster_A,app=math
Note

This example intentionally sets the value of cluster in datakit.conf to be different from the value of the cluster field in the data point, mainly to emphasize the impact of the tag key here. You can understand it as follows: once a qualifying global tag key appears in a data point, it has the same effect as adding this global tag key to global_customer_keys.

Dataway sink Commands

Starting from version Version-1.3.6, Dataway supports managing sinker configuration from the command line. The usage is as follows:

$ ./dataway sink --help

Usage of sink:
  -add string
        single rule json file
  -cfg-file string
        configure file (default "/usr/local/cloudcare/dataflux/dataway/dataway.yaml")
  -file string
        file path of the rule json, only used for command put and get
  -get
        get the rule json
  -list
        list rules
  -log string
        log file path (default "/dev/null")
  -put
        save the rule json
  -token string
        rules filtered by token, eg: xx,yy

Specify a configuration file

When the command runs, the default configuration file loaded is /usr/local/cloudcare/dataflux/dataway/dataway.yaml. To load another configuration, specify it with --cfg-file.

$ ./dataway sink --cfg-file dataway.yaml [--list...]

Command Log Settings

By default, command output logs are disabled. To view them, set the --log parameter.

# output log to stdout
$ ./dataway sink --list --log stdout

# output log to file
$ ./dataway sink --list --log /tmp/log

View the Rule List

# list all rules
$ ./dataway sink --list

# list all rules filtered by token
$ ./dataway sink --list --token=token1,token2

CreateRevision: 2
ModRevision: 41
Version: 40
Rules:
[
    {
        "rules": [
            "{ workspace = 'zhengb-test'}"
        ],
        "url": "https://openway.guance.com?token=token1"
    }
]

Add Rules

Create a rule file rule.json with the following content:

[
  {
    "rules": [
      "{ host = 'HOST1'}"
    ],
    "url": "https://openway.guance.com?token=tkn_xxxxxxxxxxxxx"
  },
  {
    "rules": [
      "{ host = 'HOST2'}"
    ],
    "url": "https://openway.guance.com?token=tkn_yyyyyyyyyyyyy"
  }
]

Add rules

$ ./dataway sink --add rule.json

add 2 rules ok!

Export Configuration

Exporting the configuration saves the sinker configuration to a local file.

$ ./dataway sink --get --file sink-get.json

rules json was saved to sink-get.json!

Write Configuration

Writing rules synchronizes the local rule file to sinker.

Create a rule file sink-put.json with the following content:

{
    "rules": [
        {
            "rules": [
                "{ workspace = 'test'}"
            ],
            "url": "https://openway.guance.com?token=tkn_xxxxxxxxxxxxxx"
        }
    ],
    "strict": true
}

Write the configuration

$ ./dataway sink --put --file sink-put.json

Configuration Examples

dataway.yaml Example in Kubernetes (expand below)

Specify sinker JSON directly in YAML:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: deployment-utils-dataway
  name: dataway
  namespace: utils
spec:
  replicas: 1
  selector:
    matchLabels:
      app: deployment-utils-dataway
  template:
    metadata:
      labels:
        app: deployment-utils-dataway
      annotations:
        datakit/logs: |
          [{"disable": true}]
        datakit/prom.instances: |
          [[inputs.prom]]
            url = "http://$IP:9090/metrics" # The port here (default 9090) depends on the situation
            source = "dataway"
            measurement_name = "dw" # Fixed to this measurement
            interval = "10s"

            [inputs.prom.tags]
              namespace = "$NAMESPACE"
              pod_name = "$PODNAME"
              node_name = "$NODENAME"
    spec:
      affinity:
        podAffinity: {}
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: app
                    operator: In
                    values:
                      - deployment-utils-dataway
              topologyKey: kubernetes.io/hostname

      containers:
      - image: registry.jiagouyun.com/dataway/dataway:1.3.6 # Select an appropriate version number here
        #imagePullPolicy: IfNotPresent
        imagePullPolicy: Always
        name: dataway
        env:
        - name: DW_REMOTE_HOST
          value: "http://kodo.forethought-kodo:9527" # Enter the actual Kodo address, or the address of the next Dataway
        - name: DW_BIND
          value: "0.0.0.0:9528"
        - name: DW_UUID
          value: "agnt_xxxxx" # Enter the actual Dataway UUID
        - name: DW_TOKEN
          value: "tkn_oooooooooooooooooooooooooooooooo" # Enter the actual Dataway token, usually the token of the system workspace
        - name: DW_PROM_LISTEN
          value: "0.0.0.0:9090"
        - name: DW_SECRET_TOKEN
          value: "tkn_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
        - name: DW_SINKER_FILE_PATH
          value: "/usr/local/cloudcare/dataflux/dataway/sinker.json"
        ports:
        - containerPort: 9528
          name: 9528tcp01
          protocol: TCP
        volumeMounts:
          - mountPath: /usr/local/cloudcare/dataflux/dataway/cache
            name: dataway-cache
          - mountPath: /usr/local/cloudcare/dataflux/dataway/sinker.json
            name: sinker
            subPath: sinker.json
        resources:
          limits:
            cpu: '4'
            memory: 4Gi
          requests:
            cpu: 100m
            memory: 512Mi
      # nodeSelector:
      #   key: string
      imagePullSecrets:
      - name: registry-key
      restartPolicy: Always
      volumes:
      - hostPath:
          path: /root/dataway_cache
        name: dataway-cache
      - configMap:
          name: sinker
        name: sinker
---

apiVersion: v1
kind: Service
metadata:
  name: dataway
  namespace: utils
spec:
  ports:
  - name: 9528tcp02
    port: 9528
    protocol: TCP
    targetPort: 9528
    nodePort: 30928
  selector:
    app: deployment-utils-dataway
  type: NodePort

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: sinker
  namespace: utils
data:
  sinker.json: |
    {
        "strict":true,
        "rules": [
            {
                "rules": [
                    "{ project = 'xxxxx'}"
                ],
                "url": "http://kodo.forethought-kodo:9527?token=tkn_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            },
            {
                "rules": [
                    "{ project = 'xxxxx'}"
                ],
                "url": "http://kodo.forethought-kodo:9527?token=tkn_yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
            }
         ]
    }
Ingress Configuration Example (expand below)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: dataway-sinker
  namespace: utils
spec:
  ingressClassName: nginx
  rules:
  - host: datawaysinker-xxxx.com
    http:
      paths:
      - backend:
          service:
            name: dataway
            port:
              number: 9528
        path: /
        pathType: ImplementationSpecific

FAQ

View Details of Dropped Requests

Version-1.3.7

When a request does not match the Sinker rules, Dataway drops the request and increments a drop count in the metrics. However, during debugging, you need to know the details of a dropped request, especially the X-Global-Tags information carried in the request header.

You can search the Dataway logs with the following command:

$ cat <path/to/dataway/log> | grep dropped

In the output, you can see something like the following:

for API /v1/write/logging with X-Global-Tags <some-X-Global-Tags...> dropped

Troubleshoot Dropped Datakit Requests

Version-1.3.9

When a Datakit request is dropped by Dataway, Dataway returns the corresponding HTTP error. The Datakit log shows an error similar to the following:

post 3641 to http://dataway-ip:9528/v1/write/metric failed(HTTP: 406 Not Acceptable):
{"error_code":"dataway.sinkRulesNotMatched","message":"X-Global-Tags: `host=my-host',
URL: `/v1/write/metric'"}, data dropped

This error indicates that the request /v1/write/metric was dropped because its X-Global-Tags did not match any rule on Dataway.

At the same time, in the DataWay APIs panel in the lower-right corner of Datakit monitor (datakit monitor -V), the Status column shows Not Acceptable, indicating that the corresponding Dataway API request was dropped.

You can also see the corresponding metrics in Datakit's own metrics:

$ curl -s http://localhost:9529/metrics | grep datakit_io_dataway_api_latency_seconds_count

datakit_io_dataway_api_latency_seconds_count{api="/v1/datakit/pull",status="Not Acceptable"} 50
datakit_io_dataway_api_latency_seconds_count{api="/v1/write/metric",status="Not Acceptable"} 301

Datakit Reports Error 403

If the sinker configuration on Dataway is incorrect, all Datakit requests use secret_token. However, this token is not recognized by the center (Kodo), so a 403 error kodo.tokenNotFound is reported.

This problem may be caused by an incorrect etcd username or password, which prevents Dataway from obtaining the Sinker configuration. Dataway then considers the current sinker invalid, and all data is sent directly to the center.

Etcd Permission Configuration Issues

If the Dataway log contains the following error, the permission settings may be incorrect:

sinker ping: etcdserver: permission denied, retrying(97th)

If the permissions are incorrectly configured, you can delete all existing Dataway-based permissions and reconfigure them. For details, see here

Key Override Relationship on Datakit

When configuring the global custom key list, if the global host tags and global election tags also contain keys with the same names, the corresponding key-value pair in the collected data is used.

For example, if the configured global custom key list contains key1,key2,key3, and these keys are also configured in the global host tags or global election tags with corresponding values, such as key1=value-1, and a data collection also contains a field key1=value-from-data, the final grouping basis uses key1=value-from-data from the data and ignores the value of the corresponding key configured in the global host tags and global election tags.

If the global host tags and global election tags contain keys with the same name, the key in the global election tags takes precedence. In short, the priority of key value sources is as follows (descending):

  • Collected data
  • Global election tags
  • Global host tags

Built-in Global Custom Keys

Datakit provides the following built-in custom keys. They generally do not appear in collected data, but Datakit can use these keys to group data. If you need routing by these keys, you can add them to the global custom key list (these keys are not configured by default). You can use the following built-in custom keys to route data.

Warning

Adding global custom keys causes data to be split into multiple packets during sending. If the granularity is too fine, Datakit upload efficiency will drop sharply. In general, it is not recommended to use more than 3 global custom keys.

  • class: For object data. When enabled, data is routed by object class. For example, the object class of a Pod is kubelet_pod, so you can create a routing rule for pods:
{
    "strict": true,
    "rules": [
        {
            "rules": [
                "{ class = 'kubelet_pod' AND other_conditon = 'some-value' }",
            ],
            "url": "https://kodo.guance.com?token=<YOUR-TOKEN>"
        },
        {
            ... # other rules
        }
    ]
}
  • measurement: For metric data. You can send a specific measurement to a specific workspace. For example, if the disk measurement name is disk, you can write the rule as follows:
{
    "strict": true,
    "rules": [
        {
           "rules": [
               "{ measurement = 'disk' AND other_conditon = 'some-value' }",
           ],
           "url": "https://kodo.guance.com?token=<YOUR-TOKEN>"
        },
        {
            ... # other rules
        }
    ]
}
  • source: For logs (L), eBPF network metrics (N), events (E), and RUM data
  • service: For Tracing, Scheck, and Profiling
  • category: For all regular data categories. Its value is the "Name" column of the corresponding data category (for example, time series is metric, object is object, etc.). Taking logs as an example, you can create a separate routing rule for logs as follows:
{
    "strict": true,
    "rules": [
        {
            "rules": [
                "{ category = 'logging' AND other_conditon = 'some-value' }",
            ],
            "url": "https://kodo.guance.com?token=<YOUR-TOKEN>"
        },
        {
            ... # other rules
        }
    ]
}

Special Routing Behavior

Starting from Version-2.0.0, Datakit adds the Dataway Sinker header only to point write requests (/v1/write/*). Other Dataway APIs that pull resources from the center, perform identity identification, or synchronize configuration no longer carry X-Global-Tags/X-Global-Tags-V2, so you no longer need to add special routing rules for these APIs.

For versions earlier than Datakit 2.0.0, some requests initiated by Datakit are intended to pull resources from the center or perform its own identity identification. These behaviors are already atomic and cannot be split further, nor can these requests be distributed to multiple workspaces (because Datakit must process the responses of these API requests and decide its subsequent behavior). Therefore, these APIs can be routed to at most one workspace.

If multiple conditions are matched in the routing rules, these APIs are still routed only to the workspace pointed to by the first matching rule.

The following is an example of a compatibility rule available for versions earlier than Datakit 2.0.0:

Add this rule only when an older version of Datakit needs to pin these APIs to a specific workspace. Datakit 2.0.0 and later do not need it.

{
    "strict": true,
    "info": "Special workspace (only for APIs such as data pull)",
    "rules": [
        {
            "rules": [
                "{ __dataway_api in ['/v1/datakit/pull', '/v1/election', '/v1/election/heartbeat', '/v1/query/raw', '/v1/workspace', '/v1/object/labels', '/v1/check/token'] }"
            ],
            "url": "https://kodo.guance.com?token=<SOME-SPECIAL-WORKSPACE-TOKEN>"
        }
    ]
}
Info

These API URLs are described as follows:

  • /v1/election: Election request
  • /v1/election/heartbeat: Election heartbeat request
  • /v1/datakit/pull: Pull the Pipeline and blacklist configured in the center
  • /v1/query/raw: DQL query
  • /v1/workspace: Get workspace information
  • /v1/object/labels: Update/delete object data
  • /v1/check/token: Check workspace token information

Before Datakit 2.0.0, the __dataway_api key did not need to be configured in global_customer_keys in datakit.conf. Dataway used it as a routing key by default, with the API route of the current request as its value. That is, for a certain API:

POST /v1/some/api
X-Global-Tags: cluster=cluster_A,app=math

the final routing effect is the same as the following:

POST /v1/some/api
X-Global-Tags: cluster=cluster_A,app=math,__dataway_api=/v1/write/metrics

Therefore, in compatibility scenarios for older versions, you can directly use the __dataway_api key-value pair in Sink rules for matching. This also reminds us that in this special rule, do not add other important data upload APIs, such as /v1/write/... interfaces; otherwise, which workspace the data ultimately lands in is undefined. In Datakit 2.0.0 and later, these non-point write APIs no longer carry the Sinker header, so there is no need to rely on __dataway_api rules for routing.

Feedback

Is this page helpful?