Skip to content

Commit

Permalink
Merge pull request #6 from EIETS/dev
Browse files Browse the repository at this point in the history
feat: complete bamboo_exporter development with basic functionality
  • Loading branch information
HeZephyr authored Dec 3, 2024
2 parents 2ceaea5 + b6ddfc9 commit faea212
Show file tree
Hide file tree
Showing 10 changed files with 574 additions and 0 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Advanced"

on:
push:
branches:
- main
- dev
- feature/**
pull_request:
branches:
- main
- dev
schedule:
- cron: '20 3 * * 1'

jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: 'go'
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ 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
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
9 changes: 9 additions & 0 deletions .ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DS_Store

.idea/*
.vscode/*

bin/*
vendor/

bamboo_exporter
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG ARCH="amd64"
ARG OS="linux"
FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest
LABEL maintainer="https://github.com/EIETS"

ARG ARCH="amd64"
ARG OS="linux"
COPY .build/${OS}-${ARCH}/bamboo_exporter /bin/bamboo_exporter

EXPOSE 9117
USER nobody
ENTRYPOINT [ "/bin/bamboo_exporter" ]
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright © 2024 EIETS

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
96 changes: 96 additions & 0 deletions bamboo_exporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package main

import (
"net/http"
"os"
"os/signal"
"syscall"
"time"

"github.com/EIETS/bamboo_exporter/collector"
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus/client_golang/prometheus"
versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promslog"
"github.com/prometheus/common/promslog/flag"
"github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
"github.com/prometheus/exporter-toolkit/web/kingpinflag"
)

var (
metricsEndpoint = kingpin.Flag("telemetry.endpoint", "Path under which to expose metrics.").Default("/metrics").String()
scrapeURI = kingpin.Flag("bamboo.uri", "Full Bamboo URI to scrape metrics from.").Default("http://localhost:8085").String()
insecure = kingpin.Flag("insecure", "Ignore server certificate if using https.").Bool()
// toolkitFlags: Add default web server configuration flags.
toolkitFlags = kingpinflag.AddFlags(kingpin.CommandLine, ":9117")
// gracefulStop: Channel to receive OS signals for graceful shutdown.
gracefulStop = make(chan os.Signal, 1)
)

func main() {
promslogConfig := &promslog.Config{}

// Parse flags
flag.AddFlags(kingpin.CommandLine, promslogConfig)
kingpin.HelpFlag.Short('h')
kingpin.Version(version.Print("bamboo_exporter"))
kingpin.Parse()

logger := promslog.New(promslogConfig)
// listen to termination signals from the OS
signal.Notify(gracefulStop, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP, syscall.SIGQUIT)

config := &collector.Config{
ScrapeURI: *scrapeURI,
Insecure: *insecure,
}

exporter := collector.NewExporter(config, logger)
prometheus.MustRegister(exporter)
prometheus.MustRegister(versioncollector.NewCollector("bamboo_exporter"))

// log startup information
logger.Info("Starting bamboo_exporter", "version", version.Info())
logger.Info("Build context", "build", version.BuildContext())
logger.Info("Collecting metrics from", "scrape_host", *scrapeURI)

// listener for the termination signals from the OS
go func() {
logger.Debug("Listening and waiting for graceful stop")
sig := <-gracefulStop
logger.Info("Caught signal. Wait 2 seconds...", "sig", sig)
time.Sleep(2 * time.Second)
os.Exit(0)
}()

http.Handle(*metricsEndpoint, promhttp.Handler())

// configure the landing page
landingConfig := web.LandingConfig{
Name: "Bamboo Exporter",
Description: "Prometheus exporter for Bamboo metrics",
Version: version.Info(),
Links: []web.LandingLinks{
{
Address: *metricsEndpoint,
Text: "Metrics",
},
},
}

landingPage, err := web.NewLandingPage(landingConfig)
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
http.Handle("/", landingPage)

// start the http server
server := &http.Server{}
if err := web.ListenAndServe(server, toolkitFlags, logger); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
}
Loading

0 comments on commit faea212

Please sign in to comment.