Skip to content

Commit

Permalink
support new protobuf format used in newer versions of chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlice committed Dec 22, 2023
1 parent 6e41c68 commit 6378c7d
Show file tree
Hide file tree
Showing 33 changed files with 8,931 additions and 3,773 deletions.
7 changes: 7 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Learn more: https://docs.buf.build/configuration/v1/buf-gen-yaml
version: v1
plugins:
- plugin: es
path: ./node_modules/.bin/protoc-gen-es
opt: target=ts
out: src/gen
4 changes: 3 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
version: "3"
services:
search:
image: ghcr.io/askalice/search.emu.sh:master
container_name: search
build: .
image: search
restart: always
ports:
- "3006:8080"
Expand Down
11,054 changes: 7,473 additions & 3,581 deletions package-lock.json

Large diffs are not rendered by default.

49 changes: 34 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,50 @@
},
"scripts": {
"test": "npm run build:ts && tsc -p test/tsconfig.test.json && cross-env TS_NODE_FILES=true tap --ts test/**/*.test.ts",
"start": "npm run build:ts && fastify start -l info dist/app.js",
"start": "npm run build:ts && fastify start -l info dist/main.js",
"predeploy": "npm run build:ts",
"production": "cross-env NODE_ENV=production fastify start -l info dist/app.js -p 8080",
"build:ts": "tsc",
"dev": "tsc && concurrently -k -p \"[{name}]\" -n \"search.emu.sh\" -c \"yellow.bold,cyan.bold\" \"tsc -w\" \"fastify start --ignore-watch=.ts$ -p 3006 -w -l info -P dist/app.js\""
"dev:ts": "tsc -w",
"dev:node": "npx dotenv-cli -e .env -- npx nodemon --watch 'dist/**/*.js' --exec 'node dist/main.js'",
"development": "concurrently \"npm:dev:ts\" \"npm:dev:node\"",
"devold": "tsc && concurrently -k -p \"[{name}]\" -n \"search.emu.sh\" -c \"yellow.bold,cyan.bold\" \"tsc -w\" \"fastify start --ignore-watch=.ts$ -p 3006 -w -l info -P dist/app.js\"",
"dev": "tsc && concurrently -k \"npm:dev:*\" "
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@autotelic/fastify-opentelemetry": "^0.17.1",
"@bufbuild/protobuf": "^1.3.0",
"@bufbuild/protoc-gen-es": "^1.3.0",
"@fastify/autoload": "^5.4.1",
"@fastify/sensible": "^5.1.1",
"@fastify/static": "^6.5.0",
"@google-cloud/language": "^4.2.6",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/auto-instrumentations-node": "^0.34.0",
"@opentelemetry/exporter-collector": "^0.25.0",
"@opentelemetry/exporter-jaeger": "^1.8.0",
"@opentelemetry/instrumentation": "^0.34.0",
"@opentelemetry/instrumentation-fastify": "^0.30.1",
"@opentelemetry/instrumentation-http": "^0.34.0",
"@opentelemetry/resources": "^1.8.0",
"@opentelemetry/sdk-node": "^0.34.0",
"@opentelemetry/sdk-trace-base": "^1.8.0",
"@opentelemetry/sdk-trace-node": "^1.8.0",
"@opentelemetry/semantic-conventions": "^1.8.0",
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/auto-instrumentations-node": "^0.38.0",
"@opentelemetry/context-async-hooks": "^1.14.0",
"@opentelemetry/exporter-collector-grpc": "^0.25.0",
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.40.0",
"@opentelemetry/exporter-metrics-otlp-http": "^0.40.0",
"@opentelemetry/exporter-prometheus": "^0.40.0",
"@opentelemetry/exporter-trace-otlp-grpc": "^0.40.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.40.0",
"@opentelemetry/exporter-trace-otlp-proto": "^0.40.0",
"@opentelemetry/instrumentation": "^0.40.0",
"@opentelemetry/instrumentation-dns": "^0.32.0",
"@opentelemetry/instrumentation-fastify": "^0.32.0",
"@opentelemetry/instrumentation-http": "^0.40.0",
"@opentelemetry/propagator-b3": "^1.14.0",
"@opentelemetry/propagator-jaeger": "^1.14.0",
"@opentelemetry/resources": "^1.14.0",
"@opentelemetry/sdk-metrics": "^1.14.0",
"@opentelemetry/sdk-node": "^0.40.0",
"@opentelemetry/sdk-trace-base": "^1.14.0",
"@opentelemetry/sdk-trace-node": "^1.14.0",
"@opentelemetry/sdk-trace-web": "^1.14.0",
"@opentelemetry/semantic-conventions": "^1.14.0",
"axios": "^1.1.3",
"cross-env": "^7.0.3",
"dohjs": "^0.3.2",
Expand All @@ -47,13 +64,15 @@
"node-cache": "^5.1.2",
"node-dig-dns": "^0.3.0",
"openai": "^3.1.0",
"ping": "^0.4.1"
"ping": "^0.4.1",
"protobufjs": "^7.2.4"
},
"devDependencies": {
"@types/node": "^15.0.0",
"@types/tap": "^15.0.0",
"concurrently": "^6.0.0",
"fastify-tsconfig": "^1.0.1",
"protobufjs-cli": "^1.1.1",
"tap": "^15.0.9",
"ts-node": "^10.0.0",
"typescript": "^4.2.4"
Expand Down
33 changes: 25 additions & 8 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
//
//
import openTelemetryPlugin from '@autotelic/fastify-opentelemetry';
import AutoLoad, { AutoloadPluginOptions } from '@fastify/autoload';
import fastifyStatic from '@fastify/static';
import { context, trace } from '@opentelemetry/api';
import { FastifyInstance, FastifyPluginAsync } from 'fastify';
import fastifyRacing from 'fastify-racing';
import { join } from 'path';
import { tracer as tracing } from './tracing';
export type AppOptions = {} & Partial<AutoloadPluginOptions>;

// const ServerOptions: RawServerBase = {
// http2: true,
// };

const app: FastifyPluginAsync<AppOptions> = async (fastify: FastifyInstance<any>, opts): Promise<void> => {
tracing.startSpan('main');

// fastify.
await fastify.register(openTelemetryPlugin, { wrapRoutes: true });
await fastify.register(AutoLoad, {
Expand All @@ -30,15 +32,29 @@ const app: FastifyPluginAsync<AppOptions> = async (fastify: FastifyInstance<any>
prefix: '/icons/',
});
fastify.addHook('onRequest', async (request) => {
const span = tracing.startSpan(request?.routerPath);
// console.log(context, 'trace:', trace, request.url);
span.setAttribute('order', request.ip);
const {
activeSpan,
tracer,
// context,
// extract,
// inject,
} = request.openTelemetry()
// Spans started in a wrapped route will automatically be children of the activeSpan.
const span = tracer.startSpan(`${(activeSpan as any).name} - child process`)
console.log(context, 'trace:', trace, request.url);
Object.entries(request?.query || {})?.forEach(([key, value]) => {
if(span?.setAttribute)
span?.setAttribute(key, value);
});
span?.end()

});
fastify.addHook('onResponse', async (request) => {
const span = trace.getSpan(context.active());
// console.log(span, context, 'trace:', trace, request.url);
span?.end();
// span.setAttribute('order', request.ip);
Object.entries(request?.query)?.forEach(([key, value]) => {
if(span?.setAttribute)
span?.setAttribute(key, value);
});
});
// fastify.use((req, res, next) => {
// const span = trace.getSpan(context.active());
Expand All @@ -56,3 +72,4 @@ const app: FastifyPluginAsync<AppOptions> = async (fastify: FastifyInstance<any>

export default app;
export { app };

10 changes: 10 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as process from 'process';
import otelSDK from './tracing';
otelSDK.start();

import start from './start';
start(otelSDK);


export { default as app, default } from './app';

29 changes: 29 additions & 0 deletions src/proto/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2022 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//third_party/protobuf/proto_library.gni")

if (is_android) {
import("//build/config/android/rules.gni")
}

_proto_files = [
"action_info.proto",
"chrome_searchbox_stats.proto",
"entity_info.proto",
"groups.proto",
"types.proto",
]

proto_library("omnibox_proto") {
sources = _proto_files
proto_in_dir = "."
}

if (is_android) {
proto_java_library("omnibox_proto_java") {
proto_path = "."
sources = _proto_files
}
}
4 changes: 4 additions & 0 deletions src/proto/DIR_METADATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
monorail: {
component: "UI>Browser>Omnibox"
}
team_email: "[email protected]"
27 changes: 27 additions & 0 deletions src/proto/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022 The Chromium Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions src/proto/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file://components/omnibox/OWNERS
22 changes: 22 additions & 0 deletions src/proto/README.chromium
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Name: Omnibox Protos
Short Name: omnibox_proto
URL: This is the canonical public repository
Version: 539203338
Date: 2023/06/09 UTC
License: BSD
License File: LICENSE
Security Critical: Yes
Shipped: yes

Description:
This package contains the protos that are used by the Omnibox team to facilitate
integration between Chrome and Google Search.
Updates to this code should be made by changing the internal copies, and then
running the export script.

blaze run //chrome/omnibox/tools/proto_export -- \
--from_piper \
--output=$CHROMIUM_SRC/third_party/omnibox_proto

Local Modifications:
Unchanged from the output of the export script.
30 changes: 30 additions & 0 deletions src/proto/action_info.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = 'proto2';

option go_package = "github.com/AskAlice/chrome-suggest/proto/action_info";
package omnibox;

// Entity Suggestion Action type received in the server response and echoed back
// as part of the searchboxstats. The values are not used in Chrome in any way
// and thus do not need names or comments that describe what they represent.
enum ActionType {
UNKNOWN_ACTION_TYPE = 0;
ACTION_PHONE_CALL = 1;
ACTION_TEXT = 2;
ACTION_EMAIL = 3;
ACTION_CALL = 4;
ACTION_CHAT = 5;
ACTION_VIDEO_CALL = 6;
ACTION_NAVIGATE = 7;
ACTION_SEARCH = 8;
ACTION_WEBPAGE = 9;
ACTION_OSRP = 10;
ACTION_SM = 11;
ACTION_AOG = 12;
}

message ActionInfo {
optional ActionType logs_action_type = 1;
optional string package_id = 2;
optional string action_uri = 4;
optional uint32 action_type = 6;
}
86 changes: 86 additions & 0 deletions src/proto/entity_info.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
syntax = 'proto2';

option go_package = "github.com/AskAlice/chrome-suggest/proto/entity_info";

message EntityInfo {
// The entity id.
optional string entity_id = 1;

// The suggestion second line (subtitle).
// For some clients (e.g. desktop) this is used as the part which is to the
// right of the emdash.
optional string annotation = 2;

// Image Url.
// Will replace the suggestion icon
optional string image_url = 6;

// Will replace the original suggestion as the text on the suggestion's 1st
// line (title).
optional string name = 7;

// Dominant color.
// Affects how image is rendered.
optional string dominant_color = 9;

// Encoding of how search behavior should be modified when clicking the entity
// suggestion (gs_ssp).
optional string suggest_search_parameters = 10;

// List of possible actions for this entity.
repeated ActionInfo action_suggestions = 12;

// List of categories this entity belongs to.
repeated CategoryInfo.Category category = 14;

// The entity's official website uri.
optional string website_uri = 17;
}

// Entity Suggestion Action descriptor.
message ActionInfo {
enum ActionType {
DIRECTIONS = 2;
CALL = 3;
REVIEWS = 20;
}

// The URI to open when the action is invoked.
optional string action_uri = 3;

// // Action type for logging.
// optional ActionType logs_action_type = 4;

// Action type.
optional ActionType action_type = 8;

// If non-empty, the action must result in navigation to the SRP accompanied
// with these additional request parameters to help force a certain SRP.
map<string, string> search_parameters = 9;
}

// Entity Suggestion Category info.
message CategoryInfo {
enum Category {
UNKNOWN = 0;
MUSIC = 2;
GAMES = 4;
PEOPLE = 6;
SPORTS = 7;
BOOKS = 9;
GEO = 12;
NATURAL_WORLD = 13;
FOOD = 15;
PRODUCTS = 16;
UNIVERSITIES = 17;
CARS_US = 18;
TV = 19;
MOVIES = 20;
CARS_MODEL_US = 21;
LOCAL_POIS_AND_CHAINS = 22;
COMPANIES = 23;
PRODUCT_LINES = 24;
LOCAL_POI = 25;
LOCALITY = 26;
}
}
Loading

0 comments on commit 6378c7d

Please sign in to comment.