-
-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(services): add runtime metrics exporter (#1619)
* feat(runtime-exporter): init * optimize dockerfile * chore * chore * chore * chore * chore * chore * refactor * chore * chore * chore * chore * chore * chore * chore * add ServiceMonitor to runtime-exporter build * test * fix * chore --------- Co-authored-by: lim <[email protected]>
- Loading branch information
Showing
18 changed files
with
3,881 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: dockerize-runtime-exporter | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- "services/runtime-exporter/**" | ||
- ".github/workflows/dockerize-runtime-exporter.yml" | ||
- "!**/*.md" | ||
- "!services/runtime-exporter/package-lock.json" | ||
|
||
concurrency: | ||
group: dockerize-runtime-exporter-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
dockerize-runtime-exporter: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: | | ||
ghcr.io/${{ github.repository_owner }}/runtime-exporter | ||
docker.io/${{ secrets.DOCKER_USERNAME }}/runtime-exporter | ||
# https://github.com/docker/metadata-action#typesemver | ||
tags: | | ||
type=raw,value=latest,enable=true | ||
type=sha,enable=true,format=short | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Login to Github Container Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: ./services/runtime-exporter | ||
file: ./services/runtime-exporter/Dockerfile | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: linux/amd64, linux/arm64 | ||
|
||
trigger-workflow-build-cluster-image: | ||
needs: [dockerize-runtime-exporter] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: trigger cluster image workflow | ||
uses: peter-evans/repository-dispatch@v2 | ||
with: | ||
event-type: docker_build_success | ||
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "version": "latest"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
{{- include "runtime-exporter.labels" . | nindent 4 }} | ||
name: runtime-exporter | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
{{- include "runtime-exporter.selectorLabels" . | nindent 6 }} | ||
template: | ||
metadata: | ||
labels: | ||
{{- include "runtime-exporter.selectorLabels" . | nindent 8 }} | ||
spec: | ||
automountServiceAccountToken: {{ .Values.serviceAccount.create }} | ||
serviceAccountName: {{ include "laf-server.serviceAccountName" . }} | ||
securityContext: | ||
{{- toYaml .Values.podSecurityContext | nindent 8 }} | ||
containers: | ||
- image: docker.io/lafyun/runtime-exporter:latest | ||
imagePullPolicy: Always | ||
name: runtime-exporter | ||
ports: | ||
- name: http | ||
containerPort: 2342 | ||
protocol: TCP | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: http | ||
readinessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: http | ||
env: | ||
- name: API_SECRET | ||
value: {{ .Values.default_region.runtime_exporter_secret | quote }} | ||
- name: NAMESPACE | ||
value: {{ .Release.Namespace | quote }} | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
{{- include "runtime-exporter.labels" . | nindent 4 }} | ||
name: runtime-exporter | ||
spec: | ||
ports: | ||
- name: http | ||
port: 2342 | ||
protocol: TCP | ||
targetPort: http | ||
selector: | ||
{{- include "runtime-exporter.selectorLabels" . | nindent 4 }} | ||
|
||
--- | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
labels: | ||
namespace: {{ .Release.Namespace }} | ||
release: prometheus | ||
name: runtime-exporter | ||
spec: | ||
endpoints: | ||
- interval: 60s | ||
path: "/runtime/metrics/{{ .Values.default_region.runtime_exporter_secret}}" | ||
scrapeTimeout: 10s | ||
namespaceSelector: | ||
matchNames: | ||
- {{ .Release.Namespace }} | ||
selector: | ||
matchLabels: | ||
{{- include "runtime-exporter.labels" . | nindent 6 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist | ||
node_modules | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dist | ||
node_modules | ||
.env | ||
tsconfig.build.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"semi": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Stage 1: Build | ||
FROM node:18-slim AS build | ||
|
||
WORKDIR /app | ||
|
||
# Utilize cache mechanism, only execute npm install when dependency files change | ||
COPY package*.json ./ | ||
RUN npm install | ||
|
||
# Copy other files and directories | ||
COPY . . | ||
|
||
# Build the application | ||
RUN npm run build | ||
|
||
# Stage 2: Set up production environment | ||
FROM node:18-slim AS production | ||
|
||
# Set environment variables | ||
ENV LOG_LEVEL=debug | ||
ENV NODE_ENV=production | ||
|
||
WORKDIR /app | ||
|
||
# Copy build artifacts from build stage | ||
COPY --from=build /app/dist ./dist | ||
# Copy production dependencies, omitting development dependencies | ||
COPY --from=build /app/node_modules ./node_modules | ||
COPY --from=build /app/package*.json ./ | ||
|
||
# Set non-root user for better security | ||
RUN chown -R node:node /app/ | ||
USER node | ||
|
||
# Expose application port | ||
EXPOSE 2342 | ||
|
||
# Start the application | ||
CMD [ "npm", "run", "start" ] |
Oops, something went wrong.