Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CI

on:
push:
branches:
- 'feature/**'
- 'v[0-9]+.[0-9]+'
pull_request:
branches:
- master*
- 'feature/**'
- 'v[0-9]+.[0-9]+'

env:
GO_VERSION: 1.22.1

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

jobs:
golangci:
strategy:
fail-fast: false
name: Build and Push
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Docker login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker Build
run: |
make agent-image
- name: Docker Push
run: |
make agent-push



25 changes: 18 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# include tools/make/*.mk

AGENT_IMAGE ?= blockopsnetwork/agent:latest
OPERATOR_IMAGE ?= blockopsnetwork/agent:latest
AGENT_IMAGE ?= blockopsnetwork/telescope:v0.1.5
OPERATOR_IMAGE ?= blockopsnetwork/telescope:latest
AGENT_BINARY ?= build/agent
OPERATOR_BINARY ?= build/agent-operator
AGENTLINT_BINARY ?= build/agentlint
Expand Down Expand Up @@ -39,6 +39,8 @@ GO_LDFLAGS := -X $(VPREFIX).Branch=$(GIT_BRANCH) \
DEFAULT_FLAGS := $(GO_FLAGS)
DEBUG_GO_FLAGS := -ldflags "$(GO_LDFLAGS)" -tags "$(GO_TAGS)"
RELEASE_GO_FLAGS := -ldflags "-s -w $(GO_LDFLAGS)" -tags "$(GO_TAGS)"
PLATFORMS ?= linux/amd64,linux/arm64


ifeq ($(RELEASE_BUILD),1)
GO_FLAGS := $(DEFAULT_FLAGS) $(RELEASE_GO_FLAGS)
Expand Down Expand Up @@ -77,8 +79,8 @@ integration-test:
# Targets for building binaries
#

.PHONY: binaries agent operator
binaries: agent operator
.PHONY: binaries agent operator multi-platform-agent-image
binaries: agent operator multi-platform-agent-image

agent:
ifeq ($(USE_CONTAINER),1)
Expand Down Expand Up @@ -111,14 +113,23 @@ ifneq ($(DOCKER_PLATFORM),)
DOCKER_FLAGS += --platform=$(DOCKER_PLATFORM)
endif

.PHONY: images agent-image operator-image
images: agent-image operator-image
.PHONY: images agent-image operator-image
images: agent-image operator-image multi-platform-agent-image

agent-image:
DOCKER_BUILDKIT=1 docker build $(DOCKER_FLAGS) -t $(AGENT_IMAGE) -f cmd/agent/Dockerfile .
operator-image:
DOCKER_BUILDKIT=1 docker build $(DOCKER_FLAGS) -t $(OPERATOR_IMAGE) -f cmd/agent-operator/Dockerfile .

agent-push:
docker push $(AGENT_IMAGE)


multi-platform-agent-image:
docker buildx create --use --name multiarch --driver docker-container
docker buildx build --platform $(PLATFORMS) $(DOCKER_FLAGS) -t $(AGENT_IMAGE) -f cmd/agent/Dockerfile .
# docker buildx build --push --platform $(PLATFORMS) $(DOCKER_FLAGS) -t $(OPERATOR_IMAGE) -f cmd/agent-operator/Dockerfile .

#
# Targets for generating assets
#
Expand All @@ -138,7 +149,7 @@ generate-helm-docs:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
cd operations/helm/charts/grafana-agent && helm-docs
cd operations/helm/charts/telescope && helm-docs
endif

generate-helm-tests:
Expand Down
16 changes: 8 additions & 8 deletions cmd/agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ RUN --mount=type=cache,target=/root/.cache/go-build \

FROM public.ecr.aws/ubuntu/ubuntu:mantic

#Username and uid for grafana-agent user
#Username and uid for telescope user
ARG UID=473
ARG USERNAME="grafana-agent"
ARG USERNAME="telescope"

LABEL org.opencontainers.image.source="https://github.com/grafana/agent"
LABEL org.opencontainers.image.source="https://github.com/blockopsnetwork/telescope"

# Install dependencies needed at runtime.
RUN <<EOF
Expand All @@ -45,15 +45,15 @@ RUN <<EOF
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EOF

COPY --from=build /src/agent/build/grafana-agent /bin/grafana-agent
COPY cmd/grafana-agent/agent-local-config.yaml /etc/agent/agent.yaml
COPY --from=build /src/agent/build/agent /bin/agent
COPY cmd/agent/agent-local-config.yaml /etc/agent/agent.yaml

# Create grafana-agent user in container, but do not set it as default
# Create telescope agent user in container, but do not set it as default
RUN groupadd --gid $UID $USERNAME
RUN useradd -m -u $UID -g $UID $USERNAME
RUN chown -R $USERNAME:$USERNAME /etc/agent
RUN chown -R $USERNAME:$USERNAME /bin/grafana-agent
RUN chown -R $USERNAME:$USERNAME /bin/agent

