Skip to content

Commit

Permalink
damoun#49: read config
Browse files Browse the repository at this point in the history
  • Loading branch information
surdaft committed Feb 14, 2025
1 parent 7f2240b commit 3ff7460
Show file tree
Hide file tree
Showing 32 changed files with 1,266 additions and 276 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@ on:
pull_request:
branches:
- main
- devel
workflow_dispatch:

jobs:
golang:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: '^1.22.2'
- run: make promu
- run: promu crossbuild -v
- name: Store binaries
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: build
path: .build
if-no-files-found: error
include-hidden-files: true
- name: Test binary
run: .build/linux-amd64/twitch_exporter --help

docker:
needs: golang
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Download binaries artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # v3.25.15
uses: github/codeql-action/init@dd746615b3b9d728a6a37ca2045b68ca76d4841a # v3.28.8
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -56,7 +56,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # v3.25.15
uses: github/codeql-action/autobuild@dd746615b3b9d728a6a37ca2045b68ca76d4841a # v3.28.8

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -69,4 +69,4 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # v3.25.15
uses: github/codeql-action/analyze@dd746615b3b9d728a6a37ca2045b68ca76d4841a # v3.28.8
10 changes: 6 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: '^1.22.2'
- run: make promu
- run: promu crossbuild -v
- name: Store binaries artifacts
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: build
path: .build
if-no-files-found: error
include-hidden-files: true
- name: Test binary
run: .build/linux-amd64/twitch_exporter --help

publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Download binaries artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release Charts

on:
push:
branches:
- main

jobs:
release:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.7.0
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@
*.so
*.dylib
twitch_exporter
__debug_*

# ignore helm chart configuration if local
values.yaml
*.values.yaml

# Don't ignore committing the helm chart values file
!charts/twitch-exporter/values.yaml

# ignore helmfile, which is used to manage helm deployments
helmfile.yaml

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Ignore config files
twitch_exporter.yml*
*.twitch_exporter.yml*
74 changes: 74 additions & 0 deletions .vscode/collector.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
// Place your twitch_exporter workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"collector": {
"description": "Quickly create a collector",
"scope": "go",
"prefix": "collector",
"body": [
"package collector",
"",
"import (",
"\t\"log/slog\"",
"",
"\t\"github.com/damoun/twitch_exporter/config\"",
"",
"\t\"github.com/nicklaw5/helix/v2\"",
"\t\"github.com/prometheus/client_golang/prometheus\"",
")",
"",
"type metricCollector struct {",
"\tlogger *slog.Logger",
"\tclient *helix.Client",
"\tchannelNames *config.ChannelNames",
"",
"\tmetric typedDesc",
"}",
"",
"func init() {",
"\tregisterCollector(\"metric\", defaultEnabled, NewMetricCollector)",
"}",
"",
"func NewMetricCollector(logger *slog.Logger, client *helix.Client, cfg *config.Config) (Collector, error) {",
"\tc := metricCollector{",
"\t\tlogger: logger,",
"\t\tclient: client,",
"\t\tchannelNames: cfg.Twitch.Channels,",
"",
"\t\tmetric: typedDesc{prometheus.NewDesc(",
"\t\t\tprometheus.BuildFQName(namespace, \"\", \"metric\"),",
"\t\t\t\"metric description\",",
"\t\t\t[]string{\"username\"}, nil,",
"\t\t), prometheus.GaugeValue},",
"\t}",
"",
"\treturn c, nil",
"}",
"",
"func (c metricCollector) Update(ch chan<- prometheus.Metric) error {",
"\tif len(*c.channelNames) == 0 {",
"\t\treturn ErrNoData",
"\t}",
"",
"\tch <- c.metric.mustNewConstMetric(float64(1), \"username\")",
"",
"\treturn nil",
"}",
],
"isFileTemplate": true
}
}
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"args": [
"--twitch.channel",
"timthetatman"
]
}
]
}
Loading

0 comments on commit 3ff7460

Please sign in to comment.