Skip to content

Commit

Permalink
Add a common directory, and common logging. (cloudspannerecosystem#158)
Browse files Browse the repository at this point in the history
Use bunyan logging, and have a common module.
Update poller/scaler to use common logging.
Fix docker builds to include common module
All build files moved to src/ root directory
Update GKE deployment build instructions.
  • Loading branch information
nielm authored Dec 28, 2023
1 parent 1802f94 commit cd74aa8
Show file tree
Hide file tree
Showing 35 changed files with 9,346 additions and 7,520 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ updates:
- dependency-name: "*"
update-types: ["version-update:semver-major"]

- directory: "/src/autoscaler-common"
package-ecosystem: "npm"
schedule:
interval: "weekly"
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-major"]

- directory: "/src/forwarder"
package-ecosystem: "npm"
schedule:
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: npm install in autoscaler-common
working-directory: src/autoscaler-common
run: npm install
- name: npm install in poller-core
run: npm install
- run: npm test
env:
CI: true
Expand All @@ -58,7 +62,11 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: npm install in autoscaler-common
working-directory: src/autoscaler-common
run: npm install
- name: npm install in scaler-core
run: npm install
- run: npm test
env:
CI: true
3 changes: 3 additions & 0 deletions src/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.gcloudignore
.nyc_output
13 changes: 9 additions & 4 deletions src/scaler/Dockerfile → src/Dockerfile-poller
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ ARG NODE_VERSION=18
FROM node:${NODE_VERSION}-alpine AS build-env

WORKDIR /usr/src/app
COPY . .
COPY autoscaler-common/ autoscaler-common/
COPY poller/ poller/

WORKDIR /usr/src/app/autoscaler-common
RUN npm config set update-notifier false
RUN npm install
RUN npm install --omit=dev

WORKDIR /usr/src/app/poller
RUN npm install --omit=dev

FROM gcr.io/distroless/nodejs${NODE_VERSION}:latest
COPY --from=build-env /usr/src/app /usr/src/app
WORKDIR /usr/src/app/scaler-core
WORKDIR /usr/src/app/poller/poller-core

CMD ["../index.js"]
CMD ["-e", "require('../index').main()"]
13 changes: 9 additions & 4 deletions src/poller/Dockerfile → src/Dockerfile-scaler
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ ARG NODE_VERSION=18
FROM node:${NODE_VERSION}-alpine AS build-env

WORKDIR /usr/src/app
COPY . .
COPY autoscaler-common/ autoscaler-common/
COPY scaler/ scaler/

WORKDIR /usr/src/app/autoscaler-common
RUN npm config set update-notifier false
RUN npm install
RUN npm install --omit=dev

WORKDIR /usr/src/app/scaler
RUN npm install --omit=dev

FROM gcr.io/distroless/nodejs${NODE_VERSION}:latest
COPY --from=build-env /usr/src/app /usr/src/app
WORKDIR /usr/src/app/poller-core
WORKDIR /usr/src/app/scaler/scaler-core

CMD ["../index.js"]
CMD ["-e", "require('../index').main()"]
4 changes: 2 additions & 2 deletions src/Dockerfile → src/Dockerfile-unified
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ WORKDIR /usr/src/app
COPY . .

RUN npm config set update-notifier false
RUN npm install
RUN npm install --omit=dev

FROM gcr.io/distroless/nodejs${NODE_VERSION}:latest
COPY --from=build-env /usr/src/app /usr/src/app
WORKDIR /usr/src/app/scaler/scaler-core

CMD ["../../index.js"]
CMD ["-e", "require('../../index').main()"]
38 changes: 38 additions & 0 deletions src/autoscaler-common/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* Create a Bunyan Logger using structured logging to stdout.
*/
const bunyan = require('bunyan');
const {LoggingBunyan} = require('@google-cloud/logging-bunyan');

// Create logging client.
const loggingBunyan = new LoggingBunyan({
redirectToStdout: true,
projectId: process.env.PROJECT_ID,
logName: 'autoscaler',
useMessageField: false,
});

const logger = bunyan.createLogger({
name: 'cloud-spanner-autoscaler',
streams: [
loggingBunyan.stream('trace'),
],
});

module.exports = {
logger: logger,
};
Loading

0 comments on commit cd74aa8

Please sign in to comment.