diff --git a/internal/buildscripts/packaging/technical-addon/Makefile b/internal/buildscripts/packaging/technical-addon/Makefile new file mode 100644 index 0000000000..a2a4e8b1b8 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/Makefile @@ -0,0 +1,100 @@ +# Used for building +SOURCE_DIR?=$(dir $(abspath $(lastword $(MAKEFILE_LIST)))) +BUILD_DIR?=./build +OTEL_COLLECTOR_VERSION?=0.104.0 +SPLUNK_OTELCOL_DOWNLOAD_BASE?=https://github.com/signalfx/splunk-otel-collector/releases/download +PLATFORM?=linux +ARCH?=amd64 + +# Used for testing & validation +ORCA_CLOUD?=kubernetes +UF_VERSION?=8.2.7 +SPLUNK_PLATFORM?=x64_centos_7 +SPLUNK_ARCH?=x86_64 + +# Used for releases +SPLUNK_OTEL_VERSION?= +TA_VERSION?= + + +.PHONY: generate-technical-addon +generate-technical-addon: env-guard-all + BUILD_DIR="$(BUILD_DIR)" \ + SOURCE_DIR="$(SOURCE_DIR)" \ + $(SOURCE_DIR)/packaging-scripts/make-buildspace.sh + +.PHONY: env-guard-all +env-guard-all: + SOURCE_DIR="$(SOURCE_DIR)" \ + BUILD_DIR="$(BUILD_DIR)" \ + $(SOURCE_DIR)/packaging-scripts/env/all.sh + +.PHONY: env-guard-ta +env-guard-ta: env-guard-all + PLATFORM="$(PLATFORM)" \ + ARCH="$(ARCH)" \ + OTEL_COLLECTOR_VERSION="$(OTEL_COLLECTOR_VERSION)" \ + $(SOURCE_DIR)/packaging-scripts/env/ta.sh + + +.PHONY: env-guard-verify +env-guard-verify: env-guard-ta + ORCA_CLOUD="$(ORCA_CLOUD)" \ + UF_VERSION="$(UF_VERSION)" \ + $(SOURCE_DIR)/packaging-scripts/env/verify.sh + +.PHONY: download +download: env-guard-ta + BUILD_DIR="$(BUILD_DIR)" \ + SOURCE_DIR="$(SOURCE_DIR)" \ + OTEL_COLLECTOR_VERSION="$(OTEL_COLLECTOR_VERSION)" \ + SPLUNK_OTELCOL_DOWNLOAD_BASE="$(SPLUNK_OTELCOL_DOWNLOAD_BASE)" \ + PLATFORM="$(PLATFORM)" \ + ARCH="$(ARCH)" \ + $(SOURCE_DIR)/packaging-scripts/download-release.sh + + +.PHONY: package +package: env-guard-ta + BUILD_DIR="$(BUILD_DIR)" \ + SOURCE_DIR="$(SOURCE_DIR)" \ + ARCH="$(ARCH)" \ + PLATFORM="$(PLATFORM)" \ + OTEL_COLLECTOR_VERSION="$(OTEL_COLLECTOR_VERSION)" \ + $(SOURCE_DIR)/packaging-scripts/package-ta.sh + +.PHONY: distribute-ta +distribute-ta: generate-technical-addon download package + +.PHONY: verify +verify: env-guard-verify + SOURCE_DIR="$(SOURCE_DIR)" \ + BUILD_DIR="$(BUILD_DIR)" \ + ARCH="$(ARCH)" \ + PLATFORM="$(PLATFORM)" \ + OTEL_COLLECTOR_VERSION="$(OTEL_COLLECTOR_VERSION)" \ + ORCA_CLOUD="$(ORCA_CLOUD)" \ + UF_VERSION="$(UF_VERSION)" \ + SPLUNK_PLATFORM="$(SPLUNK_PLATFORM)" \ + OLLY_ACCESS_TOKEN="$(OLLY_ACCESS_TOKEN)" \ + $(SOURCE_DIR)/packaging-scripts/deploy-and-verify.sh + +.PHONY: update-deps +update-deps: + SOURCE_DIR="$(SOURCE_DIR)" \ + SPLUNK_OTEL_VERSION="$(SPLUNK_OTEL_VERSION)" \ + ./packaging-scripts/update-otel-version.sh + TA_VERSION="$(TA_VERSION)" \ + $(SOURCE_DIR)/packaging-scripts/update-ta-version.sh + +.PHONY: release +release: + SOURCE_DIR="$(SOURCE_DIR)" \ + $(SOURCE_DIR)/packaging-scripts/release-ta-version.sh + +.PHONY: update-and-release +update-and-release: update-deps release + +.PHONY: clean +clean: + rm -rf build diff --git a/internal/buildscripts/packaging/technical-addon/README.md b/internal/buildscripts/packaging/technical-addon/README.md new file mode 100644 index 0000000000..92b27f2bf8 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/README.md @@ -0,0 +1,42 @@ +# Need Help? +See `#otel-ta-community` for help. + +# Developing this TA +See [`CONTRIBUTING.md`](./CONTRIBUTING.md) + +# Configuration +## environment variables +In addition to the typical collector environment variables, we additionally provide + +- `$SPLUNK_HOME` ex `/opt/splunk` +- `$SPLUNK_OTEL_TA_HOME` ex `/opt/splunk/etc/apps/Splunk_TA_Otel` +- `$SPLUNK_OTEL_TA_PLATFORM_HOME` ex `/opt/splunk/etc/apps/Splunk_TA_Otel/linux_x86_64` + +These are useful for setting things in `inputs.conf` such as +- `splunk_bundle_dir=$SPLUNK_OTEL_TA_PLATFORM_HOME/bin/agent-bundle` +- `splunk_collectd_dir=$SPLUNK_OTEL_TA_PLATFORM_HOME/bin/agent-bundle/run/collectd` + +There is a debug environment variable for the TA scripts, which will log verbose +messages if set to anything other than the empty string. +- `SPLUNK_OTEL_TA_DEBUG` + +## parameters +See `Splunk_TA_Otel/README/inputs.conf.spec` or `Splunk_TA_Otel/default/inputs.conf` for configuration values. + +Of note is that we need to read the `access_token` from a file into an environment variable during TA initialization. +By default, this access_token is expected to live in `$SPLUNK_OTEL_TA_HOME/local/access_token` + + +# Installation + +## Reducing the size of the TA +Customers may want to remove unnecessary configuration if they're only using one +operating system (ex windows, linux). + +This can be accomplished by removing either `Splunk_TA_Otel/linux_x86_64` or +`Splunk_TA_Otel/windows_x86_64`, respectively. + +## Maintaining configuration between upgrades +As with all TAs, any changes made to `configs` will be overwritten. +Customers should copy any relevant custom configuration from `configs/` or `defaults/` +to `local/`. diff --git a/internal/buildscripts/packaging/technical-addon/RELEASE.md b/internal/buildscripts/packaging/technical-addon/RELEASE.md new file mode 100644 index 0000000000..744297cb02 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/RELEASE.md @@ -0,0 +1,19 @@ +# Making a new release of the TA + +## Update versions for splunk otel collector && TA +1. run `make update-deps` +2. Verify `git diff main -- Makefile Splunk_TA_otel/default/app.conf` shows expected changes + + +## Cut Release +- run `make update-and-release` to automatically upgrade to the latest splunk otel collector release and bump the minor release. + - For more control, you can directly specify the environment variables `SPLUNK_OTEL_VERSION` and `TA_VERSION` + - Example: `SPLUNK_OTEL_VERSION=0.0.0 TA_VERSION=0.0.1 make -e update-and-release` (replacing the version values as desired) +- upload `out/distribution/Splunk_TA_otel.tgz` artifact from `build-all-platforms` job of release branch to splunkbase + +If you have issues with pushing the branch due to duplicate refs or anything, `git tag -d TAG_NAME` can be useful + +## Market release +1. Inform docs team of release (or DIY) +2. Include link to our [latest release notes](https://github.com/signalfx/splunk-otel-collector/releases/) +3. Optionally include link to [latest upstream release notes](https://github.com/open-telemetry/opentelemetry-collector-contrib/releases) diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/README.md b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/README.md new file mode 100644 index 0000000000..3c0971ee23 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/README.md @@ -0,0 +1,144 @@ +# Splunk Add-on for OpenTelemetry Collector + +This technical add-on for Splunk Universal Forwarder helps in deploying the OpenTelemetry Collector alongside Universal Forwarder. + +Splunk Add-on for OpenTelemetry Collector is supported on Linux and Windows on `amd64` (`x86_64`) + +## Contents + +The package contains the following folders and files - + +------------| + |------windows_x86_64 + +------------| + |------linux_x86_64 + +------------| + |------README + +------------| + |------default + +------------| + |------configs + +------------| + |------README.md + + +The Windows and Linux folders contain platform specific binaries. The default folder contains the `app.conf` and `inputs.conf` files. The configs folder contains sample configuration files for collecting host metrics and traces using the OpenTelemetry Collector. + +## Install the add-on + +The installation process for the Splunk Add-on for OpenTelemetry Collector differs depending on the deployment method. + +### Splunk Deployment Server + +Follow these steps to install the add-on using Splunk Deployment Server: + +1. Extract the `Splunk_TA_otel.tgz` file to the `$SPLUNK_HOME/etc/deployment-apps` folder. +2. Edit the configuration files. +3. Follow the instructions for deploying apps. See https://docs.splunk.com/Documentation/Splunk/8.1.2/Updating/Updateconfigurations. +4. Make sure to activate the restart of Universal Forwarder after deployment. + +### Splunk Universal Forwarder + +To install the add-on directly on Universal Forwarder, follow these steps: + +1. Log in to Universal Forwarder. +2. Copy the tar file on the server. +3. Extract the package to the `$SPLUNK_HOME/etc/apps` folder: + +``` +tar -zxf Splunk_TA_otel.tgz +``` + +## Configure the add-on + +Before using the add-on, create a `local` folder and write the contents of your Splunk Observability Cloud access token to this file. +**WE STRONGLY RECOMMEND** that you restrict read and write to this token to the minimal possible permissions. +Alternatively, you can set the `SPLUNK_ACCESS_TOKEN` environment variable to avoid needing to write this. + +```sh +cd /opt/splunkforwarder/etc/apps/Splunk_TA_otel/ +mkdir local +cp -R config local +touch local/access_token +# make the contents of the access_token file your o11y access token. +``` + +After all the steps are completed, restart Splunk Universal Forwarder by running `$SPLUNK_HOME/bin/splunk.exe restart` + +## Configure the OpenTelemetry Collector + +To configure the OpenTelemetry Collector within the add-on, follow these steps: + +1. Create a new configuration file in YAML format for the Collector. For more information, see [Configure the Collector](https://docs.splunk.com/Observability/gdi/opentelemetry/configure-the-collector.html) in the Splunk Observability Cloud documentation. +2. Edit the inputs.conf file inside default to point to the new configuration file. +3. Restart Splunk Universal Forwarder. + +Various settings in the `inputs.conf.spec` are "pass through" [environment variables](https://github.com/signalfx/splunk-otel-collector/blob/main/internal/settings/settings.go#L37-L64) to the default splunk distribution of the opentelemetry collector's agent configuration. We do not currently pass through things related to `gateway` nor for the splunk hec related settings. That said, the binary vended in the TA is identical to upstream + +Note that we additionally configure the following environment variables in the hopes of making configuration easier. +- `$SPLUNK_OTEL_TA_HOME` References the location of the TA, ex `/opt/splunk/etc/apps/Splunk_TA_Otel` +- `$SPLUNK_OTEL_TA_PLATFORM_HOME` references the location of the platform-specific configuration for the TA, ex `/opt/splunk/etc/apps/Splunk_TA_Otel/linux_x86_64`. By default the `splunk_bundle_dir` and `splunk_collectd_dir` options in `inputs.conf` references this environment variable. + +Finally, setting `$SPLUNK_OTEL_TA_DEBUG` to anything other than an empty string will provide detailed logging messages during TA start up. + + +## Check operational status + +Both the add-on and the OpenTelemetry Collector generate log files to indicate operational status. + +You can find the log files in the `$SPLUNK_HOME/var/log/splunk/` folder. + +- The Splunk add-on log file is `Splunk_TA_otel.log`. +- By default, the OpenTelemetry Collector log file is `otel.log` (although you can override this path to whatever you please). + +## Explore metrics and traces + +You can browse the metrics and traces collected by the add-on in in Splunk Observability Cloud. See the [Splunk Observability Cloud documentation for more information](https://docs.splunk.com/Observability). + +If you're using the default configuration, you can search [metrics finder](https://docs.splunk.com/observability/en/metrics-and-metadata/metrics-finder-metadata-catalog.html#metrics-finder-and-metadata-catalog) for [`splunk.distribution:otel-ta`](https://app.signalfx.com/#/metrics?sources%5B%5D=splunk.distribution:otel-ta). + +*note*: if you're using your own configuration, *please* continue to include the telemetry in the configuration. + + +Under `processors` +``` + resource/telemetry: + attributes: + - action: insert + key: splunk.distribution + value: otel-ta +``` + +Under `receivers` +``` + # This section is used to collect the OpenTelemetry Collector metrics + # Even if just a Splunk APM customer, these metrics are included + prometheus/internal: + config: + scrape_configs: + - job_name: 'otel-collector' + scrape_interval: 10s + static_configs: + - targets: ["${env:SPLUNK_LISTEN_INTERFACE}:8888"] + metric_relabel_configs: + - source_labels: [ __name__ ] + regex: '.*grpc_io.*' + action: drop +``` + +Under `pipelines`, assuming you're using a `signalfx` exporter (only `otlp` is supported for our internal telemetry metrics) +``` + metrics/telemetry: + receivers: [prometheus/internal] + processors: [memory_limiter, batch, resourcedetection, resource/telemetry] + exporters: [signalfx] +``` + +# Binary File Declaration +`linux_x86_64/bin/otelcol_linux_amd64` +`windows_x86_64/bin/otelcol_windows_amd64.exe` diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/README/inputs.conf.spec b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/README/inputs.conf.spec new file mode 100644 index 0000000000..7fcf63a0c5 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/README/inputs.conf.spec @@ -0,0 +1,55 @@ +[Splunk_TA_otel://] + +splunk_access_token_file = +* File whose contents store the credentials to be set in `SPLUNK_ACCESS_TOKEN` (used to auth with Splunk Observability Cloud, default `$SPLUNK_OTEL_TA_HOME/local/access_token`). + +splunk_otel_log_file = +* Log file for otel collector + + +# Below are all "pass through" configuration options that will enable environment variables supported in +# https://github.com/signalfx/splunk-otel-collector/blob/main/internal/settings/settings.go#L37-L64 +gomemlimit = +* Value to use for the `GOMEMLIMIT` environment variable + +splunk_api_url = +* Value to use for the `SPLUNK_API_URL` environment variable + +splunk_bundle_dir = +* Value to use for the `SPLUNK_BUNDLE_DIR` environment variable (used in smart agent config, default `$SPLUNK_OTEL_TA_PLATFORM_HOME/bin/agent-bundle`). NOTE: Once extracted, please do not move the folder structure, as some "first-run" patching occurs that depends on the directory it was run in. Instead, allow the TA to re-extract to the new location if changed. + +splunk_collectd_dir = +* Value to use for the `SPLUNK_COLLECTD_DIR` environment variable (used in smart agent config, default `$SPLUNK_OTEL_TA_HOME/bin/agent-bundle/run/collectd`) + +splunk_config = +* Value to use for the `SPLUNK_CONFIG` environment variable (default `$SPLUNK_OTEL_TA_HOME/config/ta_agent_config.yaml`) + +splunk_config_dir = +* Value to use for the `SPLUNK_CONFIG_DIR` environment variable (default `$SPLUNK_OTEL_TA_HOME/config/`) + +splunk_debug_config_server = +* Value to use for the `SPLUNK_DEBUG_CONFIG_SERVER` environment variable + +splunk_config_yaml = +* Value to use for the `SPLUNK_CONFIG_YAML` environment variable + +splunk_listen_interface = +* Value to use for the `SPLUNK_LISTEN_INTERFACE` environment variable + +splunk_gateway_url = +* Value to use for the `SPLUNK_GATEWAY_URL` environment variable + +splunk_memory_limit_mib = +* Value to use for the `SPLUNK_MEMORY_LIMIT_MIB` environment variable + +splunk_memory_total_mib = +* Value to use for the `SPLUNK_MEMORY_TOTAL_MIB` environment variable + +splunk_trace_url = +* Endpoint for `SPLUNK_TRACE_URL` + +splunk_ingest_url = +* Endpoint for `SPLUNK_API_URL` + +splunk_realm = +* Splunk Observability realm to use for the `SPLUNK_REALM` environment variable (ex us0) diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/configs/ta-agent-config.yaml b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/configs/ta-agent-config.yaml new file mode 100644 index 0000000000..01906c05fc --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/configs/ta-agent-config.yaml @@ -0,0 +1,164 @@ +# Default configuration file for the Linux (deb/rpm) and Windows MSI collector packages + +# If the collector is installed without the Linux/Windows installer script, the following +# environment variables are required to be manually defined or configured below: +# - SPLUNK_ACCESS_TOKEN: The Splunk access token to authenticate requests +# - SPLUNK_API_URL: The Splunk API URL, e.g. https://api.us0.signalfx.com +# - SPLUNK_BUNDLE_DIR: The path to the Smart Agent bundle, e.g. /usr/lib/splunk-otel-collector/agent-bundle +# - SPLUNK_COLLECTD_DIR: The path to the collectd config directory for the Smart Agent, e.g. /usr/lib/splunk-otel-collector/agent-bundle/run/collectd +# - SPLUNK_INGEST_URL: The Splunk ingest URL, e.g. https://ingest.us0.signalfx.com +# - SPLUNK_LISTEN_INTERFACE: The network interface the agent receivers listen on. +# - SPLUNK_TRACE_URL: The Splunk trace endpoint URL, e.g. https://ingest.us0.signalfx.com/v2/trace + +extensions: + health_check: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:13133" + http_forwarder: + ingress: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6060" + egress: + endpoint: "${env:SPLUNK_API_URL}" + # Use instead when sending to gateway + smartagent: + bundleDir: "${env:SPLUNK_BUNDLE_DIR}" + collectd: + configDir: "${env:SPLUNK_COLLECTD_DIR}" + zpages: + #endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:55679" + +receivers: + fluentforward: + endpoint: 127.0.0.1:8006 + hostmetrics: + collection_interval: 10s + scrapers: + cpu: + disk: + filesystem: + memory: + network: + # System load average metrics https://en.wikipedia.org/wiki/Load_(computing) + load: + # Paging/Swap space utilization and I/O metrics + paging: + # Aggregated system process count metrics + processes: + # System processes metrics, disabled by default + # process: + jaeger: + protocols: + grpc: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:14250" + thrift_binary: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6832" + thrift_compact: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6831" + thrift_http: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:14268" + otlp: + protocols: + grpc: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:4317" + http: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:4318" + # This section is used to collect the OpenTelemetry Collector metrics + # Even if just a Splunk APM customer, these metrics are included + prometheus/internal: + config: + scrape_configs: + - job_name: 'otel-collector' + scrape_interval: 10s + static_configs: + - targets: ["${env:SPLUNK_LISTEN_INTERFACE}:8888"] + metric_relabel_configs: + - source_labels: [ __name__ ] + regex: '.*grpc_io.*' + action: drop + smartagent/processlist: + type: processlist + signalfx: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:9943" + # Whether to preserve incoming access token and use instead of exporter token + # default = false + #access_token_passthrough: true + zipkin: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:9411" + +processors: + batch: + # Enabling the memory_limiter is strongly recommended for every pipeline. + # Configuration is based on the amount of memory allocated to the collector. + # For more information about memory limiter, see + # https://github.com/open-telemetry/opentelemetry-collector/blob/main/processor/memorylimiter/README.md + memory_limiter: + check_interval: 2s + limit_mib: ${env:SPLUNK_MEMORY_LIMIT_MIB} + + # Detect if the collector is running on a cloud system, which is important for creating unique cloud provider dimensions. + # Detector order is important: the `system` detector goes last so it can't preclude cloud detectors from setting host/os info. + # Resource detection processor is configured to override all host and cloud attributes because instrumentation + # libraries can send wrong values from container environments. + # https://docs.splunk.com/Observability/gdi/opentelemetry/components/resourcedetection-processor.html#ordering-considerations + resourcedetection: + detectors: [gcp, ecs, ec2, azure, system] + override: true + + # Optional: The following processor can be used to add a default "deployment.environment" attribute to the logs and + # traces when it's not populated by instrumentation libraries. + # If enabled, make sure to enable this processor in a pipeline. + # For more information, see https://docs.splunk.com/Observability/gdi/opentelemetry/components/resource-processor.html + #resource/add_environment: + #attributes: + #- action: insert + #value: staging/production/... + #key: deployment.environment + # + # This helps splunk track usage and support of the TA + resource/telemetry: + attributes: + - action: insert + key: splunk.distribution + value: otel-ta + +exporters: + # Traces + sapm: + access_token: "${env:SPLUNK_ACCESS_TOKEN}" + endpoint: "${env:SPLUNK_TRACE_URL}" + # Metrics + Events + signalfx: + access_token: "${env:SPLUNK_ACCESS_TOKEN}" + api_url: "${env:SPLUNK_API_URL}" + ingest_url: "${env:SPLUNK_INGEST_URL}" + sync_host_metadata: true + correlation: + # Debug + logging: + verbosity: detailed + +service: + telemetry: + metrics: + address: "${env:SPLUNK_LISTEN_INTERFACE}:8888" + extensions: [health_check, http_forwarder, zpages, smartagent] + pipelines: + traces: + receivers: [jaeger, otlp, zipkin] + processors: + - memory_limiter + - batch + - resourcedetection + #- resource/add_environment + exporters: [sapm, signalfx] + metrics: + receivers: [hostmetrics, otlp, signalfx] + processors: [memory_limiter, batch, resourcedetection] + exporters: [signalfx] + logs/signalfx: + receivers: [signalfx, smartagent/processlist] + processors: [memory_limiter, batch, resourcedetection] + exporters: [signalfx] + metrics/telemetry: + receivers: [prometheus/internal] + processors: [memory_limiter, batch, resourcedetection, resource/telemetry] + exporters: [signalfx] diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/configs/ta-agent-to-gateway-config.yaml b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/configs/ta-agent-to-gateway-config.yaml new file mode 100644 index 0000000000..3871954a14 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/configs/ta-agent-to-gateway-config.yaml @@ -0,0 +1,182 @@ +# Taken as-is from https://github.com/signalfx/splunk-otel-collector/blob/main/cmd/otelcol/config/collector/agent_config.yaml +# Default configuration file for the Linux (deb/rpm) and Windows MSI collector packages + +# If the collector is installed without the Linux/Windows installer script, the following +# environment variables are required to be manually defined or configured below: +# - SPLUNK_ACCESS_TOKEN: The Splunk access token to authenticate requests +# - SPLUNK_API_URL: The Splunk API URL, e.g. https://api.us0.signalfx.com +# - SPLUNK_BUNDLE_DIR: The path to the Smart Agent bundle, e.g. /usr/lib/splunk-otel-collector/agent-bundle +# - SPLUNK_COLLECTD_DIR: The path to the collectd config directory for the Smart Agent, e.g. /usr/lib/splunk-otel-collector/agent-bundle/run/collectd +# - SPLUNK_HEC_TOKEN: The Splunk HEC authentication token +# - SPLUNK_HEC_URL: The Splunk HEC endpoint URL, e.g. https://ingest.us0.signalfx.com/v1/log +# - SPLUNK_INGEST_URL: The Splunk ingest URL, e.g. https://ingest.us0.signalfx.com +# - SPLUNK_LISTEN_INTERFACE: The network interface the agent receivers listen on. +# - SPLUNK_TRACE_URL: The Splunk trace endpoint URL, e.g. https://ingest.us0.signalfx.com:443 + +extensions: + health_check: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:13133" + http_forwarder: + ingress: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6060" + egress: + endpoint: "${env:SPLUNK_GATEWAY_URL}" + smartagent: + bundleDir: "${env:SPLUNK_BUNDLE_DIR}" + collectd: + configDir: "${env:SPLUNK_COLLECTD_DIR}" + zpages: + #endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:55679" + +receivers: + fluentforward: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:8006" + hostmetrics: + collection_interval: 10s + scrapers: + cpu: + disk: + filesystem: + memory: + network: + # System load average metrics https://en.wikipedia.org/wiki/Load_(computing) + load: + # Paging/Swap space utilization and I/O metrics + paging: + # Aggregated system process count metrics + processes: + # System processes metrics, disabled by default + # process: + jaeger: + protocols: + grpc: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:14250" + thrift_binary: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6832" + thrift_compact: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6831" + thrift_http: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:14268" + otlp: + protocols: + grpc: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:4317" + http: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:4318" + # This section is used to collect the OpenTelemetry Collector metrics + # Even if just a Splunk APM customer, these metrics are included + prometheus/internal: + config: + scrape_configs: + - job_name: 'otel-collector' + scrape_interval: 10s + static_configs: + - targets: ["${env:SPLUNK_LISTEN_INTERFACE}:8888"] + metric_relabel_configs: + - source_labels: [ __name__ ] + regex: 'otelcol_rpc_.*' + action: drop + - source_labels: [ __name__ ] + regex: 'otelcol_http_.*' + action: drop + - source_labels: [ __name__ ] + regex: 'otelcol_processor_batch_.*' + action: drop + smartagent/processlist: + type: processlist + signalfx: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:9943" + # Whether to preserve incoming access token and use instead of exporter token + # default = false + #access_token_passthrough: true + zipkin: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:9411" + +processors: + batch: + # Enabling the memory_limiter is strongly recommended for every pipeline. + # Configuration is based on the amount of memory allocated to the collector. + # For more information about memory limiter, see + # https://github.com/open-telemetry/opentelemetry-collector/blob/main/processor/memorylimiter/README.md + memory_limiter: + check_interval: 2s + limit_mib: ${env:SPLUNK_MEMORY_LIMIT_MIB} + + # Detect if the collector is running on a cloud system, which is important for creating unique cloud provider dimensions. + # Detector order is important: the `system` detector goes last so it can't preclude cloud detectors from setting host/os info. + # Resource detection processor is configured to override all host and cloud attributes because instrumentation + # libraries can send wrong values from container environments. + # https://docs.splunk.com/Observability/gdi/opentelemetry/components/resourcedetection-processor.html#ordering-considerations + resourcedetection: + detectors: [gcp, ecs, ec2, azure, system] + override: true + + # Optional: The following processor can be used to add a default "deployment.environment" attribute to the logs and + # traces when it's not populated by instrumentation libraries. + # If enabled, make sure to enable this processor in a pipeline. + # For more information, see https://docs.splunk.com/Observability/gdi/opentelemetry/components/resource-processor.html + #resource/add_environment: + #attributes: + #- action: insert + #value: staging/production/... + #key: deployment.environment + resource/telemetry: + attributes: + - action: insert + value: otel-ta-gateway-agent + key: splunk.distribution + +exporters: + # Metrics + Events + signalfx: + access_token: "${env:SPLUNK_ACCESS_TOKEN}" + api_url: http://${env:SPLUNK_GATEWAY_URL}:6060 + ingest_url: http://${env:SPLUNK_GATEWAY_URL}:9943 + sync_host_metadata: true + correlation: + # Send to gateway + otlp: + endpoint: "${env:SPLUNK_GATEWAY_URL}:4317" + tls: + insecure: true + # Debug + debug: + verbosity: detailed + +service: + telemetry: + metrics: + address: "${env:SPLUNK_LISTEN_INTERFACE}:8888" + extensions: [health_check, http_forwarder, zpages, smartagent] + pipelines: + traces: + receivers: [jaeger, otlp, zipkin] + processors: + - memory_limiter + - batch + - resourcedetection + #- resource/add_environment + exporters: [otlp, signalfx] + metrics: + receivers: [hostmetrics, otlp, signalfx] + processors: [memory_limiter, batch, resourcedetection] + exporters: [otlp] + metrics/internal: + receivers: [prometheus/internal] + processors: [memory_limiter, batch, resourcedetection, resource/telemetry] + # When sending to gateway, at least one metrics pipeline needs + # to use signalfx exporter so host metadata gets emitted + exporters: [signalfx] + logs/signalfx: + receivers: [signalfx, smartagent/processlist] + processors: [memory_limiter, batch, resourcedetection] + exporters: [signalfx] + logs: + receivers: [fluentforward, otlp] + processors: + - memory_limiter + - batch + - resourcedetection + #- resource/add_environment + exporters: [otlp] + diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/configs/ta-gateway-config.yaml b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/configs/ta-gateway-config.yaml new file mode 100644 index 0000000000..b7c2158c42 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/configs/ta-gateway-config.yaml @@ -0,0 +1,145 @@ +# Configuration file that uses the Splunk exporters (SAPM, SignalFx) to push +# data to Splunk products. + +extensions: + health_check: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:13133" + http_forwarder: + ingress: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6060" + egress: + endpoint: "https://api.${env:SPLUNK_REALM}.signalfx.com" + zpages: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:55679" + +receivers: + jaeger: + protocols: + grpc: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:14250" + thrift_binary: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6832" + thrift_compact: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6831" + thrift_http: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:14268" + otlp: + protocols: + grpc: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:4317" + http: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:4318" + # This section is used to collect the OpenTelemetry Collector metrics + # Even if just a Splunk APM customer, these metrics are included + prometheus/internal: + config: + scrape_configs: + - job_name: 'otel-collector' + scrape_interval: 10s + static_configs: + - targets: ['${env:SPLUNK_LISTEN_INTERFACE}:8888'] + metric_relabel_configs: + - source_labels: [ __name__ ] + regex: 'otelcol_rpc_.*' + action: drop + - source_labels: [ __name__ ] + regex: 'otelcol_http_.*' + action: drop + - source_labels: [ __name__ ] + regex: 'otelcol_processor_batch_.*' + action: drop + sapm: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:7276" + # Whether to preserve incoming access token and use instead of exporter token + # default = false + #access_token_passthrough: true + signalfx: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:9943" + # Whether to preserve incoming access token and use instead of exporter token + # default = false + #access_token_passthrough: true + zipkin: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:9411" + +processors: + batch: + # Enabling the memory_limiter is strongly recommended for every pipeline. + # Configuration is based on the amount of memory allocated to the collector. + # For more information about memory limiter, see + # https://github.com/open-telemetry/opentelemetry-collector/blob/main/processor/memorylimiter/README.md + memory_limiter: + check_interval: 2s + limit_mib: ${env:SPLUNK_MEMORY_LIMIT_MIB} + + # Optional: The following processor can be used to add a default "deployment.environment" attribute to the traces + # when it's not populated by instrumentation libraries. + # If enabled, make sure to enable this processor in the pipeline below. + #resource/add_environment: + #attributes: + #- action: insert + #value: staging/production/... + #key: deployment.environment + + # Detect if the collector is running on a cloud system. Overrides resource attributes set by receivers. + # Detector order is important: the `system` detector goes last so it can't preclude cloud detectors from setting host/os info. + # https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#ordering + resourcedetection/internal: + detectors: [gcp, ecs, ec2, azure, system] + override: true + + resource/telemetry: + attributes: + - action: insert + value: otel-ta-gateway-agent + key: splunk.distribution + +exporters: + # Traces + sapm: + access_token: "${env:SPLUNK_ACCESS_TOKEN}" + endpoint: "https://ingest.${env:SPLUNK_REALM}.signalfx.com/v2/trace" + sending_queue: + num_consumers: 32 + # Metrics + Events + signalfx: + access_token: "${env:SPLUNK_ACCESS_TOKEN}" + realm: "${env:SPLUNK_REALM}" + sending_queue: + num_consumers: 32 + ## Uncomment below if your agents are sending via signalfx exporter + ## to avoid double translations and exclusions. + #translation_rules: [] + #exclude_metrics: [] + signalfx/internal: + access_token: "${env:SPLUNK_ACCESS_TOKEN}" + realm: "${env:SPLUNK_REALM}" + sync_host_metadata: true + # Debug + #debug: + #verbosity: detailed + +service: + telemetry: + metrics: + address: "${env:SPLUNK_LISTEN_INTERFACE}:8888" + extensions: [health_check, http_forwarder, zpages] + pipelines: + traces: + receivers: [jaeger, otlp, sapm, zipkin] + processors: + - memory_limiter + - batch + #- resource/add_environment + exporters: [sapm] + metrics: + receivers: [otlp, signalfx] + processors: [memory_limiter, batch] + exporters: [signalfx] + metrics/internal: + receivers: [prometheus/internal] + processors: [memory_limiter, batch, resourcedetection/internal, resource/telemetry] + exporters: [signalfx/internal] + logs/signalfx: + receivers: [signalfx] + processors: [memory_limiter, batch] + exporters: [signalfx] diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/default/access_token b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/default/access_token new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/default/app.conf b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/default/app.conf new file mode 100644 index 0000000000..a1c8c7cde2 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/default/app.conf @@ -0,0 +1,28 @@ +###################################################### +# +# Splunk_TA_otel +# +# Copyright (C) 2005-2020 Splunk Inc. All Rights Reserved. +# +###################################################### + +[install] +state = enabled +is_configured = false +build = 0 + +[ui] +is_visible = false +label = Splunk Add-on for OpenTelemetry Agent + +[launcher] +author = Splunk, Inc. +description = Splunk Add-on for OpenTelemetry is used to easily deploy OpenTelemetry Agent alongside Splunk Universal Forwarder to collect traces and metrics +version = 1.3.2 + +[package] +id = Splunk_TA_otel + +[id] +name = Splunk_TA_otel +version = 1.3.2 diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/default/inputs.conf b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/default/inputs.conf new file mode 100644 index 0000000000..8f0410db35 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/default/inputs.conf @@ -0,0 +1,26 @@ +[monitor://$SPLUNK_HOME/var/log/splunk/otel.log] +_TCP_ROUTING = * +index = _internal +sourcetype = Splunk_TA_otel + +[monitor://$SPLUNK_HOME/var/log/splunk/Splunk_TA_otel.log] +_TCP_ROUTING = * +index = _internal +sourcetype = Splunk_TA_otel + +[Splunk_TA_otel://Splunk_TA_otel] +disabled=false +start_by_shell=false +interval = 60 +index = _internal +sourcetype = Splunk_TA_otel +splunk_access_token_file=$SPLUNK_OTEL_TA_HOME/local/access_token +splunk_api_url=https://api.us0.signalfx.com +splunk_bundle_dir=$SPLUNK_OTEL_TA_PLATFORM_HOME/bin/agent-bundle +splunk_collectd_dir=$SPLUNK_OTEL_TA_PLATFORM_HOME/bin/agent-bundle/run/collectd +splunk_ingest_url=https://ingest.us0.signalfx.com +splunk_trace_url=https://ingest.us0.signalfx.com/v2/trace +splunk_listen_interface=localhost +splunk_realm=us0 +splunk_config=$SPLUNK_OTEL_TA_HOME/configs/ta-agent-config.yaml +splunk_otel_log_file=$SPLUNK_HOME/var/log/splunk/otel.log diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/linux_x86_64/bin/Splunk_TA_otel.sh b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/linux_x86_64/bin/Splunk_TA_otel.sh new file mode 100755 index 0000000000..b6845bd87b --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/linux_x86_64/bin/Splunk_TA_otel.sh @@ -0,0 +1,516 @@ +#!/bin/bash + + +# script args related vars +splunk_TA_otel_num_args="$#" +splunk_TA_otel_args=("$@") +# script location and splunk app location +splunk_TA_otel_script_file=$(realpath "$0") +splunk_TA_otel_script_directory=$(dirname "${splunk_TA_otel_script_file}") +if [ -z "$SPLUNK_OTEL_TA_PLATFORM_HOME" ]; then + SPLUNK_OTEL_TA_PLATFORM_HOME="$(realpath "$splunk_TA_otel_script_directory/../")" +fi +if [ -z "$SPLUNK_OTEL_TA_HOME" ]; then + SPLUNK_OTEL_TA_HOME="$(realpath "$SPLUNK_OTEL_TA_PLATFORM_HOME/../")" +fi +if [ -z "$SPLUNK_HOME" ]; then + SPLUNK_HOME="$(realpath "$SPLUNK_OTEL_TA_HOME/../../../")" +fi + + +# Begin autogenerated code +gomemlimit_name="gomemlimit" +gomemlimit_value="" +splunk_api_url_name="splunk_api_url" +splunk_api_url_value="" +splunk_ballast_size_mib_name="splunk_ballast_size_mib" +splunk_ballast_size_mib_value="" +splunk_bundle_dir_name="splunk_bundle_dir" +splunk_bundle_dir_value="" +splunk_config_name="splunk_config" +splunk_config_value="" +splunk_config_dir_name="splunk_config_dir" +splunk_config_dir_value="" +splunk_collectd_dir_name="splunk_collectd_dir" +splunk_collectd_dir_value="" +splunk_debug_config_server_name="splunk_debug_config_server" +splunk_debug_config_server_value="" +splunk_config_yaml_name="splunk_config_yaml" +splunk_config_yaml_value="" +splunk_gateway_url_name="splunk_gateway_url" +splunk_gateway_url_value="" +splunk_hec_url_name="splunk_hec_url" +splunk_hec_url_value="" +splunk_listen_interface_name="splunk_listen_interface" +splunk_listen_interface_value="" +splunk_memory_limit_mib_name="splunk_memory_limit_mib" +splunk_memory_limit_mib_value="" +splunk_memory_total_mib_name="splunk_memory_total_mib" +splunk_memory_total_mib_value="" +splunk_trace_url_name="splunk_trace_url" +splunk_trace_url_value="" +splunk_otel_log_file_name="splunk_otel_log_file" +splunk_otel_log_file_value="" +splunk_ingest_url_name="splunk_ingest_url" +splunk_ingest_url_value="" +splunk_realm_name="splunk_realm" +splunk_realm_value="" +splunk_access_token_file_name="splunk_access_token_file" +splunk_access_token_file_value="" +# End autogenerated code + + +# otel agent related vars +splunk_otel_process_name="otelcol_linux_amd64" +splunk_TA_otel_pid="" +if [ -z "$SPLUNK_ACCESS_TOKEN" ]; then + SPLUNK_ACCESS_TOKEN="" +fi + +splunk_TA_otel_configure_traps() { + trap splunk_TA_otel_exit_func INT TERM +} + +splunk_TA_otel_exit_func() { + # called when this script is asked to exit + if [ "$splunk_TA_otel_pid" ] ; then + log_message="Stopping otel agent" + splunk_TA_otel_log_msg "INFO" "$log_message" + kill "$splunk_TA_otel_pid" + fi +} + +Splunk_TA_otel_expand_config_param() { + # Start with longest matching string and move down to least substring. + param="$1" + if [ "$(echo "$param" | grep "SPLUNK_OTEL_TA_PLATFORM_HOME")" ]; then + param="${param//\$SPLUNK_OTEL_TA_PLATFORM_HOME/$SPLUNK_OTEL_TA_PLATFORM_HOME}" + fi + if [ "$(echo "$param" | grep "SPLUNK_OTEL_TA_HOME")" ]; then + param="${param//\$SPLUNK_OTEL_TA_HOME/$SPLUNK_OTEL_TA_HOME}" + fi + if [ "$(echo "$param" | grep "SPLUNK_HOME")" ]; then + param="${param//\$SPLUNK_HOME/$SPLUNK_HOME}" + fi + + echo "$param" + + if [ "$param" ] ; then + if [ -f "$param" ] ; then + return 0 + else + return 1 + fi + fi + return 1 +} + + +splunk_TA_otel_read_configs() { + # reads configs form inputs.conf + # inputs.conf is actually rendered as a xml file here, so actually we grab everything in between tags + # inputs.conf is passed via stdin + splunk_TA_otel_log_msg "INFO" "reading config from .conf..." + while read line + do + splunk_TA_otel_log_msg "DEBUG" "line: $line" + + # Begin autogenerated code + has_gomemlimit="$(echo "$line" | grep "$gomemlimit_name")" + if [ "$has_gomemlimit" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $gomemlimit_name from line $has_gomemlimit" + gomemlimit_value="$(echo "$has_gomemlimit" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "DEBUG" "Set $gomemlimit_name to $gomemlimit_value" + fi + + has_splunk_api_url="$(echo "$line" | grep "$splunk_api_url_name")" + if [ "$has_splunk_api_url" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_api_url_name from line $has_splunk_api_url" + splunk_api_url_value="$(echo "$has_splunk_api_url" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_api_url_name to $splunk_api_url_value" + fi + + has_splunk_ballast_size_mib="$(echo "$line" | grep "$splunk_ballast_size_mib_name")" + if [ "$has_splunk_ballast_size_mib" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_ballast_size_mib_name from line $has_splunk_ballast_size_mib" + splunk_ballast_size_mib_value="$(echo "$has_splunk_ballast_size_mib" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_ballast_size_mib_name to $splunk_ballast_size_mib_value" + fi + + has_splunk_bundle_dir="$(echo "$line" | grep "$splunk_bundle_dir_name")" + if [ "$has_splunk_bundle_dir" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_bundle_dir_name from line $has_splunk_bundle_dir" + splunk_bundle_dir_value="$(echo "$has_splunk_bundle_dir" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_bundle_dir_name to $splunk_bundle_dir_value" + fi + + has_splunk_config="$(echo "$line" | grep "$splunk_config_name")" + if [ "$has_splunk_config" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_config_name from line $has_splunk_config" + splunk_config_value="$(echo "$has_splunk_config" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_config_name to $splunk_config_value" + fi + + has_splunk_config_dir="$(echo "$line" | grep "$splunk_config_dir_name")" + if [ "$has_splunk_config_dir" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_config_dir_name from line $has_splunk_config_dir" + splunk_config_dir_value="$(echo "$has_splunk_config_dir" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_config_dir_name to $splunk_config_dir_value" + fi + + has_splunk_collectd_dir="$(echo "$line" | grep "$splunk_collectd_dir_name")" + if [ "$has_splunk_collectd_dir" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_collectd_dir_name from line $has_splunk_collectd_dir" + splunk_collectd_dir_value="$(echo "$has_splunk_collectd_dir" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_collectd_dir_name to $splunk_collectd_dir_value" + fi + + has_splunk_debug_config_server="$(echo "$line" | grep "$splunk_debug_config_server_name")" + if [ "$has_splunk_debug_config_server" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_debug_config_server_name from line $has_splunk_debug_config_server" + splunk_debug_config_server_value="$(echo "$has_splunk_debug_config_server" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_debug_config_server_name to $splunk_debug_config_server_value" + fi + + has_splunk_config_yaml="$(echo "$line" | grep "$splunk_config_yaml_name")" + if [ "$has_splunk_config_yaml" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_config_yaml_name from line $has_splunk_config_yaml" + splunk_config_yaml_value="$(echo "$has_splunk_config_yaml" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_config_yaml_name to $splunk_config_yaml_value" + fi + + has_splunk_gateway_url="$(echo "$line" | grep "$splunk_gateway_url_name")" + if [ "$has_splunk_gateway_url" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_gateway_url_name from line $has_splunk_gateway_url" + splunk_gateway_url_value="$(echo "$has_splunk_gateway_url" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "DEBUG" "Set $splunk_gateway_url_name to $splunk_gateway_url_value" + fi + + has_splunk_hec_url="$(echo "$line" | grep "$splunk_hec_url_name")" + if [ "$has_splunk_hec_url" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_hec_url_name from line $has_splunk_hec_url" + splunk_hec_url_value="$(echo "$has_splunk_hec_url" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_hec_url_name to $splunk_hec_url_value" + fi + + has_splunk_listen_interface="$(echo "$line" | grep "$splunk_listen_interface_name")" + if [ "$has_splunk_listen_interface" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_listen_interface_name from line $has_splunk_listen_interface" + splunk_listen_interface_value="$(echo "$has_splunk_listen_interface" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_listen_interface_name to $splunk_listen_interface_value" + fi + + has_splunk_memory_limit_mib="$(echo "$line" | grep "$splunk_memory_limit_mib_name")" + if [ "$has_splunk_memory_limit_mib" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_memory_limit_mib_name from line $has_splunk_memory_limit_mib" + splunk_memory_limit_mib_value="$(echo "$has_splunk_memory_limit_mib" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_memory_limit_mib_name to $splunk_memory_limit_mib_value" + fi + + has_splunk_memory_total_mib="$(echo "$line" | grep "$splunk_memory_total_mib_name")" + if [ "$has_splunk_memory_total_mib" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_memory_total_mib_name from line $has_splunk_memory_total_mib" + splunk_memory_total_mib_value="$(echo "$has_splunk_memory_total_mib" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "DEBUG" "Set $splunk_memory_total_mib_name to $splunk_memory_total_mib_value" + fi + + has_splunk_trace_url="$(echo "$line" | grep "$splunk_trace_url_name")" + if [ "$has_splunk_trace_url" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_trace_url_name from line $has_splunk_trace_url" + splunk_trace_url_value="$(echo "$has_splunk_trace_url" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_trace_url_name to $splunk_trace_url_value" + fi + + has_splunk_otel_log_file_name="$(echo "$line" | grep "$splunk_otel_log_file_name")" + if [ "$has_splunk_otel_log_file_name" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_otel_log_file_name from line $has_splunk_otel_log_file_name" + splunk_otel_log_file_value="$(echo "$has_splunk_otel_log_file_name" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_otel_log_file_name to $splunk_otel_log_file_value" + fi + + has_splunk_ingest_url="$(echo "$line" | grep "$splunk_ingest_url_name")" + if [ "$has_splunk_ingest_url" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_ingest_url_name from line $has_splunk_ingest_url" + splunk_ingest_url_value="$(echo "$has_splunk_ingest_url" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_ingest_url_name to $splunk_ingest_url_value" + fi + + has_splunk_realm="$(echo "$line" | grep "$splunk_realm_name")" + if [ "$has_splunk_realm" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_realm_name from line $has_splunk_realm" + splunk_realm_value="$(echo "$has_splunk_realm" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_realm_name to $splunk_realm_value" + fi + # End autogenerated code + + # Secrets and management + has_splunk_access_token_file="$(echo "$line" | grep "$splunk_access_token_file_name")" + if [ "$has_splunk_access_token_file" ] ; then + splunk_TA_otel_log_msg "DEBUG" "reading $splunk_access_token_file_name from line $has_splunk_access_token_file" + splunk_access_token_file_value="$(echo "$has_splunk_access_token_file" | grep -Eo ">(.*?)<" | sed 's/^>\(.*\)<$/\1/')" + splunk_TA_otel_log_msg "INFO" "Set $splunk_access_token_file_name to $splunk_access_token_file_value" + fi + done < /dev/stdin +} + +is_splunk_TA_otel_agent_running() { + # checks if the otel agent is running - if running, returns 0 else returns 1 + pid="$1" + if ps -p "$pid" > /dev/null 2>&1 + then + return 0 + fi + return 1 +} + +get_access_token() { + if [ "$SPLUNK_ACCESS_TOKEN" ] ; then + splunk_TA_otel_log_msg "INFO" "Using access token in SPLUNK_ACCESS_TOKEN environment variable." + return 0 + fi + SPLUNK_ACCESS_TOKEN="$(cat "$splunk_access_token_file_value")" + if [ -n "$SPLUNK_ACCESS_TOKEN" ] ; then + splunk_TA_otel_log_msg "INFO" "Using access token from $splunk_access_token_file_value." + return 0 + else + return 1 + fi +} + +splunk_TA_otel_run_agent() { + splunk_TA_otel_log_msg "INFO" "starting agent.." + + #1 Read configs + splunk_TA_otel_read_configs + + #2 Validate configs + ## 2a expand shell variables for SPLUNK_HOME (and anything else) + + splunk_bundle_dir_value="$(Splunk_TA_otel_expand_config_param "$splunk_bundle_dir_value")" + splunk_config_value="$(Splunk_TA_otel_expand_config_param "$splunk_config_value")" + splunk_config_yaml_value="$(Splunk_TA_otel_expand_config_param "$splunk_config_yaml_value")" + splunk_collectd_dir_value="$(Splunk_TA_otel_expand_config_param "$splunk_collectd_dir_value")" + splunk_otel_log_file_value="$(Splunk_TA_otel_expand_config_param "$splunk_otel_log_file_value")" + splunk_access_token_file_value="$(Splunk_TA_otel_expand_config_param "$splunk_access_token_file_value")" + + get_access_token + if [[ $? == 1 ]] ; then + log_msg="Failed to get access token." + splunk_TA_otel_log_error "$log_msg" + fi + + #3 Control start/stop of otel agent + splunk_TA_otel_configure_traps + + log_message="Starting otel agent from $(dirname "${splunk_TA_otel_script_directory}") with configuration file $splunk_config_value and log file $splunk_otel_log_file_value" + splunk_TA_otel_log_msg "INFO" "$log_message" + + #4 Start the agent + otel_path="$splunk_TA_otel_script_directory/$splunk_otel_process_name" + if ! [ -f "$otel_path" ] ; then + splunk_TA_otel_log_error "Otel binary not found: $otel_path" + exit 1 + fi + + # Begin autogenerated code + if [ "$splunk_api_url_value" ] ; then + export SPLUNK_API_URL="$splunk_api_url_value" + else + splunk_TA_otel_log_msg "INFO" "NOT SET: $splunk_api_url_name" + fi + if [ "$splunk_ballast_size_mib_value" ] ; then + export SPLUNK_BALLAST_SIZE_MIB="$splunk_ballast_size_mib_value" + else + splunk_TA_otel_log_msg "INFO" "NOT SET: $splunk_ballast_size_mib_name" + fi + if [ "$splunk_bundle_dir_value" ] ; then + export SPLUNK_BUNDLE_DIR="$splunk_bundle_dir_value" + else + splunk_TA_otel_log_msg "INFO" "NOT SET: $splunk_bundle_dir_name" + fi + if [ "$splunk_config_value" ] ; then + export SPLUNK_CONFIG="$splunk_config_value" + else + splunk_TA_otel_log_msg "DEBUG" "NOT SET: $splunk_config_name" + fi + if [ "$splunk_config_dir_value" ] ; then + export SPLUNK_CONFIG_DIR="$splunk_config_dir_value" + else + splunk_TA_otel_log_msg "DEBUG" "NOT SET: $splunk_config_dir_name" + fi + if [ "$splunk_collectd_dir_value" ] ; then + export SPLUNK_COLLECTD_DIR="$splunk_collectd_dir_value" + else + splunk_TA_otel_log_msg "INFO" "NOT SET: $splunk_collectd_dir_name" + fi + if [ "$splunk_debug_config_server_value" ] ; then + export SPLUNK_DEBUG_CONFIG_SERVER="$splunk_debug_config_server_value" + else + splunk_TA_otel_log_msg "DEBUG" "NOT SET: $splunk_debug_config_server_name" + fi + if [ "$splunk_config_yaml_value" ] ; then + export SPLUNK_CONFIG_YAML="$splunk_config_yaml_value" + else + splunk_TA_otel_log_msg "DEBUG" "NOT SET: $splunk_config_yaml_name" + fi + if [ "$splunk_gateway_url_value" ] ; then + export SPLUNK_GATEWAY_URL="$splunk_gateway_url_value" + else + splunk_TA_otel_log_msg "INFO" "NOT SET: $splunk_gateway_url_name" + fi + if [ "$splunk_hec_url_value" ] ; then + export SPLUNK_HEC_URL="$splunk_hec_url_value" + else + splunk_TA_otel_log_msg "INFO" "NOT SET: $splunk_hec_url_name" + fi + if [ "$splunk_listen_interface_value" ] ; then + export SPLUNK_LISTEN_INTERFACE="$splunk_listen_interface_value" + else + splunk_TA_otel_log_msg "INFO" "NOT SET: $splunk_listen_interface_name" + fi + if [ "$splunk_memory_limit_mib_value" ] ; then + export SPLUNK_MEMORY_LIMIT_MIB="$splunk_memory_limit_mib_value" + else + splunk_TA_otel_log_msg "DEBUG" "NOT SET: $splunk_memory_limit_mib_name" + fi + if [ "$splunk_memory_total_mib_value" ] ; then + export SPLUNK_MEMORY_TOTAL_MIB="$splunk_memory_total_mib_value" + else + splunk_TA_otel_log_msg "DEBUG" "NOT SET: $splunk_memory_total_mib_name" + fi + if [ "$splunk_trace_url_value" ] ; then + export SPLUNK_TRACE_URL="$splunk_trace_url_value" + else + splunk_TA_otel_log_msg "INFO" "NOT SET: $splunk_trace_url_name" + fi + if [ "$splunk_otel_log_file_value" ] ; then + export SPLUNK_OTEL_LOG_FILE_NAME="$splunk_otel_log_file_value" + else + splunk_TA_otel_log_msg "INFO" "NOT SET: $splunk_otel_log_file_name" + fi + if [ "$splunk_ingest_url_value" ] ; then + export SPLUNK_INGEST_URL="$splunk_ingest_url_value" + else + splunk_TA_otel_log_msg "INFO" "NOT SET: $splunk_ingest_url_name" + fi + if [ "$splunk_realm_value" ] ; then + export SPLUNK_REALM="$splunk_realm_value" + else + splunk_TA_otel_log_msg "DEBUG" "NOT SET: $splunk_realm_name" + fi + if [ "$splunk_access_token_file_value" ] ; then + export SPLUNK_ACCESS_TOKEN_FILE="$splunk_access_token_file_value" + else + splunk_TA_otel_log_msg "INFO" "NOT SET: $splunk_access_token_file_name" + fi + # End autogenerated code + + splunk_TA_otel_log_msg "INFO" "Running as user $(whoami)" + splunk_TA_otel_log_msg "INFO" "platform home: $SPLUNK_OTEL_TA_PLATFORM_HOME" + + # Set path based on properties of set variables + if [ "$splunk_bundle_dir_value" ] ; then + # extract the agent bundle (if configured) + extract_bundle + splunk_TA_otel_log_msg "INFO" "DETECTED AGENT BUNDLE CONFIGURED, patching path (orginal: $PATH )" + PATH="$PATH:$splunk_bundle_dir_value/bin/:$splunk_bundle_dir_value/jre/bin" + splunk_TA_otel_log_msg "INFO" "DETECTED AGENT BUNDLE CONFIGURED, patched path: $PATH" + splunk_TA_otel_log_msg "DEBUG" "above is output of $SPLUNK_OTEL_TA_PLATFORM_HOME/bin/agent-bundle/bin/collectd" + # Splunkd sets LD_PRELOAD & LD_LIBRARY_PATH env vars, but they conflict + # with what the agent-bundle sets, so unset them only for this script. + LD_PRELOAD="" + LD_LIBRARY_PATH="" + fi + + + # don't export any secrets, instead do in-line + splunk_TA_otel_log_msg "INFO" "splunk_TA_otel_script_file=$splunk_TA_otel_script_file" + splunk_TA_otel_log_msg "INFO" "splunk_TA_otel_script_directory=$splunk_TA_otel_script_directory" + splunk_TA_otel_log_msg "INFO" "SPLUNK_OTEL_TA_PLATFORM_HOME=$SPLUNK_OTEL_TA_PLATFORM_HOME" + splunk_TA_otel_log_msg "INFO" "SPLUNK_OTEL_TA_HOME=$SPLUNK_OTEL_TA_HOME" + splunk_TA_otel_log_msg "INFO" "SPLUNK_HOME=$SPLUNK_HOME" + + + SPLUNK_ACCESS_TOKEN="$SPLUNK_ACCESS_TOKEN" \ + SPLUNK_HOME="$SPLUNK_HOME" \ + SPLUNK_OTEL_TA_HOME="$SPLUNK_OTEL_TA_HOME" \ + PATH="$PATH" \ + LD_PRELOAD="$LD_PRELOAD" \ + LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \ + SPLUNK_OTEL_TA_PLATFORM_HOME="$SPLUNK_OTEL_TA_PLATFORM_HOME" \ + "$otel_path" > "$splunk_otel_log_file_value" 2>&1 & + splunk_TA_otel_pid="$!" + is_splunk_TA_otel_agent_running "$splunk_TA_otel_pid" + if [[ $? == 1 ]] ; then + log_message="Failed to start otel agent" + splunk_TA_otel_log_error "$log_message" + else + log_message="Otel agent running" + splunk_TA_otel_log_msg "INFO" "$log_message" + wait $splunk_TA_otel_pid + trap - TERM INT + wait $splunk_TA_otel_pid + fi + + log_message="Otel agent stopped" + splunk_TA_otel_log_msg "INFO" "$log_message" +} + +splunk_TA_otel_scheme() { + exit 0 +} + +splunk_TA_otel_validate_args() { + exit 0 +} + +splunk_TA_otel_log_msg() { + log_type=$1 + log_msg=$2 + log_date="$(date +'%m-%d-%Y %H:%M:%S %z')" + if [[ "$log_type" != "DEBUG" ]] || [ -n "$SPLUNK_OTEL_TA_DEBUG" ] ; then + echo "$log_date" "$log_type" "$log_msg" >> "$SPLUNK_HOME/var/log/splunk/Splunk_TA_otel.log" + fi +} + +splunk_TA_otel_log_error() { + message=$1 + splunk_TA_otel_log_msg "ERROR" "$message" +} + +splunk_TA_otel_perform_actions() { + + if [[ "$splunk_TA_otel_num_args" -eq "0" ]] ; then + splunk_TA_otel_run_agent + elif [[ "${splunk_TA_otel_args[0]}" == "--scheme" ]] ; then + splunk_TA_otel_scheme + elif [[ "${splunk_TA_otel_args[0]}" == "--validate-arguments" ]] ; then + splunk_TA_otel_validate_arg + else + splunk_TA_otel_log_error "Splunk_TA_Otel received an unsupported argument" + fi +} + +extract_bundle() { + if [ -d "$SPLUNK_BUNDLE_DIR" ]; then + splunk_TA_otel_log_msg "INFO" "Agent bundle path exists on filesystem -- not attempting to extract nor patch interpreter. May still patch PATH env var." + return 0 + else + splunk_TA_otel_log_msg "INFO" "Extracting agent bundle to $SPLUNK_BUNDLE_DIR" + fi + SMART_AGENT_BUNDLE="agent-bundle_linux_amd64.tar.gz" + BUNDLE_PARENT="$(realpath --canonicalize-missing "$SPLUNK_BUNDLE_DIR/../")" + splunk_TA_otel_log_msg "DEBUG" "will cd to $BUNDLE_PARENT" + tar -C "$BUNDLE_PARENT" -xzf "$splunk_TA_otel_script_directory/$SMART_AGENT_BUNDLE" || splunk_TA_otel_log_error "failed to extract $splunk_TA_otel_script_directory/$SMART_AGENT_BUNDLE to $SPLUNK_BUNDLE_DIR" + splunk_TA_otel_log_msg "INFO" "agent bundle extracted to $SPLUNK_BUNDLE_DIR" + + # Patch everything in agent-bundle/bin to use our provided .so + root_path="$(readlink -f "$splunk_bundle_dir_value")" + "$root_path"/bin/patch-interpreter "$root_path" + +} + +echo "Starting Splunk TA Otel." + +splunk_TA_otel_perform_actions +exit 0 diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/static/appIcon.png b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/static/appIcon.png new file mode 100644 index 0000000000..a0ef506fb1 Binary files /dev/null and b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/static/appIcon.png differ diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/static/appIcon_2x.png b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/static/appIcon_2x.png new file mode 100644 index 0000000000..fd54f53a2e Binary files /dev/null and b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/static/appIcon_2x.png differ diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/windows_x86_64/bin/Splunk_TA_otel.cmd b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/windows_x86_64/bin/Splunk_TA_otel.cmd new file mode 100644 index 0000000000..a93c7960db --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/windows_x86_64/bin/Splunk_TA_otel.cmd @@ -0,0 +1,369 @@ +@echo off +:: Set inputs.conf and other configuration variables (values, input names, possibly defaults, etc) +set "splunk_TA_otel_app_directory=%~dp0" +set "splunk_otel_process_name=otelcol_windows_amd64.exe" +set "splunk_otel_common_ps_name=Splunk_TA_otel_utils.ps1" + +set "SPLUNK_OTEL_TA_HOME=" +set "SPLUNK_OTEL_TA_PLATFORM_HOME=" + + +:: BEGIN AUTOGENERATED CODE +set "gomemlimit_name=gomemlimit" +set "gomemlimit_value=" +set "splunk_api_url_name=splunk_api_url" +set "splunk_api_url_value=" +set "splunk_ballast_size_mib_name=splunk_ballast_size_mib" +set "splunk_ballast_size_mib_value=" +set "splunk_bundle_dir_name=splunk_bundle_dir" +set "splunk_bundle_dir_value=" +set "splunk_config_name=splunk_config" +set "splunk_config_value=" +set "splunk_config_dir_name=splunk_config_dir" +set "splunk_config_dir_value=" +set "splunk_collectd_dir_name=splunk_collectd_dir" +set "splunk_collectd_dir_value=" +set "splunk_debug_config_server_name=splunk_debug_config_server" +set "splunk_debug_config_server_value=" +set "splunk_config_yaml_name=splunk_config_yaml" +set "splunk_config_yaml_value=" +set "splunk_gateway_url_name=splunk_gateway_url" +set "splunk_gateway_url_value=" +set "splunk_hec_url_name=splunk_hec_url" +set "splunk_hec_url_value=" +set "splunk_listen_interface_name=splunk_listen_interface" +set "splunk_listen_interface_value=" +set "splunk_memory_limit_mib_name=splunk_memory_limit_mib" +set "splunk_memory_limit_mib_value=" +set "splunk_memory_total_mib_name=splunk_memory_total_mib" +set "splunk_memory_total_mib_value=" +set "splunk_trace_url_name=splunk_trace_url" +set "splunk_trace_url_value=" +set "splunk_otel_log_file_name=splunk_otel_log_file" +set "splunk_otel_log_file_value=" +set "splunk_ingest_url_name=splunk_ingest_url" +set "splunk_ingest_url_value=" +set "splunk_realm_name=splunk_realm" +set "splunk_realm_value=" +set "splunk_access_token_file_name=splunk_access_token_file" +set "splunk_access_token_file_value=" +:: END AUTOGENERATED CODE + + +echo on +echo "Starting Splunk TA Otel." +echo off + +:: switch based on which arg was passed +if "%1%"=="" goto splunk_TA_otel_run_agent +if "%1%"=="--scheme" goto splunk_TA_otel_scheme +if "%1%"=="--validate-arguments" goto splunk_TA_otel_validate_arg +:: exit if no matching handler for argument +exit /b + +:: main entry hooks + +:splunk_TA_otel_scheme +setlocal +echo "display scheme called" +endlocal +exit /B + +:splunk_TA_otel_validate_arg +setlocal +echo "validate args called" +endlocal +exit /B 0 + + +:splunk_TA_otel_run_agent +setlocal +:: READING CONFIGURATION FROM STDIN +call :splunk_TA_otel_read_configs + +call :splunk_TA_otel_log_msg "INFO" "Starting otel agent from %splunk_TA_otel_app_directory% with configuration file %splunk_config_value% and log file %splunk_otel_log_file_value%" +call :splunk_TA_otel_log_msg "INFO" "Logging TA notices to %splunk_TA_otel_log_file%" +:: By default, otel will register itself as a windows service. In context of the TA, we want splunk to manage our lifecycle, so turn this off. +set "NO_WINDOWS_SERVICE=1" + +if "%SPLUNK_ACCESS_TOKEN%"=="" ( + call :splunk_TA_otel_log_msg "INFO" "Grabbing SPLUNK_ACCESS_TOKEN from file %splunk_access_token_file%" + call :get_access_token +) else ( + call :splunk_TA_otel_log_msg "INFO" "Environment variable SPLUNK_ACCESS_TOKEN already set." +) + + +:: BEGIN AUTOGENERATED CODE +if "%gomemlimit_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %gomemlimit_name% not set" +) else ( + set "GOMEMLIMIT=%gomemlimit_value%" +) +if "%splunk_api_url_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_api_url_name% not set" +) else ( + set "SPLUNK_API_URL=%splunk_api_url_value%" +) +if "%splunk_ballast_size_mib_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_ballast_size_mib_name% not set" +) else ( + set "SPLUNK_BALLAST_SIZE_MIB=%splunk_ballast_size_mib_value%" +) +if "%splunk_bundle_dir_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_bundle_dir_name% not set" +) else ( + set "SPLUNK_BUNDLE_DIR=%splunk_bundle_dir_value%" +) +if "%splunk_config_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_config_name% not set" +) else ( + set "SPLUNK_CONFIG=%splunk_config_value%" +) +if "%splunk_config_dir_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_config_dir_name% not set" +) else ( + set "SPLUNK_CONFIG_DIR=%splunk_config_dir_value%" +) +if "%splunk_collectd_dir_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_collectd_dir_name% not set" +) else ( + set "SPLUNK_COLLECTD_DIR=%splunk_collectd_dir_value%" +) +if "%splunk_debug_config_server_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_debug_config_server_name% not set" +) else ( + set "SPLUNK_DEBUG_CONFIG_SERVER=%splunk_debug_config_server_value%" +) +if "%splunk_config_yaml_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_config_yaml_name% not set" +) else ( + set "SPLUNK_CONFIG_YAML=%splunk_config_yaml_value%" +) +if "%splunk_gateway_url_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_gateway_url_name% not set" +) else ( + set "SPLUNK_GATEWAY_URL=%splunk_gateway_url_value%" +) +if "%splunk_hec_url_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_hec_url_name% not set" +) else ( + set "SPLUNK_HEC_URL=%splunk_hec_url_value%" +) +if "%splunk_listen_interface_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_listen_interface_name% not set" +) else ( + set "SPLUNK_LISTEN_INTERFACE=%splunk_listen_interface_value%" +) +if "%splunk_memory_limit_mib_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_memory_limit_mib_name% not set" +) else ( + set "SPLUNK_MEMORY_LIMIT_MIB=%splunk_memory_limit_mib_value%" +) +if "%splunk_memory_total_mib_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_memory_total_mib_name% not set" +) else ( + set "SPLUNK_MEMORY_TOTAL_MIB=%splunk_memory_total_mib_value%" +) +if "%splunk_trace_url_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_trace_url_name% not set" +) else ( + set "SPLUNK_TRACE_URL=%splunk_trace_url_value%" +) +if "%splunk_otel_log_file_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_otel_log_file_name% not set" +) else ( + set "SPLUNK_OTEL_LOG_FILE=%splunk_otel_log_file_value%" +) +if "%splunk_ingest_url_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_ingest_url_name% not set" +) else ( + set "SPLUNK_INGEST_URL=%splunk_ingest_url_value%" +) +if "%splunk_realm_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_realm_name% not set" +) else ( + set "SPLUNK_REALM=%splunk_realm_value%" +) +if "%splunk_access_token_file_value%" == "" ( + call :splunk_TA_otel_log_msg "DEBUG" "Param %splunk_access_token_file_name% not set" +) else ( + set "SPLUNK_ACCESS_TOKEN_FILE=%splunk_access_token_file_value%" +) +:: END AUTOGENERATED CODE + +:: Extract agent bundle +call :extract_bundle + +set "command_line=%splunk_TA_otel_app_directory%%splunk_otel_process_name%" +start /B "" "%command_line%" > "%splunk_otel_log_file_value%" 2>&1 +set "splunk_otel_common_ps=%splunk_TA_otel_app_directory%%splunk_otel_common_ps_name%" +start /B "" /I /WAIT powershell "& '%splunk_otel_common_ps%' '%splunk_otel_process_name%' '%splunk_TA_otel_log_file%'" + +call :splunk_TA_otel_log_msg "INFO" "Otel agent stopped" +endlocal +exit /B 0 + +:: Helper functions + +:splunk_TA_otel_log_msg +setlocal +echo on +set "log_type=%~1" +set "log_msg=%~2" + +for /f "delims=" %%a in ('powershell -noninteractive -noprofile -command "get-date -format 'MM-dd-yyyy HH:mm K'"') do ( + set "log_date=%%a" +) + +if not "%log_type%%SPLUNK_OTEL_TA_DEBUG%" == "DEBUG" ( + echo "%log_date%" "%log_type%" "%log_msg%" >> "%splunk_TA_otel_log_file%" +) + +endlocal +exit /B 0 + +:splunk_TA_otel_read_configs +echo "INFO grabbing config from stdin..." + +for /F "tokens=1,2 delims==" %%I in ('powershell -noninteractive -noprofile -command "$input | Select-String -Pattern '.*?(%gomemlimit_name%|%splunk_api_url_name%|%splunk_ballast_size_mib_name%|%splunk_bundle_dir_name%|%splunk_config_name%|%splunk_config_dir_name%|%splunk_collectd_dir_name%|%splunk_debug_config_server_name%|%splunk_config_yaml_name%|%splunk_gateway_url_name%|%splunk_hec_url_name%|%splunk_listen_interface_name%|%splunk_memory_limit_mib_name%|%splunk_memory_total_mib_name%|%splunk_trace_url_name%|%splunk_otel_log_file_name%|%splunk_ingest_url_name%|%splunk_realm_name%|%splunk_access_token_file_name%|session_key).*?>(.*?)<' | ForEach-Object { $_.Matches.Groups[1].Value + '=' + $_.Matches.Groups[2].Value }"') do ( + if "%%I"=="%gomemlimit_name%" set "gomemlimit_value=%%J" + if "%%I"=="%splunk_api_url_name%" set "splunk_api_url_value=%%J" + if "%%I"=="%splunk_ballast_size_mib_name%" set "splunk_ballast_size_mib_value=%%J" + if "%%I"=="%splunk_bundle_dir_name%" set "splunk_bundle_dir_value=%%J" + if "%%I"=="%splunk_config_name%" set "splunk_config_value=%%J" + if "%%I"=="%splunk_config_dir_name%" set "splunk_config_dir_value=%%J" + if "%%I"=="%splunk_collectd_dir_name%" set "splunk_collectd_dir_value=%%J" + if "%%I"=="%splunk_config_yaml_name%" set "splunk_config_yaml_value=%%J" + if "%%I"=="%splunk_debug_config_server_name%" set "splunk_debug_config_server_value=%%J" + if "%%I"=="%splunk_gateway_url_name%" set "splunk_gateway_url_value=%%J" + if "%%I"=="%splunk_hec_url_name%" set "splunk_hec_url_value=%%J" + if "%%I"=="%splunk_listen_interface_name%" set "splunk_listen_interface_value=%%J" + if "%%I"=="%splunk_memory_limit_mib_name%" set "splunk_memory_limit_mib_value=%%J" + if "%%I"=="%splunk_memory_total_mib_name%" set "splunk_memory_total_mib_value=%%J" + if "%%I"=="%splunk_trace_url_name%" set "splunk_trace_url_value=%%J" + if "%%I"=="%splunk_otel_log_file_name%" set "splunk_otel_log_file_value=%%J" + if "%%I"=="%splunk_ingest_url_name%" set "splunk_ingest_url_value=%%J" + if "%%I"=="%splunk_realm_name%" set "splunk_realm_value=%%J" + if "%%I"=="%splunk_access_token_file_name%" set "splunk_access_token_file_value=%%J" +) +echo "INFO done grabbing configs..." + +if "%SPLUNK_OTEL_TA_PLATFORM_HOME%"=="" ( + for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "(get-item '%splunk_TA_otel_app_directory%' ).parent.FullName"') do ( + set "SPLUNK_OTEL_TA_PLATFORM_HOME=%%i" + ) +) +if "%SPLUNK_OTEL_TA_HOME%"=="" ( + for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "(get-item '%SPLUNK_OTEL_TA_PLATFORM_HOME%' ).parent.FullName"') do ( + set "SPLUNK_OTEL_TA_HOME=%%i" + ) +) +if "%SPLUNK_HOME%"=="" ( + :: Parent 3 times... $SPLUNK_HOME/etc/deployment-apps/Splunk_TA_otel + for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "(get-item '%SPLUNK_OTEL_TA_HOME%' ).parent.parent.parent.FullName"') do ( + set "SPLUNK_HOME=%%i" + ) +) else ( + echo "SPLUNK_HOME already set, reusing value: %SPLUNK_HOME%" +) + +set "splunk_TA_otel_log_file=%SPLUNK_HOME%\var\log\splunk\Splunk_TA_otel.log" +echo "otel ta log file: %splunk_TA_otel_log_file%" +call :splunk_TA_otel_log_msg "INFO" "splunk_TA_otel_app_directory: %splunk_TA_otel_app_directory%" + +:: BEGIN AUTOGENERATED CODE +:: expand params in splunk_access_token_file_value +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_access_token_file_value%' -replace '\$SPLUNK_OTEL_TA_PLATFORM_HOME', '%SPLUNK_OTEL_TA_PLATFORM_HOME%'"') do ( + set "splunk_access_token_file_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_access_token_file_value%' -replace '\$SPLUNK_OTEL_TA_HOME', '%SPLUNK_OTEL_TA_HOME%'"') do ( + set "splunk_access_token_file_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_access_token_file_value%' -replace '\$SPLUNK_HOME', '%SPLUNK_HOME%'"') do ( + set "splunk_access_token_file_value=%%i" +) + + +:: expand params in splunk_bundle_dir_value +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_bundle_dir_value%' -replace '\$SPLUNK_OTEL_TA_PLATFORM_HOME', '%SPLUNK_OTEL_TA_PLATFORM_HOME%'"') do ( + set "splunk_bundle_dir_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_bundle_dir_value%' -replace '\$SPLUNK_OTEL_TA_HOME', '%SPLUNK_OTEL_TA_HOME%'"') do ( + set "splunk_bundle_dir_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_bundle_dir_value%' -replace '\$SPLUNK_HOME', '%SPLUNK_HOME%'"') do ( + set "splunk_bundle_dir_value=%%i" +) + + +:: expand params in splunk_config_value +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_config_value%' -replace '\$SPLUNK_OTEL_TA_PLATFORM_HOME', '%SPLUNK_OTEL_TA_PLATFORM_HOME%'"') do ( + set "splunk_config_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_config_value%' -replace '\$SPLUNK_OTEL_TA_HOME', '%SPLUNK_OTEL_TA_HOME%'"') do ( + set "splunk_config_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_config_value%' -replace '\$SPLUNK_HOME', '%SPLUNK_HOME%'"') do ( + set "splunk_config_value=%%i" +) + + +:: expand params in splunk_config_dir_value +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_config_dir_value%' -replace '\$SPLUNK_OTEL_TA_PLATFORM_HOME', '%SPLUNK_OTEL_TA_PLATFORM_HOME%'"') do ( + set "splunk_config_dir_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_config_dir_value%' -replace '\$SPLUNK_OTEL_TA_HOME', '%SPLUNK_OTEL_TA_HOME%'"') do ( + set "splunk_config_dir_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_config_dir_value%' -replace '\$SPLUNK_HOME', '%SPLUNK_HOME%'"') do ( + set "splunk_config_dir_value=%%i" +) + + +:: expand params in splunk_collectd_dir_value +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_collectd_dir_value%' -replace '\$SPLUNK_OTEL_TA_PLATFORM_HOME', '%SPLUNK_OTEL_TA_PLATFORM_HOME%'"') do ( + set "splunk_collectd_dir_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_collectd_dir_value%' -replace '\$SPLUNK_OTEL_TA_HOME', '%SPLUNK_OTEL_TA_HOME%'"') do ( + set "splunk_collectd_dir_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_collectd_dir_value%' -replace '\$SPLUNK_HOME', '%SPLUNK_HOME%'"') do ( + set "splunk_collectd_dir_value=%%i" +) + + +:: expand params in splunk_config_yaml_value +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_config_yaml_value%' -replace '\$SPLUNK_OTEL_TA_PLATFORM_HOME', '%SPLUNK_OTEL_TA_PLATFORM_HOME%'"') do ( + set "splunk_config_yaml_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_config_yaml_value%' -replace '\$SPLUNK_OTEL_TA_HOME', '%SPLUNK_OTEL_TA_HOME%'"') do ( + set "splunk_config_yaml_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_config_yaml_value%' -replace '\$SPLUNK_HOME', '%SPLUNK_HOME%'"') do ( + set "splunk_config_yaml_value=%%i" +) + +:: expand params in splunk_otel_log_file_value +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_otel_log_file_value%' -replace '\$SPLUNK_OTEL_TA_PLATFORM_HOME', '%SPLUNK_OTEL_TA_PLATFORM_HOME%'"') do ( + set "splunk_otel_log_file_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_otel_log_file_value%' -replace '\$SPLUNK_OTEL_TA_HOME', '%SPLUNK_OTEL_TA_HOME%'"') do ( + set "splunk_otel_log_file_value=%%i" +) +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "'%splunk_otel_log_file_value%' -replace '\$SPLUNK_HOME', '%SPLUNK_HOME%'"') do ( + set "splunk_otel_log_file_value=%%i" +) + +:: END AUTOGENERATED CODE + +:get_access_token +set /p SPLUNK_ACCESS_TOKEN=<"%splunk_access_token_file_value%" +exit /B 0 + +:extract_bundle +call :splunk_TA_otel_log_msg "INFO" "Extract agent bundle from '%splunk_TA_otel_app_directory%\agent-bundle_windows_amd64.zip' to %splunk_bundle_dir%" +for /f "delims=" %%i in ('powershell -noninteractive -noprofile -command "if (-not (Test-Path '%splunk_bundle_dir%')) {Expand-Archive -LiteralPath '%splunk_TA_otel_app_directory%\agent-bundle_windows_amd64.zip' -Destination '%splunk_bundle_dir%\..\' -Force }"') do ( + call :splunk_TA_otel_log_msg "DEBUG" "result from extract: %%i" +) +exit /B 0 diff --git a/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/windows_x86_64/bin/Splunk_TA_otel_utils.ps1 b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/windows_x86_64/bin/Splunk_TA_otel_utils.ps1 new file mode 100755 index 0000000000..fd306c6814 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/Splunk_TA_otel/windows_x86_64/bin/Splunk_TA_otel_utils.ps1 @@ -0,0 +1,53 @@ +$otelProcessName=$args[0] +$splunkTAOtelLogFileName=$args[1] +$splunkTAOtelLogDir=Split-Path -Path $splunkTAOtelLogFileName +$splunkTAPSLogFile=Join-Path -Path $splunkTAOtelLogDir -ChildPath Splunk_TA_otelutils.log + +function otelLogWrite +{ + Param ([string]$logstring) + + Add-content $splunkTAPSLogFile -value $logstring +} + +function isOtelProcessRunning($processName) +{ + $parent = (Get-WmiObject win32_process | ? processid -eq $PID).parentprocessid + $Global:parentPid = $parent + $child = (Get-WmiObject win32_process | ? parentprocessid -eq $parent | ? processname -eq $processName).processid + $Global:otelPid = $child + $otelProcess = Get-Process -Id $child + if($otelProcess) + { + otelLogWrite "INFO Otel agent running" + return 1 + } +} + +function waitForExit($parent) +{ + Wait-Process -Id $parent +} + +function forceStopOtelProcess($processId) +{ + Stop-Process -Id $processId -Force + Start-Sleep -Seconds 1 +} + +function CheckOtelProcessStop($processId) +{ + $processInfo = Get-WmiObject win32_process | ? processid -eq $processId + if($processInfo) { + otelLogWrite "ERROR Otel agent didn't stop" + } else { + otelLogWrite "INFO Otel agent stopped" + } +} + +start-sleep -s 3 +isOtelProcessRunning($otelProcessName) + +waitForExit($parentPid) +forceStopOtelProcess($otelPid) +CheckOtelProcessStop($otelPid) \ No newline at end of file diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/collectd.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/collectd.sh new file mode 100755 index 0000000000..06ab534f91 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/collectd.sh @@ -0,0 +1,43 @@ +#!/bin/bash -eux +set -o pipefail + +# customize TA +BUILD_DIR="$(realpath "$BUILD_DIR")" + +# Set ta-agent-config.yml with mysql config +TEMP_DIR="$BUILD_DIR/ci-cd/collectd" +mkdir -p "$TEMP_DIR" +tar xzvf "$BUILD_DIR/out/distribution/Splunk_TA_otel.tgz" -C "$TEMP_DIR" +cp -r "$TEMP_DIR/Splunk_TA_otel/default/" "$TEMP_DIR/Splunk_TA_otel/local/" +echo "$OLLY_ACCESS_TOKEN" > "$TEMP_DIR/Splunk_TA_otel/local/access_token" +sed -i '/splunk_config/d' "$TEMP_DIR/Splunk_TA_otel/local/inputs.conf" +mkdir "$TEMP_DIR/Splunk_TA_otel/configs/mysql" +cp "$SOURCE_DIR/packaging-scripts/cicd-tests/mysql/ta-agent-config.yaml" "$TEMP_DIR/Splunk_TA_otel/configs/mysql" +echo "splunk_config=\$SPLUNK_OTEL_TA_HOME/configs/mysql/ta-agent-config.yaml" >> "$TEMP_DIR/Splunk_TA_otel/local/inputs.conf" +tar -C "$TEMP_DIR" -hcz -f "$TEMP_DIR/Splunk_TA_otel.tgz" "Splunk_TA_otel" + +# Create ORCA container & grab id +splunk_orca -vvv --cloud kubernetes --printer sdd-json --deployment-file "$BUILD_DIR/orca_deployment_collectd.json" --ansible-log "$BUILD_DIR/ansible-local.log" create --env SPLUNK_CONNECTION_TIMEOUT=600 --so 1 --splunk-version "${UF_VERSION}" --platform x64_centos_7 --local-apps "$BUILD_DIR/ci-cd/collectd/Splunk_TA_otel.tgz" --cloud-instance-type-mapping '{"universal_forwarder": "c5.large", "heavy_forwarder": "c5.large", "indexer": "c5.large", "eventgen_standalone": "c5.large", "testrunner": "c5.large", "license_master": "c5.large", "deployment_server": "c5.large", "deployer": "c5.large", "eventgen_server": "c5.large", "cluster_master": "c5.large", "search_head": "c5.large", "eventgen_controller": "c5.large", "standalone": "c5.large"}' --playbook "$SOURCE_DIR/packaging-scripts/orca-playbook-$PLATFORM.yml,site.yml" --custom-services "$SOURCE_DIR/packaging-scripts/orca-playbook-mysql.yml" +deployment_id="$(grep "orca_deployment_id" "$BUILD_DIR/orca_deployment_collectd.json" | awk -F ':' '{print $2}' | awk -F '"' '{print $2}')" +echo "deployment_id: $deployment_id" +splunk_orca --cloud kubernetes show containers --deployment-id "${deployment_id}" >> "$BUILD_DIR/container_details_collectd.txt" +sed -i '/custom/d' "$BUILD_DIR/container_details_collectd.txt" +orca_container=$(grep "Container Name" "$BUILD_DIR/container_details_collectd.txt" | awk -F " " '{print $8}') + +# Change to the host running mysql in the config yaml +custom_ip="$(jq -r '.server_roles.custom[0].host' "$BUILD_DIR/orca_deployment_collectd.json")" +echo "custom IP: $custom_ip" +sed -i "s/127.0.0.1/$custom_ip/g" "$TEMP_DIR/Splunk_TA_otel/configs/mysql/ta-agent-config.yaml" +splunk_orca --cloud kubernetes copy to "${orca_container}" ${ORCA_OPTION} --source "$TEMP_DIR/Splunk_TA_otel/configs/mysql/ta-agent-config.yaml" --destination /opt/splunk/etc/apps/Splunk_TA_otel/configs/mysql +splunk_orca --cloud kubernetes provision "${deployment_id}" --playbooks "$SOURCE_DIR/packaging-scripts/orca-playbook-linux-restart.yml" +sleep 90s +splunk_orca --cloud kubernetes copy from "${orca_container}" ${ORCA_OPTION} --source /opt/splunk/var/log/splunk/otel.log --destination "$BUILD_DIR/splunklog" +grep -q "Failed to connect to database mysql" "$BUILD_DIR/splunklog/otel.log" && exit 1 +grep -q "Collectd died when it was supposed to be running" "$BUILD_DIR/splunklog/otel.log" && exit 1 + +# clean up orca container +splunk_orca --cloud kubernetes destroy "${deployment_id}" + +mv "$BUILD_DIR/orca_deployment_collectd.json" "$BUILD_DIR/container_details_collectd.txt" "$BUILD_DIR/ansible-local.log" "$TEMP_DIR" +rm "$TEMP_DIR/Splunk_TA_otel.tgz" +exit 0 diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/gateway.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/gateway.sh new file mode 100755 index 0000000000..55fef13e39 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/gateway.sh @@ -0,0 +1,29 @@ +#!/bin/bash -eux +set -o pipefail + +# customize TA +BUILD_DIR="$(realpath "$BUILD_DIR")" + +# Set gateway +TEMP_DIR="$BUILD_DIR/ci-cd/gateway" +mkdir -p "$TEMP_DIR" +tar xzvf "$BUILD_DIR/out/distribution/Splunk_TA_otel.tgz" -C "$TEMP_DIR" +cp -r "$TEMP_DIR/Splunk_TA_otel/default/" "$TEMP_DIR/Splunk_TA_otel/local/" +echo "$OLLY_ACCESS_TOKEN" > "$TEMP_DIR/Splunk_TA_otel/local/access_token" +echo "splunk_config=\$SPLUNK_OTEL_TA_HOME/configs/ta-gateway-config.yaml" >> "$TEMP_DIR/Splunk_TA_otel/local/inputs.conf" +tar -C "$TEMP_DIR" -hcz -f "$TEMP_DIR/Splunk_TA_otel.tgz" "Splunk_TA_otel" + +# Set gateway +TEMP_DIR="$BUILD_DIR/ci-cd/gateway-agent" +mkdir -p "$TEMP_DIR" +tar xzvf "$BUILD_DIR/out/distribution/Splunk_TA_otel.tgz" -C "$TEMP_DIR" +cp -r "$TEMP_DIR/Splunk_TA_otel/default/" "$TEMP_DIR/Splunk_TA_otel/local/" +echo "$OLLY_ACCESS_TOKEN" > "$TEMP_DIR/Splunk_TA_otel/local/access_token" +echo "splunk_config=\$SPLUNK_OTEL_TA_HOME/configs/ta-agent-to-gateway-config.yaml" >> "$TEMP_DIR/Splunk_TA_otel/local/inputs.conf" +echo "gateway_url=localhost" >> "$TEMP_DIR/Splunk_TA_otel/local/inputs.conf" +tar -C "$TEMP_DIR" -hcz -f "$TEMP_DIR/Splunk_TA_otel_agent_to_gateway.tgz" "Splunk_TA_otel" + +splunk_orca -v --cloud kubernetes --ansible-log "$BUILD_DIR/ansible-local-gateway.log" create --env SPLUNK_CONNECTION_TIMEOUT=600 --platform x64_centos_7 --local-apps "$BUILD_DIR/ci-cd/gateway/Splunk_TA_otel.tgz" --local-apps "$BUILD_DIR/ci-cd/gateway-agent/Splunk_TA_otel_agent_to_gateway.tgz" --playbook "$SOURCE_DIR/packaging-scripts/orca-playbook-linux.yml,site.yml" +rm "$BUILD_DIR/ci-cd/gateway/Splunk_TA_otel.tgz" +rm "$TEMP_DIR/Splunk_TA_otel_agent_to_gateway.tgz" +exit 0 diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/mysql/ta-agent-config.yaml b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/mysql/ta-agent-config.yaml new file mode 100644 index 0000000000..acca70f2b4 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/mysql/ta-agent-config.yaml @@ -0,0 +1,175 @@ +# Default configuration file for the Linux (deb/rpm) and Windows MSI collector packages + +# If the collector is installed without the Linux/Windows installer script, the following +# environment variables are required to be manually defined or configured below: +# - SPLUNK_ACCESS_TOKEN: The Splunk access token to authenticate requests +# - SPLUNK_API_URL: The Splunk API URL, e.g. https://api.us0.signalfx.com +# - SPLUNK_BUNDLE_DIR: The path to the Smart Agent bundle, e.g. /usr/lib/splunk-otel-collector/agent-bundle +# - SPLUNK_COLLECTD_DIR: The path to the collectd config directory for the Smart Agent, e.g. /usr/lib/splunk-otel-collector/agent-bundle/run/collectd +# - SPLUNK_INGEST_URL: The Splunk ingest URL, e.g. https://ingest.us0.signalfx.com +# - SPLUNK_LISTEN_INTERFACE: The network interface the agent receivers listen on. +# - SPLUNK_TRACE_URL: The Splunk trace endpoint URL, e.g. https://ingest.us0.signalfx.com/v2/trace + +extensions: + health_check: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:13133" + http_forwarder: + ingress: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6060" + egress: + endpoint: "${env:SPLUNK_API_URL}" + # Use instead when sending to gateway + smartagent: + bundleDir: "${env:SPLUNK_BUNDLE_DIR}" + collectd: + configDir: "${env:SPLUNK_COLLECTD_DIR}" + zpages: + #endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:55679" + +receivers: + smartagent/mysql: + type: collectd/mysql + host: 127.0.0.1 + port: 3306 + username: root + password: password + databases: + - name: mysql + smartagent/apache: + type: collectd/apache + host: localhost + port: 80 + url: "http://localhost:80/server-status?auto" + fluentforward: + endpoint: 127.0.0.1:8006 + hostmetrics: + collection_interval: 10s + scrapers: + cpu: + disk: + filesystem: + memory: + network: + # System load average metrics https://en.wikipedia.org/wiki/Load_(computing) + load: + # Paging/Swap space utilization and I/O metrics + paging: + # Aggregated system process count metrics + processes: + # System processes metrics, disabled by default + # process: + jaeger: + protocols: + grpc: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:14250" + thrift_binary: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6832" + thrift_compact: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:6831" + thrift_http: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:14268" + otlp: + protocols: + grpc: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:4317" + http: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:4318" + # This section is used to collect the OpenTelemetry Collector metrics + # Even if just a Splunk APM customer, these metrics are included + prometheus/internal: + config: + scrape_configs: + - job_name: 'otel-collector' + scrape_interval: 10s + static_configs: + - targets: ["${env:SPLUNK_LISTEN_INTERFACE}:8888"] + metric_relabel_configs: + - source_labels: [ __name__ ] + regex: '.*grpc_io.*' + action: drop + signalfx: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:9943" + # Whether to preserve incoming access token and use instead of exporter token + # default = false + #access_token_passthrough: true + zipkin: + endpoint: "${env:SPLUNK_LISTEN_INTERFACE}:9411" + +processors: + batch: + # Enabling the memory_limiter is strongly recommended for every pipeline. + # Configuration is based on the amount of memory allocated to the collector. + # For more information about memory limiter, see + # https://github.com/open-telemetry/opentelemetry-collector/blob/main/processor/memorylimiter/README.md + memory_limiter: + check_interval: 2s + limit_mib: ${env:SPLUNK_MEMORY_LIMIT_MIB} + + # Detect if the collector is running on a cloud system, which is important for creating unique cloud provider dimensions. + # Detector order is important: the `system` detector goes last so it can't preclude cloud detectors from setting host/os info. + # Resource detection processor is configured to override all host and cloud attributes because instrumentation + # libraries can send wrong values from container environments. + # https://docs.splunk.com/Observability/gdi/opentelemetry/components/resourcedetection-processor.html#ordering-considerations + resourcedetection: + detectors: [gcp, ecs, ec2, azure, system] + override: true + + # Optional: The following processor can be used to add a default "deployment.environment" attribute to the logs and + # traces when it's not populated by instrumentation libraries. + # If enabled, make sure to enable this processor in a pipeline. + # For more information, see https://docs.splunk.com/Observability/gdi/opentelemetry/components/resource-processor.html + #resource/add_environment: + #attributes: + #- action: insert + #value: staging/production/... + #key: deployment.environment + # + # This helps splunk track usage and support of the TA + resource/telemetry: + attributes: + - action: insert + key: splunk.distribution + value: otel-ta + +exporters: + # Traces + sapm: + access_token: "${env:SPLUNK_ACCESS_TOKEN}" + endpoint: "${env:SPLUNK_TRACE_URL}" + # Metrics + Events + signalfx: + access_token: "${env:SPLUNK_ACCESS_TOKEN}" + api_url: "${env:SPLUNK_API_URL}" + ingest_url: "${env:SPLUNK_INGEST_URL}" + sync_host_metadata: true + correlation: + # Debug + logging: + verbosity: detailed + +service: + telemetry: + metrics: + address: "${env:SPLUNK_LISTEN_INTERFACE}:8888" + extensions: [health_check, http_forwarder, zpages, smartagent] + pipelines: + traces: + receivers: [jaeger, otlp, zipkin] + processors: + - memory_limiter + - batch + - resourcedetection + #- resource/add_environment + exporters: [sapm, signalfx] + metrics: + receivers: [hostmetrics, otlp, signalfx] + processors: [memory_limiter, batch, resourcedetection] + exporters: [signalfx] + metrics/loggingcollectd: + receivers: ["smartagent/apache", "smartagent/mysql"] + processors: [memory_limiter, batch, resourcedetection] + exporters: [logging, signalfx] + metrics/telemetry: + receivers: [prometheus/internal] + processors: [memory_limiter, batch, resourcedetection, resource/telemetry] + exporters: [signalfx] diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/nginx.yml b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/nginx.yml new file mode 100644 index 0000000000..79da50672d --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cicd-tests/nginx.yml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: nginx + annotations: + com.splunk.orca.customservice.hostname: nginx + com.splunk.orca.customservice.ssh_enabled: "true" + com.splunk.orca.customservice.ssh_users: "splunk,ansible,root" +spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 + diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/cspell/cspell.json b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cspell/cspell.json new file mode 100644 index 0000000000..5a7d19d877 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cspell/cspell.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", + "version": "0.3", + "dictionaryDefinitions": [ + { + "name": "project-words", + "path": "./project-words.txt", + "addWords": true + } + ], + "dictionaries": ["project-words"], + "ignorePaths": ["node_modules", "./project-words.txt"] +} diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/cspell/project-words.txt b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cspell/project-words.txt new file mode 100644 index 0000000000..e8082ad7d8 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/cspell/project-words.txt @@ -0,0 +1,9 @@ +collectd +opentelemetry +otel +otelcol +otlp +resourcedetection +signalfx +splunkbase +splunkforwarder diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/delete-ta-version.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/delete-ta-version.sh new file mode 100755 index 0000000000..370511ea04 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/delete-ta-version.sh @@ -0,0 +1,17 @@ +#!/bin/bash -eux + +echo "THIS COMMAND SHOULD ONLY BE RUN ON A NON-PUBLICLY-RELEASED TAG VERSION" + +APP_CONFIG="$BUILD_DIR/Splunk_TA_otel/default/app.conf" +if ! [ -f "$APP_CONFIG" ]; then + echo "file $APP_CONFIG not found" + exit 1 +fi + +TA_VERSION="$(sed -n 's/^version = \(.*$\)/\1/p' "$APP_CONFIG" | head -n 1)" +[[ -z "$TA_VERSION" ]] && exit 1 + +echo "DELETING TAG+BRANCH (release/)v$TA_VERSION FROM LOCAL AND ORIGIN (if exists)" +git tag --delete "v$TA_VERSION" || true +git push --delete origin "v$TA_VERSION" || true +git push --delete origin "release/v$TA_VERSION" || true diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/deploy-and-verify.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/deploy-and-verify.sh new file mode 100755 index 0000000000..d5385c66f3 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/deploy-and-verify.sh @@ -0,0 +1,100 @@ +#!/bin/bash -eux + +set -o pipefail + +# Grab artifact from the build stage, add token and run the tests in orca container +cd "$BUILD_DIR" +tar xzf "$BUILD_DIR/out/distribution/Splunk_TA_otel.tgz" +cd "Splunk_TA_otel" +cp -r default/ local/ +echo "$OLLY_ACCESS_TOKEN" >> "local/access_token" + +# Re-package it & clean up +cd "-" +mkdir -p "$BUILD_DIR/ci-cd" +if [ "$PLATFORM" == "windows" ]; then + rm -Rf "./Splunk_TA_otel/linux_x86_64" +elif [ "$PLATFORM" == "linux" ]; then + rm -Rf "./Splunk_TA_otel/windows_x86_64" +fi +tar -czvf "$BUILD_DIR/ci-cd/Splunk_TA_otel.tgz" "./Splunk_TA_otel" + +# Create ORCA container & grab id +splunk_orca -vvv --cloud ${ORCA_CLOUD} --printer sdd-json --deployment-file "$BUILD_DIR/orca_deployment.json" --ansible-log ansible-local.log create --env SPLUNK_CONNECTION_TIMEOUT=600 --so 1 --splunk-version "${UF_VERSION}" --platform "${SPLUNK_PLATFORM}" --local-apps "$BUILD_DIR/ci-cd/Splunk_TA_otel.tgz" --cloud-instance-type-mapping '{"universal_forwarder": "c5.large", "heavy_forwarder": "c5.large", "indexer": "c5.large", "eventgen_standalone": "c5.large", "testrunner": "c5.large", "license_master": "c5.large", "deployment_server": "c5.large", "deployer": "c5.large", "eventgen_server": "c5.large", "cluster_master": "c5.large", "search_head": "c5.large", "eventgen_controller": "c5.large", "standalone": "c5.large"}' --playbook "$SOURCE_DIR/packaging-scripts/orca-playbook-$PLATFORM.yml,site.yml" +deployment_id="$(grep "orca_deployment_id" "$BUILD_DIR/orca_deployment.json" | awk -F ':' '{print $2}' | awk -F '"' '{print $2}')" +echo "deployment_id: $deployment_id" +splunk_orca --cloud ${ORCA_CLOUD} show containers --deployment-id "${deployment_id}" >> "$BUILD_DIR/container_details.txt" +orca_container=$(grep "Container Name" "$BUILD_DIR/container_details.txt" | awk -F " " '{print $8}') + +if [ "$PLATFORM" == "windows" ]; then + # Windows takes forever to extract + sleep 700s +else + # Can likely drop this way down, but give the collector time to collect metrics/traces + sleep 90s +fi + + +# Copy logs from container +mkdir -p "$BUILD_DIR"/splunklog +splunk_orca --cloud "${ORCA_CLOUD}" copy from "${orca_container}" ${ORCA_OPTION} --source /opt/splunk/var/log/splunk/ --destination "$BUILD_DIR/splunklog" +set +u +if [ -n "$SPLUNK_OTEL_TA_DEBUG" ]; then + set -u + mkdir "$BUILD_DIR/otel-ta-deployment" + splunk_orca --cloud "${ORCA_CLOUD}" copy from "${orca_container}" ${ORCA_OPTION} --source /opt/splunk/etc/apps/Splunk_TA_otel/ --destination "$BUILD_DIR/otel-ta-deployment/Splunk_TA_otel" +fi +set -u + +# Verify Otel agent is running without any error +grep -q "Starting otel agent" "$BUILD_DIR/splunklog/splunk/Splunk_TA_otel.log" +grep -q "Everything is ready" "$BUILD_DIR/splunklog/splunk/otel.log" +(grep -qi "ERROR" "$BUILD_DIR/splunklog/splunk/Splunk_TA_otel.log" && exit 1 ) || true +(grep -qi "ERROR" "$BUILD_DIR/splunklog/splunk/otel.log" && exit 1 ) || true + +# Verify Olly has received metrics data from this host +otel_hostname="$(grep "host.name" "$BUILD_DIR/splunklog/splunk/otel.log" | head -1 | awk -F 'host.name":"' '{print $2}' | awk -F '","' '{print $1}')" +echo "otel hostname: $otel_hostname" +#curl --header "Content-Type:application/json" --header "X-SF-TOKEN:${OLLY_ACCESS_TOKEN}" "https://api.us0.signalfx.com/v2/metrictimeseries?query=host.name:${otel_hostname}%20AND%20sf_metric:cpu_utilization%20AND%20sf_lastActiveMs:%3E%3D$(date '+%s%3N' -d '5 min ago')" > cpu_util.json +curl --header "Content-Type:application/json" --header "X-SF-TOKEN:${OLLY_ACCESS_TOKEN}" "https://api.us0.signalfx.com/v2/metrictimeseries?query=host.name:${otel_hostname}%20AND%20sf_metric:cpu.utilization" > cpu_util.json +count=$(grep '"count"' cpu_util.json | awk -F ':\ ' '{print $2}' | awk -F ',' '{print $1}') +echo $count +[[ "$count" -eq "0" ]] && echo "Test failed -- could not find cpu utilization metrics" && exit 1 +CUTOFF="$(date '+%s%3N' -d '5 min ago')" +export CUTOFF +jq '[.results[].created, .results[].lastUpdated] | max as $max | $max >= ($ENV.CUTOFF | tonumber)' cpu_util.json + +# Verify the current otel process was killed by PID by restarting splunk +if [ "$PLATFORM" == "windows" ]; then + splunk_orca --cloud "${ORCA_CLOUD}" provision "${deployment_id}" --playbooks "$SOURCE_DIR/packaging-scripts/orca-playbook-$PLATFORM-restart.yml" + splunk_orca --cloud "${ORCA_CLOUD}" copy from "${orca_container}" ${ORCA_OPTION} --source /opt/splunk/var/log/splunk/Splunk_TA_otelutils.log --destination "$BUILD_DIR/splunklog" + grep -q "INFO Otel agent stopped" "$BUILD_DIR/splunklog/Splunk_TA_otelutils.log" || exit 1 +elif [ "$PLATFORM" == "linux" ]; then + splunk_orca --cloud "${ORCA_CLOUD}" provision "${deployment_id}" --playbooks "$SOURCE_DIR/packaging-scripts/orca-playbook-$PLATFORM-restart.yml" + splunk_orca --cloud "${ORCA_CLOUD}" copy from "${orca_container}" ${ORCA_OPTION} --source /opt/splunk/var/log/splunk/Splunk_TA_otel.log --destination "$BUILD_DIR/splunklog" + grep -q "Otel agent stopped" "$BUILD_DIR/splunklog/Splunk_TA_otel.log" || exit 1 +fi + +# clean up orca container +splunk_orca --cloud ${ORCA_CLOUD} destroy "${deployment_id}" + +# Ensure telemetry is coming along +curl --header "Content-Type:application/json" --header "X-SF-TOKEN:${OLLY_ACCESS_TOKEN}" "https://api.us0.signalfx.com/v2/metrictimeseries?query=host.name:${otel_hostname}%20AND%20sf_metric:otelcol_process_uptime%20AND%20splunk.distribution:otel-ta" > uptime.json +count=$( grep '"count"' uptime.json | awk -F ':\ ' '{print $2}' | awk -F ',' '{print $1}') +echo $count +[[ "$count" -eq "0" ]] && echo "Test failed -- could not find uptime metrics" && exit 1 +jq '[.results[].created, .results[].lastUpdated] | max as $max | $max >= ($ENV.CUTOFF | tonumber)' uptime.json + +# Ensure version is as expected +actual_version="$(grep "Version" "$BUILD_DIR/splunklog/splunk/otel.log" | head -1 | awk -F 'Version": "' '{print $2}' | awk -F '", "' '{print $1}')" +echo "actual version: $actual_version" +[[ "$actual_version" != "v0.104.0" ]] && echo "Test failed -- invalid version" && exit 1 + +# Ensure gateway mode (and any other tests we wish to run) works +"$SOURCE_DIR/packaging-scripts/cicd-tests/gateway.sh" || (echo "failed to verify gateway" && exit 1) + +if [ "$PLATFORM" == "linux" ]; then + "$SOURCE_DIR/packaging-scripts/cicd-tests/collectd.sh" || (echo "failed to verify collectd" && exit 1) +fi + +exit 0 diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/download-release.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/download-release.sh new file mode 100755 index 0000000000..210df3038b --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/download-release.sh @@ -0,0 +1,51 @@ +#!/bin/bash -eux +set -o pipefail + +[[ -z "$SPLUNK_OTELCOL_DOWNLOAD_BASE" ]] && echo "SPLUNK_OTELCOL_DOWNLOAD_BASE not set" && exit 1 + +# Download collector & make it executable +if [ "$PLATFORM" == "windows" ] || [ "$PLATFORM" == "all" ]; then + COLLECTOR_BINARY="otelcol_windows_$ARCH.exe" + URL="$SPLUNK_OTELCOL_DOWNLOAD_BASE/v$OTEL_COLLECTOR_VERSION/$COLLECTOR_BINARY" + mkdir -p "$BUILD_DIR/out/bin" + OUTPUT_PATH="$BUILD_DIR/out/bin/$COLLECTOR_BINARY" + if ! [ -f "$OUTPUT_PATH" ]; then + wget "$URL" --output-document "$OUTPUT_PATH" + fi + chmod +x "$OUTPUT_PATH" + echo "SAVED $COLLECTOR_BINARY TO $OUTPUT_PATH" +fi +if [ "$PLATFORM" == "linux" ] || [ "$PLATFORM" == "all" ]; then + COLLECTOR_BINARY="otelcol_linux_$ARCH" + URL="$SPLUNK_OTELCOL_DOWNLOAD_BASE/v$OTEL_COLLECTOR_VERSION/$COLLECTOR_BINARY" + mkdir -p "$BUILD_DIR/out/bin" + OUTPUT_PATH="$BUILD_DIR/out/bin/$COLLECTOR_BINARY" + if ! [ -f "$OUTPUT_PATH" ]; then + wget "$URL" --output-document "$OUTPUT_PATH" + fi + chmod +x "$OUTPUT_PATH" + echo "SAVED $COLLECTOR_BINARY TO $OUTPUT_PATH" +fi + + +# Download smart agent +if [ "$PLATFORM" == "windows" ] || [ "$PLATFORM" == "all" ]; then + SMART_AGENT_BUNDLE="agent-bundle_${OTEL_COLLECTOR_VERSION}_windows_${ARCH}.zip" + URL="$SPLUNK_OTELCOL_DOWNLOAD_BASE/v$OTEL_COLLECTOR_VERSION/$SMART_AGENT_BUNDLE" + mkdir -p "$BUILD_DIR/out/smart-agent/" + OUTPUT_PATH="$BUILD_DIR/out/smart-agent/$SMART_AGENT_BUNDLE" + if ! [ -f "$OUTPUT_PATH" ]; then + wget "$URL" --output-document "$OUTPUT_PATH" + fi + echo "SAVED $SMART_AGENT_BUNDLE TO $OUTPUT_PATH" +fi +if [ "$PLATFORM" == "linux" ] || [ "$PLATFORM" == "all" ]; then + SMART_AGENT_BUNDLE="agent-bundle_${OTEL_COLLECTOR_VERSION}_linux_${ARCH}.tar.gz" + URL="$SPLUNK_OTELCOL_DOWNLOAD_BASE/v$OTEL_COLLECTOR_VERSION/$SMART_AGENT_BUNDLE" + mkdir -p "$BUILD_DIR/out/smart-agent/" + OUTPUT_PATH="$BUILD_DIR/out/smart-agent/$SMART_AGENT_BUNDLE" + if ! [ -f "$OUTPUT_PATH" ]; then + wget "$URL" --output-document "$OUTPUT_PATH" + fi + echo "SAVED $SMART_AGENT_BUNDLE TO $OUTPUT_PATH" +fi diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/env/all.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/env/all.sh new file mode 100755 index 0000000000..2362c5df37 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/env/all.sh @@ -0,0 +1,7 @@ +#!/bin/bash -eux +set -o pipefail + +[[ -z "$BUILD_DIR" ]] && echo "BUILD_DIR not set" && exit 1 +[[ -z "$SOURCE_DIR" ]] && echo "SOURCE_DIR not set" && exit 1 + +exit 0 diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/env/ta.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/env/ta.sh new file mode 100755 index 0000000000..4d32837b1e --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/env/ta.sh @@ -0,0 +1,8 @@ +#!/bin/bash -eux +set -o pipefail + +[[ -z "$PLATFORM" ]] && echo "PLATFORM not set" && exit 1 +[[ -z "$ARCH" ]] && echo "ARCH not set" && exit 1 +[[ -z "$OTEL_COLLECTOR_VERSION" ]] && echo "OTEL_COLLECTOR_VERSION not set" && exit 1 + +exit 0 diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/env/verify.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/env/verify.sh new file mode 100755 index 0000000000..6034aa87c8 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/env/verify.sh @@ -0,0 +1,8 @@ +#!/bin/bash -eux +set -o pipefail + +[[ -z "$ORCA_CLOUD" ]] && echo "ORCA_CLOUD not set" && exit 1 +[[ -z "$UF_VERSION" ]] && echo "UF_VERSION not set" && exit 1 +[[ -z "$OLLY_ACCESS_TOKEN" ]] && echo "OLLY_ACCESS_TOKEN not set" && exit 1 + +exit 0 diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/make-buildspace.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/make-buildspace.sh new file mode 100755 index 0000000000..a49b77d9c9 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/make-buildspace.sh @@ -0,0 +1,7 @@ +#!/bin/bash -eux +set -o pipefail + +mkdir -p "$BUILD_DIR" +cp -R "$SOURCE_DIR/Splunk_TA_otel" "$BUILD_DIR" +ls -lAh "$BUILD_DIR" +ls -lAh "$BUILD_DIR/Splunk_TA_otel" diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-linux-restart.yml b/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-linux-restart.yml new file mode 100644 index 0000000000..18ec5db33c --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-linux-restart.yml @@ -0,0 +1,15 @@ +- hosts: all:!orca_role_custom:!orca_role_testrunner + gather_facts: false + become: yes + vars: + splunk: + user: root + home: /opt/splunk + exec: /opt/splunk/bin/splunk + tasks: + #Issue a splunk restart + - name: Restart the splunkd service + command: "{{splunk.exec}} restart" + environment: + HOME: "{{splunk.home}}" + ignore_errors: true diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-linux.yml b/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-linux.yml new file mode 100644 index 0000000000..1a6a20cda5 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-linux.yml @@ -0,0 +1,8 @@ +- hosts: all:!orca_role_custom:!orca_role_testrunner + become: yes + tasks: + - name: Change timeout in splunk-ansible + replace: + path: /opt/ansible/roles/splunk_common/tasks/install_apps.yml + regexp: 'timeout: 90' + replace: 'timeout: 180' diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-mysql.yml b/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-mysql.yml new file mode 100644 index 0000000000..8d6ec00a66 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-mysql.yml @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: Pod +metadata: + name: mysql + hostname: mysql + annotations: + com.splunk.orca.customservice.hostname: mysqlpl + com.splunk.orca.customservice.ssh_enabled: "true" + com.splunk.orca.customservice.ssh_users: "splunk,ansible,root" +spec: + ports: + - containerPort: 3306 + protocol: TCP + containers: + - image: mysql:5.7 + name: mysql + env: + - name: MYSQL_ROOT_PASSWORD + value: password + ports: + - containerPort: 3306 + protocol: TCP diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-windows-restart.yml b/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-windows-restart.yml new file mode 100644 index 0000000000..3740e17faa --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-windows-restart.yml @@ -0,0 +1,16 @@ +- hosts: all:!orca_role_custom:!orca_role_testrunner + gather_facts: false + become: yes + become_method: runas + become_user: Administrator + vars: + splunk: + home: /opt/splunk + exec: /opt/splunk/bin/splunk + tasks: + #Issue a splunk restart + - name: Restart the splunkd service + command: "{{splunk.exec}} restart" + environment: + HOME: "{{splunk.home}}" + ignore_errors: true \ No newline at end of file diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-windows.yml b/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-windows.yml new file mode 100644 index 0000000000..30a2fa282a --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/orca-playbook-windows.yml @@ -0,0 +1,10 @@ +- hosts: all:!orca_role_custom:!orca_role_testrunner + become: yes + become_method: runas + become_user: Administrator + tasks: + - name: Change timeout in splunk-ansible + replace: + path: /opt/ansible/roles/splunk_common/tasks/install_apps.yml + regexp: 'timeout: 90' + replace: 'timeout: 1000' diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/package-ta.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/package-ta.sh new file mode 100755 index 0000000000..642640f241 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/package-ta.sh @@ -0,0 +1,56 @@ +#!/bin/bash -eux +set -o pipefail + +TA_NAME="Splunk_TA_otel" + +if [ "$ARCH" == "amd64" ]; then + SPLUNK_ARCH="x86_64" +else + echo "Attempted to package unknown or unsupported architecture: $ARCH" + exit 1 +fi + +TA_PACKAGING_DIR="$BUILD_DIR/out/$ARCH" +mkdir -p "$TA_PACKAGING_DIR/$TA_NAME" +# Copy config files into addon package directory +cp -rp "$BUILD_DIR/$TA_NAME/default" "$TA_PACKAGING_DIR/$TA_NAME/" +cp -rp "$BUILD_DIR/$TA_NAME/configs" "$TA_PACKAGING_DIR/$TA_NAME/" +cp -rp "$BUILD_DIR/$TA_NAME/README" "$TA_PACKAGING_DIR/$TA_NAME/" +cp -rp "$BUILD_DIR/$TA_NAME/README.md" "$TA_PACKAGING_DIR/$TA_NAME/" +cp -rp "$BUILD_DIR/$TA_NAME/static" "$TA_PACKAGING_DIR/$TA_NAME/" + +# Copy collector into addon package directory +if [ "$PLATFORM" == "windows" ] || [ "$PLATFORM" == "all" ] ; then + COLLECTOR_BINARY="otelcol_windows_$ARCH.exe" + cp -rp "$BUILD_DIR/$TA_NAME/windows_$SPLUNK_ARCH" "$TA_PACKAGING_DIR/$TA_NAME/" + cp -rp "$BUILD_DIR/out/bin/$COLLECTOR_BINARY" "$TA_PACKAGING_DIR/$TA_NAME/windows_$SPLUNK_ARCH/bin/$COLLECTOR_BINARY" +fi +if [ "$PLATFORM" == "linux" ] || [ "$PLATFORM" == "all" ] ; then + COLLECTOR_BINARY="otelcol_linux_$ARCH" + cp -rp "$BUILD_DIR/$TA_NAME/linux_$SPLUNK_ARCH" "$TA_PACKAGING_DIR/$TA_NAME/" + cp -rp "$BUILD_DIR/out/bin/$COLLECTOR_BINARY" "$TA_PACKAGING_DIR/$TA_NAME/linux_$SPLUNK_ARCH/bin/$COLLECTOR_BINARY" +fi +if [ "$PLATFORM" == "darwin" ] ; then # NOTE Darwin not used yet + COLLECTOR_BINARY="otelcol_darwin_$ARCH" + cp -rp "$BUILD_DIR/$TA_NAME/darwin_$SPLUNK_ARCH" "$TA_PACKAGING_DIR/$TA_NAME/" + cp -rp "$BUILD_DIR/out/bin/$COLLECTOR_BINARY" "$TA_PACKAGING_DIR/$TA_NAME/darwin_$SPLUNK_ARCH/bin/$COLLECTOR_BINARY" +fi + +# Copy smart agent bundle into addon package directory +if [ "$PLATFORM" == "windows" ] || [ "$PLATFORM" == "all" ] ; then + SMART_AGENT_BUNDLE="agent-bundle_${OTEL_COLLECTOR_VERSION}_windows_${ARCH}.zip" + cp "$BUILD_DIR/out/smart-agent/$SMART_AGENT_BUNDLE" "$TA_PACKAGING_DIR/$TA_NAME/windows_$SPLUNK_ARCH/bin/agent-bundle_windows_${ARCH}.zip" +fi +if [ "$PLATFORM" == "linux" ] || [ "$PLATFORM" == "all" ] ; then + SMART_AGENT_BUNDLE="agent-bundle_${OTEL_COLLECTOR_VERSION}_linux_${ARCH}.tar.gz" + cp "$BUILD_DIR/out/smart-agent/$SMART_AGENT_BUNDLE" "$TA_PACKAGING_DIR/$TA_NAME/linux_$SPLUNK_ARCH/bin/agent-bundle_linux_${ARCH}.tar.gz" +fi + +# Prepare artifact directory structure +DEST_DIR="$BUILD_DIR/out/distribution/" +mkdir -p "$DEST_DIR" + +# Package addon into artifact directory +OUT_DIR="$(realpath "$DEST_DIR")" +echo "creating tarball at $OUT_DIR/Splunk_TA_otel.tgz" +COPYFILE_DISABLE=1 tar -C "$TA_PACKAGING_DIR" -hcz --exclude '*.DS_Store' -f "$OUT_DIR/$TA_NAME.tgz" "$TA_NAME" diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/release-ta-version.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/release-ta-version.sh new file mode 100755 index 0000000000..e26807bb1c --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/release-ta-version.sh @@ -0,0 +1,18 @@ +#!/bin/bash -eux +# Get versions +APP_CONFIG="$SOURCE_DIR/Splunk_TA_otel/default/app.conf" +TA_VERSION="$(sed -n 's/^version = \(.*$\)/\1/p' "$APP_CONFIG" | head -n 1)" +SPLUNK_OTEL_VERSION="$(sed -n 's/^OTEL_COLLECTOR_VERSION?=\(.*$\)/\1/p' "Makefile" | head -n 1)" + +echo "Will create a new release for $TA_VERSION using splunk otel collector $SPLUNK_OTEL_VERSION" + +# create new git branch and tag +git checkout -B "release/v$TA_VERSION" +git add Makefile "$APP_CONFIG" +git commit -m "Updates TA to splunk-otel-collector v$SPLUNK_OTEL_VERSION and marks TA as v$TA_VERSION" || echo "version changes already comitted" + + +echo "Pushing to remote..." +git tag --annotate --sign --message "Version v$TA_VERSION" "v$TA_VERSION" +git push --set-upstream origin "release/v$TA_VERSION" +git push origin "v$TA_VERSION" diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/update-otel-version.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/update-otel-version.sh new file mode 100755 index 0000000000..c2381d42e5 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/update-otel-version.sh @@ -0,0 +1,25 @@ +#!/bin/bash -eux +# See https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#get-the-latest-release +#curl -s https://api.github.com/repos/signalfx/splunk-otel-collector/releases/latest + +# -H "Authorization: Bearer " \ +#curl -L \ +# -H "Accept: application/vnd.github+json" \ +# -H "X-GitHub-Api-Version: 2022-11-28" \ +# https://api.github.com/repos/signalfx/splunk-otel-collector/releases/latest +# Needs jq installed + +# Jq exists in brew and in all standard splunk ci-container's + +#### First, update otel version + +# if auto-detection doesn't work or you need a specific version, +# You can pass SPLUNK_OTEL_VERSION as an environment variable, or +# You can uncomment and set the below line to what's desired. +#SPLUNK_OTEL_VERSION="v0.88.0" +SPLUNK_OTEL_VERSION="${SPLUNK_OTEL_VERSION:-}" +if [ -z "$SPLUNK_OTEL_VERSION" ]; then + SPLUNK_OTEL_VERSION="$(curl "https://api.github.com/repos/signalfx/splunk-otel-collector/tags" | jq -r '.[0].name')" +fi +echo "updating otel to version $SPLUNK_OTEL_VERSION" +sed -i'.old' "s/^OTEL_COLLECTOR_VERSION?=.*$/OTEL_COLLECTOR_VERSION?=${SPLUNK_OTEL_VERSION#v}/g" "$SOURCE_DIR/Makefile" && rm Makefile.old diff --git a/internal/buildscripts/packaging/technical-addon/packaging-scripts/update-ta-version.sh b/internal/buildscripts/packaging/technical-addon/packaging-scripts/update-ta-version.sh new file mode 100755 index 0000000000..c2e0503086 --- /dev/null +++ b/internal/buildscripts/packaging/technical-addon/packaging-scripts/update-ta-version.sh @@ -0,0 +1,13 @@ +#!/bin/bash -eux +APP_CONFIG="$SOURCE_DIR/Splunk_TA_otel/default/app.conf" +if ! [ -f "$APP_CONFIG" ]; then + echo "file $APP_CONFIG not found" + exit 1 +fi +# for sed command, the capturing group for version is what will be printed (returned), but it'll print every line, so only grab first +OLD_TA_VERSION="$(sed -n 's/^version = \(.*$\)/\1/p' "$APP_CONFIG" | head -n 1)" +if [ -z "$TA_VERSION" ]; then + TA_VERSION=$(echo "$OLD_TA_VERSION" | awk -F. '{printf "1.%d.0", $2+1}') +fi +echo "Updating TA from $OLD_TA_VERSION to version $TA_VERSION" +sed -i'.old' "s/^version = .*$/version = $TA_VERSION/g" "$APP_CONFIG" && rm "$APP_CONFIG.old"