stackstate-agent

module
v0.0.0-...-7983b3b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: Apache-2.0

README

StackState Agent

Contains the code for the StackState agent V2. Agent integrations are not included in this project and can be found here.

Installation

Installation instructions are available on the StackState docs site.

Getting development started

To build the Agent you need:

  • Go 1.16 or later. You'll also need to set your $GOPATH and have $GOPATH/bin in your path.
  • Python 3.7+ along with development libraries for tooling. You will also need Python 2.7 if you are building the Agent with Python 2 support.
  • Python dependencies. You may install these with pip install -r requirements.txt This will also pull in Invoke if not yet installed.
  • CMake version 3.12 or later and a C++ compiler

Note: you may want to use a python virtual environment to avoid polluting your system-wide python environment with the agent build/dev dependencies. You can create a virtual environment using virtualenv and then use the invoke agent.build parameters --python-home-2=<venv_path> and/or --python-home-3=<venv_path> (depending on the python versions you are using) to use the virtual environment's interpreter and libraries. By default, this environment is only used for dev dependencies listed in requirements.txt.

Note: You may have previously installed invoke via brew on MacOS, or pip in any other platform. We recommend you use the version pinned in the requirements file for a smooth development/build experience.

Builds and tests are orchestrated with invoke, type invoke --list on a shell to see the available tasks.

To start working on the Agent, you can build the master branch:

  1. Checkout the repo: git clone https://github.com/StackVista/stackstate-agent.git $GOPATH/src/github.com/DataDog/datadog-agent.

  2. cd into the project folder: cd $GOPATH/src/github.com/StackVista/stackstate-agent.

  3. Install go tools: invoke install-tools.

  4. Install go dependencies: invoke deps. Make sure that $GOPATH/bin is in your $PATH otherwise this step might fail.

  5. Create a development datadog.yaml configuration file in dev/dist/datadog.yaml, containing a valid API key: api_key: <API_KEY>

  6. Build the agent with invoke agent.build --build-exclude=systemd.

  7. When editing code in VS Code or in Intellij configure it to use the same tags as are used by the previous invoke command (they are visisble in the output, current set is consul ec2 process python gce cri zk containerd zlib jmx secrets kubelet kubeapiserver jetson docker etcd apm netcgo orchestrator). In VS Code this is configurable for the workspace on the Go plugin settings.

    By default, the Agent will be built to use Python 3 but you can select which Python version you want to use:

    • invoke agent.build --python-runtimes 2 for Python2 only
    • invoke agent.build --python-runtimes 3 for Python3 only
    • invoke agent.build --python-runtimes 2,3 for both Python2 and Python3

    You can specify a custom Python location for the agent (useful when using virtualenvs):

    invoke agent.build \
      --python-runtimes 2,3 \
      --python-home-2=$GOPATH/src/github.com/StackVista/stackstate-agent/venv2 \
      --python-home-3=$GOPATH/src/github.com/StackVista/stackstate-agent/venv3 .
    

    Running invoke agent.build:

    • Discards any changes done in bin/agent/dist.
    • Builds the Agent and writes the binary to bin/agent/agent.
    • Copies files from dev/dist to bin/agent/dist. See https://github.com/DataDog/datadog-agent/blob/main/dev/dist/README.md for more information.

    If you built an older version of the agent, you may have the error make: *** No targets specified and no makefile found. Stop.. To solve the issue, you should remove CMakeCache.txt from rtloader folder with rm rtloader/CMakeCache.txt.

Testing

Run tests using invoke test. During development, add the --skip-linters option to skip straight to the tests.

invoke test --targets=./pkg/aggregator/... --skip-linters

When testing code that depends on rtloader, build and install it first.

invoke rtloader.make && invoke rtloader.install
invoke test --targets=./pkg/collector/python --skip-linters

Run

You can run the agent with:

./bin/agent/agent run -c bin/agent/dist/stackstate.yaml

The file bin/agent/dist/datadog.yaml is copied from dev/dist/datadog.yaml by invoke agent.build and must contain a valid api key.

Install

Linux
Official

To install the official release:

