Skip to content

Instantly share code, notes, and snippets.

View songy23's full-sized avatar

Yang Song songy23

View GitHub Profile
@songy23
songy23 / main.go
Created May 27, 2020 22:46
Inspect GFE Latency in Spanner Go Client - 2
// Copyright 2019 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,
@songy23
songy23 / example.py
Last active May 29, 2020 16:50
Inspect GFE Latency in Spanner Python Client
# Execute a simple SQL statement.
spanner_api = database.spanner_api
transport = spanner_api.transport
request = spanner_pb2.ExecuteSqlRequest(
session=session.name,
sql='SELECT * FROM TEST',
)
result_set, call = transport.execute_sql.with_call(request)
headers = call.initial_metadata() # is a tuple
server_timing = dict(headers)['server-timing']
@songy23
songy23 / example.go
Created May 22, 2020 00:56
Inspect GFE Latency in Spanner Go Client
var md metadata.MD
resultSet, err := client.ExecuteSql(ctx, req, gax.WithGRPCOptions(grpc.Header(&md)))
srvTiming := md.Get("server-timing")
// Process the header
@songy23
songy23 / example.java
Created May 22, 2020 00:53
Inspect GFE Latency in Spanner Java Client - 2
// Instantiates a client
SpannerOptions options =
SpannerOptions.newBuilder()
.setInterceptorProvider(() -> Collections.singletonList(interceptor))
.build();
Spanner spanner = options.getService();
@songy23
songy23 / example.java
Created May 22, 2020 00:52
Inspect GFE Latency in Spanner Java Client - 1
private static final HeaderClientInterceptor interceptor = new HeaderClientInterceptor();
private static final Metadata.Key<String> SERVER_TIMING_HEADER_KEY =
Metadata.Key.of("server-timing", Metadata.ASCII_STRING_MARSHALLER);
private static class HeaderClientInterceptor implements ClientInterceptor {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method,
CallOptions callOptions, Channel next) {
return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@songy23
songy23 / main.go
Last active April 23, 2020 06:17
Inspect GFE Latency in Spanner Go Client
// Copyright 2019 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,
@songy23
songy23 / OcAgentMetricsExportQuickstart.java
Created February 19, 2019 21:34
OcAgentMetricsExportQuickstart
/*
* Copyright 2018, OpenCensus Authors
*
* 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