Skip to content

Commit 4e4df51

Browse files
florentianayuwonorenovate[bot]cbartzgithub-actions[bot]erinecon
authored
fix: use otlp exporter type instead of otlp_grpc (#194)
* feat: enable log forwarding through otel collector * chore(deps): update dependency packaging to v26.1 (#180) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency sphinx-ubuntu-images to v0.2.0 (#181) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): replace astral-sh/setup-uv action with astral-sh/setup-uv v8 (#182) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update module github.com/jackc/pgx/v5 to v5.9.2 (#183) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(dashboard): remove dead override hiding job queue time series (#184) * fix(dashboard): remove dead override hiding job queue time series The "Job queue time" panel had a leftover hideSeriesFrom override that excluded every series except one specific named expression. Combined with the panel's current query (which already aggregates with sum by (le)), the override hid all data, leaving an empty chart. The override is obsolete now that the query collapses every label except le into a single combined histogram, so removing it restores visualisation without any other change. * ci: pin astral-sh/setup-uv to v8.1.0 The astral-sh/setup-uv repository does not publish a floating v8 major tag (only v8.0.0 and v8.1.0 specific tags exist), so referencing @v8 fails to resolve and breaks the workflow on every PR. * chore: update Copilot collections to v0.11.0 (#172) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Christopher Bartz <christopher.bartz@canonical.com> * chore(docs): update contributing guidelines (charmkeeper) (#170) * chore(docs): update contributing guidelines (charmkeeper) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(docs): build errors * chore: clarify PR checklist and remove unnecessary item * chore(docs): revert changes in CONTRIBUTING.md * fix(docs): whoops we're ignoring the changelog * fix: update pr checklist to incorporate previous items, remove duplicate items --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: run shell as bash * Update docs/how-to/enable-log-forwarding.md Co-authored-by: Erin Conley <erin.conley@canonical.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Erin Conley <erin.conley@canonical.com> * fix docs * add index * Update actions/enable-log-forwarding/enable-log-forwarding.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update actions/enable-log-forwarding/enable-log-forwarding.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * address code reviews Co-authored-by: Copilot <copilot@github.com> * add license Co-authored-by: Copilot <copilot@github.com> * fix docs Co-authored-by: Copilot <copilot@github.com> * refactor code Co-authored-by: Copilot <copilot@github.com> * Apply suggestions from code review Co-authored-by: Erin Conley <erin.conley@canonical.com> * address code reviews Co-authored-by: Copilot <copilot@github.com> * remove pyyaml Co-authored-by: Copilot <copilot@github.com> * parameterized test Co-authored-by: Copilot <copilot@github.com> * fix: use otlp exporter type instead of otlp_grpc The opentelemetry-collector snap does not register an 'otlp_grpc' exporter type. The correct type is 'otlp', which uses gRPC by default. 'otlp_grpc' caused the collector to fail to start after the config fragment was written. Also update the self-hosted smoke test to use the runner-injected OTLP endpoint (removing the hardcoded localhost) and write real log entries after forwarding is configured, so logs reach Loki. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: add tls insecure to generated otlp exporter config The OTLP endpoint otlp.actions.self-hosted-runners.internal:4317 uses a self-signed certificate that does not match its hostname. The existing github.yaml config already sets tls.insecure: true for the same endpoint. Add the same setting to the generated exporter fragment to prevent the TLS handshake failure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix logging action * style: fix black formatting and missing final newline Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Christopher Bartz <christopher.bartz@canonical.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Erin Conley <erin.conley@canonical.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <copilot@github.com> Co-authored-by: Weii Wang <weii.wang@canonical.com>
1 parent 8086844 commit 4e4df51

3 files changed

Lines changed: 52 additions & 6 deletions

File tree

.github/workflows/enable_log_forwarding_action_tests.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,22 @@ jobs:
5353
runs-on: [self-hosted-linux-amd64-noble-edge]
5454
env:
5555
TEST_CONFIG_FILE: 91-enable-log-forwarding-smoke-${{ github.run_id }}-${{ github.run_attempt }}.yaml
56+
TEST_LOG_FILE: /var/log/enable-log-forwarding-smoke-${{ github.run_id }}.log
5657
steps:
5758
- uses: actions/checkout@v6
5859

5960
- name: Run enable log forwarding action
6061
uses: ./actions/enable-log-forwarding
6162
with:
62-
files: |
63-
/var/log/syslog
63+
files: ${{ env.TEST_LOG_FILE }}
6464
config-file-name: ${{ env.TEST_CONFIG_FILE }}
65-
otlp-endpoint: 127.0.0.1:4317
65+
66+
- name: Populate log file to forward
67+
run: |
68+
for i in {1..5}; do
69+
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) INFO enable-log-forwarding smoke test: entry $i run_id=${{ github.run_id }}" | sudo tee -a ${TEST_LOG_FILE}
70+
sleep 2
71+
done
6672
6773
- name: Verify generated config file exists
6874
run: |

actions/enable-log-forwarding/enable_log_forwarding.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,22 @@
1515
from typing import Sequence
1616

1717
CONFIG_DIR = "/etc/otelcol/config.d"
18-
EXPORTER_NAME = "otlp_grpc"
18+
EXPORTER_NAME = "otlp/github_runner_optin"
19+
BATCH_PROCESSOR_NAME = "batch/github_runner_optin"
20+
SERVICE_NAME = "self-hosted-runner"
21+
LOKI_RESOURCE_LABELS = (
22+
"service.name",
23+
"github.repository",
24+
"github.runner",
25+
"github.workflow",
26+
"github.job",
27+
"github.run.id",
28+
"github.run.attempt",
29+
)
30+
LOKI_ATTRIBUTE_LABELS = (
31+
"log.file.name",
32+
"log.file.path",
33+
)
1934
SNAP_CMD = Path("/usr/bin/snap")
2035
SUDO_CMD = Path("/usr/bin/sudo")
2136
MKDIR_CMD = Path("/usr/bin/mkdir")
@@ -174,16 +189,29 @@ def exporter_exists_in_config_dir(
174189
def build_resource_attributes() -> list[dict[str, str]]:
175190
"""Build static GitHub resource attributes attached to forwarded logs."""
176191
attrs = [
192+
("service.name", SERVICE_NAME),
177193
("github.repository", os.getenv("GITHUB_REPOSITORY", "unknown")),
178194
("github.runner", os.getenv("RUNNER_NAME", "unknown")),
179195
("github.workflow", os.getenv("GITHUB_WORKFLOW", "unknown")),
180196
("github.job", os.getenv("GITHUB_JOB", "unknown")),
181197
("github.run.id", os.getenv("GITHUB_RUN_ID", "unknown")),
182198
("github.run.attempt", os.getenv("GITHUB_RUN_ATTEMPT", "unknown")),
199+
("loki.resource.labels", ", ".join(LOKI_RESOURCE_LABELS)),
183200
]
184201
return [{"key": key, "value": value, "action": "upsert"} for key, value in attrs]
185202

186203

204+
def build_log_attribute_actions() -> list[dict[str, str]]:
205+
"""Build log-attribute actions for Loki label promotion hints."""
206+
return [
207+
{
208+
"key": "loki.attribute.labels",
209+
"value": ", ".join(LOKI_ATTRIBUTE_LABELS),
210+
"action": "upsert",
211+
}
212+
]
213+
214+
187215
def build_config(
188216
files: Sequence[str],
189217
resolved_endpoint: str,
@@ -196,18 +224,28 @@ def build_config(
196224
"filelog/github_runner_optin": {
197225
"include": list(files),
198226
"start_at": "end",
227+
"include_file_name": True,
228+
"include_file_path": True,
199229
}
200230
},
201231
"processors": {
202232
"resource/github_runner_optin": {
203233
"attributes": build_resource_attributes(),
204-
}
234+
},
235+
"attributes/github_runner_optin": {
236+
"actions": build_log_attribute_actions(),
237+
},
238+
BATCH_PROCESSOR_NAME: {},
205239
},
206240
"service": {
207241
"pipelines": {
208242
"logs/github_runner_optin": {
209243
"receivers": ["filelog/github_runner_optin"],
210-
"processors": ["resource/github_runner_optin", "batch"],
244+
"processors": [
245+
"resource/github_runner_optin",
246+
"attributes/github_runner_optin",
247+
BATCH_PROCESSOR_NAME,
248+
],
211249
"exporters": [exporter_name],
212250
}
213251
}
@@ -217,6 +255,7 @@ def build_config(
217255
config["exporters"] = {
218256
exporter_name: {
219257
"endpoint": resolved_endpoint,
258+
"tls": {"insecure": True},
220259
}
221260
}
222261

actions/enable-log-forwarding/tests/test_enable_log_forwarding.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def test_build_config_exporter_block_is_conditionally_defined(
159159
assert ("exporters" in config) is has_exporters_block
160160
if has_exporters_block:
161161
assert config["exporters"][module.EXPORTER_NAME]["endpoint"] == "otel:4318"
162+
assert config["exporters"][module.EXPORTER_NAME]["tls"] == {"insecure": True}
162163

163164

164165
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)