$ curl -o- https://stackstate-agent-3.s3.amazonaws.com/install.sh | STS_API_KEY="xxx" STS_URL="yyy" bash
 or
$ wget -qO- https://stackstate-agent-3.s3.amazonaws.com/install.sh | STS_API_KEY="xxx" STS_URL="yyy" bash
Test

If you want to install a branch version use the test repository:

$ curl -o- https://stackstate-agent-3-test.s3.amazonaws.com/install.sh | STS_API_KEY="xxx" STS_URL="yyy" CODE_NAME="PR_NAME" bash
 or
$ wget -qO- https://stackstate-agent-3-test.s3.amazonaws.com/install.sh | STS_API_KEY="xxx" STS_URL="yyy" CODE_NAME="PR_NAME" bash

and replace PR_NAME with the branch name (e.g. master, STAC-xxxx).

Docker
Official
$ docker pull artifactory.tooling.stackstate.io/docker-virtual/stackstate/stackstate-agent-2:latest
Test
$ docker pull artifactory.tooling.stackstate.io/docker-virtual/stackstate/stackstate-agent-2-test:latest
Windows
Official

To install the official release:

$ . { iwr -useb https://stackstate-agent-3.s3.amazonaws.com/install.ps1 } | iex; install -stsApiKey "xxx" -stsUrl "yyy"
Test

If you want to install a branch version use the test repository:

$ . { iwr -useb https://stackstate-agent-3-test.s3.amazonaws.com/install.ps1 } | iex; install -stsApiKey "xxx" -stsUrl "yyy" -codeName "PR_NAME"

and replace PR_NAME with the branch name (e.g. master, STAC-xxxx).

Arguments

Other arguments can be passed to the installation command.

Linux arguments:

  • STS_HOSTNAME = Instance hostname
  • $HOST_TAGS = Agent host tags to use for all topology component (by default os:linux will be added)
  • SKIP_SSL_VALIDATION = Skip ssl certificates validation when talking to the backend (defaults to false)
  • STS_INSTALL_ONLY = Agent won't be automatically started after installation

Windows arguments:

  • hostname = Instance hostname
  • tags = Agent host tags to use for all topology component (by default os:windows will be added)
  • skipSSLValidation = Skip ssl certificates validation when talking to the backend (defaults to false)
  • agentVersion = Version of the Agent to be installed (defaults to latest)
Omnibus notes for windows build process

We ended up checking in a patched gem file under omnibus/vendor/cache/libyajl2-1.2.1.gem, to make windows builds work with newer msys toolchain. The source of this can be found here https://github.com/StackVista/libyajl2-gem/tree/1.2.0-fixed-lssp. Ideally we'd be able to drop this hack once we bump the ruby version > 2.6.5 because libyajl2 compiles proper on those ruby versions.

GitLab cluster agent pipeline

If you want to speed up the GitLab pipeline and run only the steps related to the cluster agent, include the string [cluster-agent] in your commit message.

Testing cluster-agent helm chart

The acceptance tests in our pipeline use the stackstate-agent helm chart to install the agent in a test cluster. If you make changes to the stackstate-agent helm chart, you probably want to test if our acceptance tests will work after your changes.

When you open a merge request on the helm-chart repository, a test version of that chart will be published to a test helm repository stackstate-test. You can add that test repo in your machine by running the following commands:

helm repo add stackstate-test https://helm-test.stackstate.io && helm repo update

You can then install this version of the cluster-agent helm chart by running:

helm upgrade --install \
  --create-namespace \
  --namespace <namespace> \
  --set-string 'stackstate.apiKey'='<api-key>' \
  --set-string 'stackstate.cluster.name'='<cluster-name' \
  --set-string 'stackstate.url'='<stackstate-url>' \
  stackstate-agent stackstate-test/stackstate-agent --version <version>

<version> is the new version you've set on helm-charts/stable/stackstate-agent/Chart.yaml on your feature branch.

To use this version in the stackstate-agent pipeline, create a branch and update the AGENT_HELM_CHART_VERSION variable on .gitlab-ci-agent.yml, with that the pipeline will use the test helm repository that was updated by the helm-charts pipeline.

Directories

Path Synopsis
cmd
agent
The Datadog Agent faithfully collects events and metrics and brings them to Datadog on your behalf.
The Datadog Agent faithfully collects events and metrics and brings them to Datadog on your behalf.
agent/api
Package api implements the agent IPC api.
Package api implements the agent IPC api.
agent/api/agent
Package agent implements the api endpoints for the `/agent` prefix.
Package agent implements the api endpoints for the `/agent` prefix.
agent/api/check
Package check implements the api endpoints for the `/check` prefix.
Package check implements the api endpoints for the `/check` prefix.
agent/app
Package app implements the Agent main loop, orchestrating all the components and providing the command line interface.
Package app implements the Agent main loop, orchestrating all the components and providing the command line interface.
agent/app/standalone
Package standalone provides utility functions for Agent CLI commands that set up a new in-process Agent runtime (ex: check, jmx commands), as opposed to CLI commands that query a running Agent's IPC API.
Package standalone provides utility functions for Agent CLI commands that set up a new in-process Agent runtime (ex: check, jmx commands), as opposed to CLI commands that query a running Agent's IPC API.
agent/clcrunnerapi
Package clcrunnerapi implements the clc runner IPC api.
Package clcrunnerapi implements the clc runner IPC api.
agent/clcrunnerapi/v1
Package v1 implements the api endpoints for the `/api/v1` prefix.
Package v1 implements the api endpoints for the `/api/v1` prefix.
agent/common
Package common provides a set of common symbols needed by different packages, to avoid circular dependencies.
Package common provides a set of common symbols needed by different packages, to avoid circular dependencies.
cluster-agent/api
Package api implements the agent IPC api.
Package api implements the agent IPC api.
cluster-agent/api/agent
Package agent implements the api endpoints for the `/agent` prefix.
Package agent implements the api endpoints for the `/agent` prefix.
security-agent/api
Package api implements the agent IPC api.
Package api implements the agent IPC api.
security-agent/api/agent
Package agent implements the api endpoints for the `/agent` prefix.
Package agent implements the api endpoints for the `/agent` prefix.
pkg
collector/check/defaults
Package defaults provides common defaults used in agent checks
Package defaults provides common defaults used in agent checks
collector/corechecks/cluster
Package cluster provides core checks for cluster level checks, used by the Datadog Cluster Agent.
Package cluster provides core checks for cluster level checks, used by the Datadog Cluster Agent.
collector/corechecks/cluster/dockerswarm
Package dockerswarm provides core checks for docker swarm topology
Package dockerswarm provides core checks for docker swarm topology
collector/corechecks/cluster/kubeapi
Package kubeapi provides core checks for kubernetes api
Package kubeapi provides core checks for kubernetes api
collector/corechecks/containers
Package containers provides core checks for containers and orchestrators
Package containers provides core checks for containers and orchestrators
collector/corechecks/containers/topology
Package topology is responsible for gathering topology for containers StackState
Package topology is responsible for gathering topology for containers StackState
collector/corechecks/net
Package net provides core checks for networking
Package net provides core checks for networking
collector/corechecks/nvidia/jetson
Package nvidia provides core checks for Nvidia's jetson device family
Package nvidia provides core checks for Nvidia's jetson device family
collector/corechecks/system
Package system provides core checks for OS-level system metrics
Package system provides core checks for OS-level system metrics
collector/corechecks/systemd
Package systemd provides core checks for systemd
Package systemd provides core checks for systemd
collector/metadata
Package metadata implements specific Metadata Collectors for the Agent.
Package metadata implements specific Metadata Collectors for the Agent.
compliance
Package compliance defines common interfaces and types for Compliance Agent
Package compliance defines common interfaces and types for Compliance Agent
compliance/agent
Package agent implements the Compliance Agent entrypoint
Package agent implements the Compliance Agent entrypoint
compliance/checks
Package checks implements Compliance Agent checks
Package checks implements Compliance Agent checks
config/resolver
Package resolver contains logic to perform per `transaction.Endpoint` domain resolution.
Package resolver contains logic to perform per `transaction.Endpoint` domain resolution.
forwarder/endpoints
Package endpoints stores a collection of `transaction.Endpoint` mainly used by the forwarder package to send data to Datadog using the right request path for a given type of data.
Package endpoints stores a collection of `transaction.Endpoint` mainly used by the forwarder package to send data to Datadog using the right request path for a given type of data.
logs/parser
Package parser supports transforming raw log "lines" into messages with some associated metadata (timestamp, severity, etc.).
Package parser supports transforming raw log "lines" into messages with some associated metadata (timestamp, severity, etc.).
logs/pb
Package pb is a generated protocol buffer package.
Package pb is a generated protocol buffer package.
metadata/externalhost
Package externalhost implements the External Host Tags metadata provider.
Package externalhost implements the External Host Tags metadata provider.
otlp/internal/testutil
Package testutil includes OTLP-related test utilities.
Package testutil includes OTLP-related test utilities.
proto/pbgo
Package pbgo is a reverse proxy.
Package pbgo is a reverse proxy.
proto/pbgo/mocks
Package mock_pbgo is a generated GoMock package.
Package mock_pbgo is a generated GoMock package.
tagset
Package tagset supports creation and manipulation of sets of tags.
Package tagset supports creation and manipulation of sets of tags.
trace/config/features
Package features provides an API for enabling features and checking if a given feature is enabled.
Package features provides an API for enabling features and checking if a given feature is enabled.
trace/event
Package event contains functionality related to APM event extraction from traces.
Package event contains functionality related to APM event extraction from traces.
trace/metrics
Package metrics exposes utilities for setting up and using a sub-set of Datadog's dogstatsd client.
Package metrics exposes utilities for setting up and using a sub-set of Datadog's dogstatsd client.
trace/metrics/timing
Package timing is used to aggregate timing calls within hotpaths to avoid using repeated statsd calls.
Package timing is used to aggregate timing calls within hotpaths to avoid using repeated statsd calls.
trace/obfuscate
Package obfuscate implements quantizing and obfuscating of tags and resources for a set of spans matching a certain criteria.
Package obfuscate implements quantizing and obfuscating of tags and resources for a set of spans matching a certain criteria.
trace/pb
Package pb contains the data structures used by the trace agent to communicate with tracers and the Datadog API.
Package pb contains the data structures used by the trace agent to communicate with tracers and the Datadog API.
trace/pb/otlppb
Package otlppb is a generated protocol buffer package.
Package otlppb is a generated protocol buffer package.
trace/sampler
Package sampler contains all the logic of the agent-side trace sampling
Package sampler contains all the logic of the agent-side trace sampling
trace/test
Package test provides utilities for running integration tests on the trace agent.
Package test provides utilities for running integration tests on the trace agent.
trace/test/testutil
Package testutil provides easy ways to generate some random or deterministic data that can be use for tests or benchmarks.
Package testutil provides easy ways to generate some random or deterministic data that can be use for tests or benchmarks.
trace/traceutil
Package traceutil contains functions for extracting and processing traces.
Package traceutil contains functions for extracting and processing traces.
util/cachedfetch
Package cachedfetch provides a read-through cache for fetched values.
Package cachedfetch provides a read-through cache for fetched values.
util/containers/providers/windows
Package windows We need a file in this package as it's referenced by a file built on windows
Package windows We need a file in this package as it's referenced by a file built on windows
util/ecs
Package ecs provides metadata collection when the Agent runs on the ECS platform
Package ecs provides metadata collection when the Agent runs on the ECS platform
util/ecs/metadata
Package metadata provides clients for Metadata APIs exposed by the ECS agent.
Package metadata provides clients for Metadata APIs exposed by the ECS agent.
util/executable
Package executable provides information on the executable that started the process and utils to find other executables on the system
Package executable provides information on the executable that started the process and utils to find other executables on the system
util/hostname/validate
Package validate provides hostname validation helpers
Package validate provides hostname validation helpers
workloadmeta/collectors
Package collectors is a wrapper that loads the available workloadmeta collectors.
Package collectors is a wrapper that loads the available workloadmeta collectors.
otlp/model Module
quantile Module
security/secl Module
util/log Module
util/scrubber Module
util/winutil Module
rtloader
test
third_party
tools

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL