Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Synthetic monitoring skeleton #463

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,27 @@ DEMO_HOST_PREFIX=privacy-sandbox-demos-

# home
HOME_HOST=privacy-sandbox-demos-home.dev
HOME_URI=http://privacy-sandbox-demos-home.dev:8080
Seburan marked this conversation as resolved.
Show resolved Hide resolved
HOME_TOKEN=""
HOME_DETAIL="Home page of Privacy Sandbox Demos"

# Publisher
## news
NEWS_HOST=privacy-sandbox-demos-news.dev
NEWS_URI=http://privacy-sandbox-demos-news.dev:8080
NEWS_TOKEN=""
NEWS_DETAIL="Publisher: News media site"

# Advertizer
## shop
SHOP_HOST=privacy-sandbox-demos-shop.dev
SHOP_URI=http://privacy-sandbox-demos-shop.dev:8080
SHOP_TOKEN=""
SHOP_DETAIL="Advertiser: EC shopping site"

## travel
TRAVEL_HOST=privacy-sandbox-demos-travel.dev
TRAVEL_URI=http://privacy-sandbox-demos-travel.dev:8080
TRAVEL_TOKEN=""
TRAVEL_DETAIL="Advertiser: EC travel site"

Expand Down Expand Up @@ -80,8 +84,11 @@ IDP_DETAIL="Identity Provider for relying parties. Also Issuing Private State To
## Topics related
## site to observe topics
MOTO_NEWS_HOST=motorcycles.privacy-sandbox-demos-news.dev
MOTO_NEWS_URI=http://motorcycles.privacy-sandbox-demos-news.dev:8080
SOCCER_NEWS_HOST=soccer.privacy-sandbox-demos-news.dev
SOCCER_NEWS_URI=http://soccer.privacy-sandbox-demos-news.dev:8080
GARDENING_NEWS_HOST=gardening.privacy-sandbox-demos-news.dev
GARDENING_NEWS_URI=http://gardening.privacy-sandbox-demos-news.dev:8080
TOPICS_DETAIL="Topics page"

## server to request topics with headers
Expand Down
7 changes: 7 additions & 0 deletions cicd/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@ DEMO_HOST_PREFIX=privacy-sandcastle-dev-

# home
HOME_HOST=privacy-sandcastle-dev-home.web.app
HOME_URI=https://privacy-sandcastle-dev-home.web.app
HOME_TOKEN=""
HOME_DETAIL="Home page of Privacy Sandbox Demos"

# Publisher
## news
NEWS_HOST=privacy-sandcastle-dev-news.web.app
NEWS_URI=https://privacy-sandcastle-dev-news.web.app
NEWS_TOKEN=""
NEWS_DETAIL="Publisher: News media site"


# Advertizer
## shop
SHOP_HOST=privacy-sandcastle-dev-shop.web.app
SHOP_URI=https://privacy-sandcastle-dev-shop.web.app
SHOP_TOKEN=""
SHOP_DETAIL="Advertiser: EC shopping site"

## travel
TRAVEL_HOST=privacy-sandcastle-dev-travel.web.app
TRAVEL_URI=https://privacy-sandcastle-dev-travel.web.app
TRAVEL_TOKEN=""
TRAVEL_DETAIL="Advertiser: EC travel site"

Expand Down Expand Up @@ -81,8 +85,11 @@ IDP_DETAIL="Identity Provider for relying parties. Also Issuing Private State To
## Topics related
## site to observe topics
MOTO_NEWS_HOST=privacy-sandcastle-dev-motorcycles.web.app
MOTO_NEWS_URI=https://privacy-sandcastle-dev-motorcycles.web.app
SOCCER_NEWS_HOST=privacy-sandcastle-dev-soccer-foot.web.app
SOCCER_NEWS_URI=https://privacy-sandcastle-dev-soccer-foot.web
GARDENING_NEWS_HOST=privacy-sandcastle-dev-gardening-potager.web.app
GARDENING_NEWS_URI=https://privacy-sandcastle-dev-gardening-potager
TOPICS_DETAIL="Topics page"

