import grpc from opencensus.common.transports.async_ import AsyncTransport from opencensus.trace.exporters import print_exporter from opencensus.trace.exporters import stackdriver_exporter from opencensus.trace.ext.grpc import client_interceptor from opencensus.trace.ext.grpc import server_interceptor from opencensus.trace.samplers import always_on from opencensus.trace.tracer import Tracer import demo_pb2 import demo_pb2_grpc from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc from logger import getJSONLogger logger = getJSONLogger('recommendationservice-server') def initStackdriverProfiling(): project_id = None try: project_id = os.environ["GCP_PROJECT_ID"] except KeyError: # Environment variable not set pass for retry in xrange(1, 4): try: if project_id: googlecloudprofiler.start(service='recommendation_server', service_version='1.0.0',
# # http://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. import grpc import demo_pb2 import demo_pb2_grpc from logger import getJSONLogger logger = getJSONLogger('emailservice-client') def send_confirmation_email(email, order): channel = grpc.insecure_channel('0.0.0.0:8080') channel = grpc.intercept_channel(channel) stub = demo_pb2_grpc.EmailServiceStub(channel) try: response = stub.SendOrderConfirmation(demo_pb2.SendOrderConfirmationRequest( email = email, order = order )) logger.info('Request sent.') except grpc.RpcError as err: logger.error(err.details()) logger.error('{}, {}'.format(err.code().name, err.code().value))
#!/usr/bin/python import sys import grpc from logger import getJSONLogger logger = getJSONLogger('adservice-v2-server') if __name__ == "__main__": # TODO # set up server stub # ensure the service is listening to port 9556 # TODO # form a request with the required input # TODO # make a call to server and return a response # Uncomment to log the resoinse from the Server # logger.info(response)
import demo_pb2 import demo_pb2_grpc from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc from opencensus.trace.exporters import stackdriver_exporter from opencensus.trace.exporters import print_exporter from opencensus.trace.ext.grpc import server_interceptor from opencensus.common.transports.async_ import AsyncTransport from opencensus.trace.samplers import always_on # import googleclouddebugger import googlecloudprofiler from logger import getJSONLogger logger = getJSONLogger('emailservice-server') # try: # googleclouddebugger.enable( # module='emailserver', # version='1.0.0' # ) # except: # pass # Loads confirmation email template from file env = Environment(loader=FileSystemLoader('templates'), autoescape=select_autoescape(['html', 'xml'])) template = env.get_template('confirmation.html')
# # http://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. import grpc import demo_pb2 import demo_pb2_grpc from logger import getJSONLogger logger = getJSONLogger('emailservice-client') from opencensus.trace.tracer import Tracer from opencensus.trace.exporters import stackdriver_exporter from opencensus.trace.ext.grpc import client_interceptor try: exporter = stackdriver_exporter.StackdriverExporter() tracer = Tracer(exporter=exporter) tracer_interceptor = client_interceptor.OpenCensusClientInterceptor(tracer, host_port='0.0.0.0:8080') except: tracer_interceptor = client_interceptor.OpenCensusClientInterceptor() def send_confirmation_email(email, order): channel = grpc.insecure_channel('0.0.0.0:8080') channel = grpc.intercept_channel(channel, tracer_interceptor)
import googlecloudprofiler from google.auth.exceptions import DefaultCredentialsError import grpc from opencensus.trace.exporters import print_exporter from opencensus.trace.exporters import stackdriver_exporter from opencensus.trace.ext.grpc import server_interceptor from opencensus.common.transports.async_ import AsyncTransport from opencensus.trace.samplers import always_on import demo_pb2 import demo_pb2_grpc from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc from logger import getJSONLogger logger = getJSONLogger('reviewservice-server') def initStackdriverProfiling(): project_id = None try: project_id = os.environ["GCP_PROJECT_ID"] except KeyError: # Environment variable not set pass for retry in range(1, 4): try: if project_id: googlecloudprofiler.start(service='review_server', service_version='1.0.0',
# 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 # # http://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. import time from logger import getJSONLogger logger = getJSONLogger('pythonservice') from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer PORT_NUMBER = 10401 #This class will handles any incoming request from #the browser class myHandler(BaseHTTPRequestHandler): #Handler for the GET requests def do_GET(self): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers()
# # http://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. import grpc import demo_pb2 import demo_pb2_grpc from logger import getJSONLogger logger = getJSONLogger("emailservice-client") def send_confirmation_email(email, order): channel = grpc.insecure_channel("0.0.0.0:8080") stub = demo_pb2_grpc.EmailServiceStub(channel) try: response = stub.SendOrderConfirmation( demo_pb2.SendOrderConfirmationRequest(email=email, order=order) ) logger.info("Request sent.") except grpc.RpcError as err: logger.error(err.details()) logger.error("{}, {}".format(err.code().name, err.code().value))
#!/usr/bin/python from concurrent import futures import grpc import os import random import time import app_pb2 import app_pb2_grpc from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc from logger import getJSONLogger logger = getJSONLogger('server') class RecommendationService(app_pb2_grpc.RecommendationServiceServicer): def ListRecommendations(self, request, context): max_responses = 5 response = catalog_stub.ListProducts(app_pb2.Empty()) product_ids = [x.id for x in response.products] filtered_products = list(set(product_ids) - set(request.product_ids)) num_products = len(filtered_products) num_return = min(max_responses, num_products) indices = random.sample(range(num_products), num_return) prod_list = [filtered_products[i] for i in indices] logger.info( '[Recv ListRecommendaitons] product_ids={}'.format(prod_list)) resp = app_pb2.ListRecommendationsResponse()
sampler = always_on.AlwaysOnSampler() exporter = stackdriver_exporter.StackdriverExporter() tracer_interceptor = server_interceptor.OpenCensusServerInterceptor(sampler, exporter) except: tracer_interceptor = server_interceptor.OpenCensusServerInterceptor() # try: # googleclouddebugger.enable( # module='emailserver', # version='1.0.0' # ) # except: # pass from logger import getJSONLogger logger = getJSONLogger('emailservice-server') # Loads confirmation email template from file env = Environment( loader=FileSystemLoader('templates'), autoescape=select_autoescape(['html', 'xml']) ) template = env.get_template('confirmation.html') class BaseEmailService(demo_pb2_grpc.EmailServiceServicer): def Check(self, request, context): return health_pb2.HealthCheckResponse( status=health_pb2.HealthCheckResponse.SERVING) class EmailService(BaseEmailService): def __init__(self):
from concurrent import futures import googleclouddebugger import grpc from opencensus.trace.exporters import print_exporter from opencensus.trace.exporters import stackdriver_exporter from opencensus.trace.ext.grpc import server_interceptor from opencensus.trace.samplers import always_on import demo_pb2 import demo_pb2_grpc from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc from logger import getJSONLogger logger = getJSONLogger('recommendationservice-server') class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer): def ListRecommendations(self, request, context): max_responses = 5 # fetch list of products from product catalog stub cat_response = product_catalog_stub.ListProducts(demo_pb2.Empty()) product_ids = [x.id for x in cat_response.products] filtered_products = list(set(product_ids)-set(request.product_ids)) num_products = len(filtered_products) num_return = min(max_responses, num_products) # sample list of indicies to return indices = random.sample(range(num_products), num_return) # fetch product ids from indices prod_list = [filtered_products[i] for i in indices]
import grpc from google.api_core.exceptions import GoogleAPICallError from grpc_health.v1 import health_pb2, health_pb2_grpc from jinja2 import Environment, FileSystemLoader, TemplateError, select_autoescape from opentelemetry import trace from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter from opentelemetry.instrumentation.grpc import GrpcInstrumentorServer from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor import demo_pb2 import demo_pb2_grpc from logger import getJSONLogger logger = getJSONLogger("emailservice-server") grpc_server_instrumentor = GrpcInstrumentorServer() grpc_server_instrumentor.instrument() otlp_exporter = OTLPSpanExporter() # Loads confirmation email template from file env = Environment( loader=FileSystemLoader("templates"), autoescape=select_autoescape(["html", "xml"]) ) template = env.get_template("confirmation.html") class BaseEmailService(demo_pb2_grpc.EmailServiceServicer): def Check(self, request, context): return health_pb2.HealthCheckResponse(
import os import random import time import traceback import logging from concurrent import futures from os.path import join, dirname from dotenv import load_dotenv import grpc import kuruvi_pb2 import kuruvi_pb2_grpc from logger import getJSONLogger logger = getJSONLogger('face-describe-server') import facenet _ONE_DAY_IN_SECONDS = 60 * 60 * 24 dotenv_path = join(dirname(__file__), '.env') load_dotenv(dotenv_path) class Greeter(kuruvi_pb2_grpc.FaceDescribeServicer): def describeFaces(self, request, context): # base_dir = join('/srv/album-faces', request.albumName) base_dir = join('/srv/album-faces', 'test-images') print("describe faces called", base_dir) facenet.main(base_dir) return kuruvi_pb2.FacePoints(points=[1.1, 1.2, 1.3])