ENTRYPOINT ["/bin/grafana-agent"]
ENTRYPOINT ["/bin/agent"]
ENV AGENT_DEPLOY_MODE=docker
CMD ["--config.file=/etc/agent/agent.yaml", "--metrics.wal-directory=/etc/agent/data"]
17 changes: 17 additions & 0 deletions cmd/agent/agent-local-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server:
log_level: info

metrics:
global:
scrape_interval: 1m
configs:
- name: test
host_filter: false
scrape_configs:
- job_name: local_scrape
static_configs:
- targets: ['127.0.0.1:12345']
labels:
cluster: 'localhost'
remote_write:
- url: http://localhost:9009/api/prom/push
58 changes: 46 additions & 12 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var cfgFile string
type Config struct {
Server ServerConfig `yaml:"server"`
Metrics MetricsConfig `yaml:"metrics"`
Integrations map[string]interface{} `yaml:"integrations"`

}

type ServerConfig struct {
Expand All @@ -46,6 +48,7 @@ type ServerConfig struct {

type MetricsConfig struct {
Global GlobalConfig `yaml:"global"`
Wal_Directory string `yaml:"wal_directory"`
Configs []MetricConfig `yaml:"configs"`
}

Expand All @@ -71,6 +74,15 @@ type BasicAuth struct {
Password string `yaml:"password"`
}

type IntegrationsConfig struct {
Agent ToIntegrate `yaml:"agent"`
NodeExporter ToIntegrate `yaml:"node_exporter"`
}

type ToIntegrate struct {
Enabled bool `yaml:"enabled"`
}

type StaticConfig struct {
Targets []string `yaml:"targets"`
}
Expand Down Expand Up @@ -175,6 +187,7 @@ func generateNetworkConfig() Config {
cRemoteWriteUrl := viper.GetString("remote-write-url")

ports, err := networkDiscovery(cNetwork)


if err != nil {
log.Fatalf("Unable to discover blockchain port: %v", err)
Expand All @@ -184,14 +197,35 @@ func generateNetworkConfig() Config {
viper.Set("scrape_port", port)
}

networkConfig, ok := networkConfigs[cNetwork]
if !ok {
log.Fatalf("Invalid network configuration for: %v", cNetwork)
}

var scrapeConfigs []ScrapeConfig
idx := 0 // Initialize index for job naming
for nodeType, port := range networkConfig.NodeType {
jobName := fmt.Sprintf("%s_%s_%s_job_%d", toLowerAndEscape(cProjectName), cNetwork, nodeType, idx)
target := fmt.Sprintf("localhost:%d", port)
scrapeConfigs = append(scrapeConfigs, ScrapeConfig{
JobName: jobName,
StaticConfigs: []StaticConfig{
{
Targets: []string{target},
},
},
})
idx++
}

return Config{
Server: ServerConfig{
LogLevel: "info",
},
Metrics: MetricsConfig{
Wal_Directory: "/tmp/wal",
Global: GlobalConfig{
ScrapeInterval: "1m",
ScrapeInterval: "15s",
ExternalLabels: map[string]string{
"project_id": cProjectId,
"project_name": cProjectName,
Expand All @@ -210,20 +244,20 @@ func generateNetworkConfig() Config {
Configs: []MetricConfig{
{
Name: toLowerAndEscape(cProjectName+cNetwork+"_metrics"),
HostFilter: true,
ScrapeConfigs: []ScrapeConfig{
{
JobName: toLowerAndEscape(cProjectName+cNetwork+"_job"),
StaticConfigs: []StaticConfig{
{
Targets: viper.GetStringSlice("scrape_port"),
},
},
},
},
HostFilter: false,
ScrapeConfigs: scrapeConfigs,
},
},
},
Integrations: map[string]interface{}{
"agent": ToIntegrate{
Enabled: false,
},
"node_exporter": ToIntegrate{
Enabled: true,
},
},

}
}

Expand Down
31 changes: 31 additions & 0 deletions telescope_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
server:
log_level: info
metrics:
global:
scrape_interval: 15s
external_labels:
project_id: hyperbridge-nexus-bootnode
project_name: hyperbridge-nexus
remote_write:
- url: https://hyperbridge-prometheus.blockops.network/api/v1/write
basic_auth:
password: hyperbridge
username: hyperbridge
wal_directory: /tmp/wal
configs:
- name: hyperbridge-nexushyperbridge_metrics
host_filter: false
scrape_configs:
- job_name: hyperbridge-nexus_hyperbridge_relaychain_job_0
static_configs:
- targets:
- localhost:9615
- job_name: hyperbridge-nexus_hyperbridge_parachain_job_1
static_configs:
- targets:
- localhost:9616
integrations:
agent:
enabled: false
node_exporter:
enabled: true