## server to request topics with headers
Expand Down
7 changes: 7 additions & 0 deletions cicd/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@ DEMO_HOST_PREFIX=privacy-sandbox-demos-

# home
HOME_HOST=privacy-sandbox-demos-home.dev
HOME_URI=https://privacy-sandbox-demos-home.dev
HOME_TOKEN=""
HOME_DETAIL="Home page of Privacy Sandbox Demos"

# Publisher
## news
NEWS_HOST=privacy-sandbox-demos-news.dev
NEWS_URI=https://privacy-sandbox-demos-news.dev
NEWS_TOKEN=""
NEWS_DETAIL="Publisher: News media site"


# Advertizer
## shop
SHOP_HOST=privacy-sandbox-demos-shop.dev
SHOP_URI=https://privacy-sandbox-demos-shop.dev
SHOP_TOKEN=""
SHOP_DETAIL="Advertiser: EC shopping site"

## travel
TRAVEL_HOST=privacy-sandbox-demos-travel.dev
TRAVEL_URI=https://privacy-sandbox-demos-travel.dev
TRAVEL_TOKEN=""
TRAVEL_DETAIL="Advertiser: EC travel site"

Expand Down Expand Up @@ -81,8 +85,11 @@ IDP_DETAIL="Identity Provider for relying parties. Also Issuing Private State To
## Topics related
## site to observe topics
MOTO_NEWS_HOST=motorcycles.privacy-sandbox-demos-news.dev
MOTO_NEWS_URI=https://motorcycles.privacy-sandbox-demos-news.dev
SOCCER_NEWS_HOST=soccer.privacy-sandbox-demos-news.dev
SOCCER_NEWS_URI=https://soccer.privacy-sandbox-demos-news.dev
GARDENING_NEWS_HOST=gardening.privacy-sandbox-demos-news.dev
GARDENING_NEWS_URI=https://gardening.privacy-sandbox-demos-news.dev
TOPICS_DETAIL="Topics page"

## server to request topics with headers
Expand Down
16 changes: 16 additions & 0 deletions monitoring/puppeteer-nodejs/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file specifies files that are *not* uploaded to Google Cloud
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

#!include:.gitignore
3 changes: 3 additions & 0 deletions monitoring/puppeteer-nodejs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ignore
.cache
node_modules
24 changes: 24 additions & 0 deletions monitoring/puppeteer-nodejs/.puppeteerrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.

// [START monitoring_synthetic_monitoring_custom_puppeteer_cjs]
const {join} = require('path');

/**
* @type {import("puppeteer").Configuration}
*/
module.exports = {
cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
};
// [END monitoring_synthetic_monitoring_custom_puppeteer_cjs]
46 changes: 46 additions & 0 deletions monitoring/puppeteer-nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Overview

This package uses the `@google-cloud/synthetics-sdk-api` to create Google Cloud Functions used with Google Cloud Synthetic Monitoring.

## Installation

```shell
# from root of repo, build all packages
npm install
```

## Add a new use case monitoring function

1. Copy the Function Entry Point template in index.js, update the Entry Point name as well as the monitoring function name.
2. Copy the monitor-uc-template.js, rename the monitoring function and build the monitoring logic.

## Running

The following command runs the selected function (ENTRY_POINT)locally. You will also need to export the required environment variables with
`export KEY=VALUE` command.

```shell
npx functions-framework --target=<ENTRY_POINT>
```

then run the command below to trigger the function

```shell
curl http://localhost:8080/
```

## Deploy to Google Cloud Platform

Setup prerequisites

```shell
cd <PROJECT_ROOT_DIR>
./script/monitoring_setup.sh
```

The following command deploys the monitoring/puppeteer-nodejs package to GCP as a cloud function v2.

```shell
cd <PROJECT_ROOT_DIR>
./script/monitoring_deploy.sh
```
81 changes: 81 additions & 0 deletions monitoring/puppeteer-nodejs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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.

// [START monitoring_synthetic_monitoring_custom_puppeteer_script]
import {
instantiateAutoInstrumentation,
runSyntheticHandler,
} from '@google-cloud/synthetics-sdk-api';

// Run instantiateAutoInstrumentation before any other code runs, to get automatic logs and traces
instantiateAutoInstrumentation();
import * as functions from '@google-cloud/functions-framework';
import * as axios from 'axios';
import * as assert from 'node:assert';
import * as puppeteer from 'puppeteer';

import {runMonitorUcSingleTouchConversion} from './monitor-uc-single-touch-conversion.js';
import {runMonitorUcRemarketing} from './monitor-uc-remarketing.js';
import {runMonitorUcVastVideoPaapi} from './monitor-uc-vast-video-paapi.js';
import {runMonitorUcVideoMultiSellerSeqAuctionPaapi} from './monitor-uc-video-multi-seller-seq-auction-paapi.js';

// >>> MONITOR TEMPLATE >>>
// Use Case : <USE CASE FULL NAME>
// functions.http('MonitorUcShortName', runSyntheticHandler(async ({ logger, executionId }) => { // TODO : replace function name with Use Case Short name

// // call implementation in monitor-uc-template.js // TODO : replace with filename
// await runMonitorUcShortName(logger, executionId); // TODO : replace function name with Use Case Short name

// }));
// <<< MONITOR TEMPLATE

// Cloud Run Functions Entry points for Synthetic Monitoring with Puppeteer

// Use Case : Single-touch conversion Attribution
functions.http(
'MonitorUcSingleTouchConversion',
runSyntheticHandler(async ({logger, executionId}) => {
// call implementation in monitor-uc-single-touch-conversion.js
await runMonitorUcSingleTouchConversion(logger, executionId); // Call the exported function
}),
);

// Use Case : Retargeting / Remarketing
functions.http(
'MonitorUcRemarketing',
runSyntheticHandler(async ({logger, executionId}) => {
// call implementation in monitor-uc-remarketing.js
await runMonitorUcRemarketing(logger, executionId); // Call the exported function
}),
);

// Use Case : Instream VAST video ad in a Protected Audience single-seller auction
functions.http(
'MonitorUcVastVideoPaapi',
runSyntheticHandler(async ({logger, executionId}) => {
// call implementation in monitor-uc-vast-video-paapi.js
await runMonitorUcVastVideoPaapi(logger, executionId); // Call the exported function
}),
);

// Use Case : Monitor Use Case : Instream video ad in a Protected Audience multi-seller sequential auction setup
functions.http(
'MonitorUcVideoMultiSellerSeqAuctionPaapi',
runSyntheticHandler(async ({logger, executionId}) => {
// call implementation in monitor-uc-video-multi-seller-seq-auction-paapi.js
await runMonitorUcVideoMultiSellerSeqAuctionPaapi(logger, executionId); // Call the exported function
}),
);

// [END monitoring_synthetic_monitoring_custom_puppeteer_script]
59 changes: 59 additions & 0 deletions monitoring/puppeteer-nodejs/lib/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2022 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.
*/

// ****************************************************************************
// ENVIRONMENT VARIABLES
// ****************************************************************************
export const {
// Home
HOME_HOST,
HOME_URI,

// Advertisers
SHOP_HOST,
SHOP_URI,
TRAVEL_HOST,
TRAVEL_URI,

// Publishers
NEWS_HOST,
NEWS_URI,
MOTO_NEWS_HOST,
MOTO_NEWS_URI,
SOCCER_NEWS_HOST,
SOCCER_NEWS_URI,
GARDENING_NEWS_HOST,
GARDENING_NEWS_URI,

// Ad-techs
DSP_HOST,
DSP_URI,

DSP_A_HOST,
DSP_A_URI,

DSP_B_HOST,
DSP_B_URI,

SSP_HOST,
SSP_URI,

SSP_A_HOST,
SSP_A_URI,

SSP_B_HOST,
SSP_B_URI,

AD_SERVER_HOST,
AD_SERVER_URI,
} = process.env;
Loading