Skip to content

Instantly share code, notes, and snippets.

@ajm188
Created April 5, 2022 13:21
Show Gist options
  • Save ajm188/03b19d5205ebffa15a51d62ee5f1fc91 to your computer and use it in GitHub Desktop.
Save ajm188/03b19d5205ebffa15a51d62ee5f1fc91 to your computer and use it in GitHub Desktop.
vtadmin channelz demo
package main
import (
"context"
"errors"
"flag"
"fmt"
"google.golang.org/grpc"
"vitess.io/vitess/go/cmd/vtctldclient/cli"
"vitess.io/vitess/go/vt/log"
channelz "google.golang.org/grpc/channelz/grpc_channelz_v1"
vtadminpb "vitess.io/vitess/go/vt/proto/vtadmin"
)
func fatal(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
addr := flag.String("addr", ":14200", "")
flag.Parse()
ctx, cancel := context.WithCancel(context.Background())
cc, err := grpc.DialContext(ctx, *addr, grpc.WithInsecure())
fatal(err)
defer cc.Close()
done := make(chan struct{})
go func(ctx context.Context) {
defer func() { done <- struct{}{} }()
client := vtadminpb.NewVTAdminClient(cc)
for {
select {
case <-ctx.Done():
return
default:
_, err := client.GetClusters(ctx, &vtadminpb.GetClustersRequest{})
if err != nil {
if errors.Is(err, context.Canceled) {
return
}
log.Errorf("GetClusters() failed with: %v", err)
}
}
}(ctx)
log.Infof("starting channelz client")
czclient := channelz.NewChannelzClient(cc)
for {
resp, err := czclient.GetTopChannels(ctx, &channelz.GetTopChannelsRequest{})
fatal(err)
if len(resp.Channel) == 0 {
log.Infof("no channels found, trying again")
continue
}
data, err := cli.MarshalJSON(resp)
fatal(err)
fmt.Printf("%s\n", data)
break
}
cancel()
<-done
}
{
"channel": [
{
"ref": {
"channel_id": "3",
"name": "local://vtctld/"
},
"data": {
"state": {
"state": 3
},
"target": "local://vtctld/",
"trace": {
"num_events_logged": "26",
"creation_timestamp": "2022-04-05T13:08:20.799665Z",
"events": [
{
"description": "Channel Created",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799684Z"
},
{
"description": "original dial target is: \"local://vtctld/\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799688Z"
},
{
"description": "parsed dial target is: {Scheme:local Authority:vtctld Endpoint: URL:{Scheme:local Opaque: User: Host:vtctld Path:/ RawPath: ForceQuery:false RawQuery: Fragment: RawFragment:}}",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799742Z"
},
{
"description": "Channel authority set to \"\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799743Z"
},
{
"description": "ccResolverWrapper: sending update to cc: {[{localhost:15999 <nil> <nil> 0 <nil>}] <nil> <nil>}",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799996Z"
},
{
"description": "Resolver state updated: {Addresses:[{Addr:localhost:15999 ServerName: Attributes:<nil> BalancerAttributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} (resolver returned new addresses)",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800002Z"
},
{
"description": "ClientConn switching balancer to \"pick_first\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800016Z"
},
{
"description": "Channel switches to new LB policy \"pick_first\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800017Z"
},
{
"description": "Subchannel(id:7) created",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800039Z",
"subchannel_ref": {
"subchannel_id": "7",
"name": ""
}
},
{
"description": "Channel Connectivity change to CONNECTING",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800136Z"
},
{
"description": "Channel Connectivity change to READY",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.801225Z"
},
{
"description": "Channel Connectivity change to IDLE",
"severity": 1,
"timestamp": "2022-04-05T13:08:50.844650Z"
},
{
"description": "ccResolverWrapper: sending update to cc: {[{localhost:15999 <nil> <nil> 0 <nil>}] <nil> <nil>}",
"severity": 1,
"timestamp": "2022-04-05T13:08:50.844674Z"
},
{
"description": "Resolver state updated: {Addresses:[{Addr:localhost:15999 ServerName: Attributes:<nil> BalancerAttributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} ()",
"severity": 1,
"timestamp": "2022-04-05T13:08:50.844678Z"
},
{
"description": "Channel Connectivity change to CONNECTING",
"severity": 1,
"timestamp": "2022-04-05T13:08:50.844738Z"
},
{
"description": "Channel Connectivity change to READY",
"severity": 1,
"timestamp": "2022-04-05T13:08:50.845225Z"
},
{
"description": "Channel Connectivity change to IDLE",
"severity": 1,
"timestamp": "2022-04-05T13:10:10.865267Z"
},
{
"description": "ccResolverWrapper: sending update to cc: {[{localhost:15999 <nil> <nil> 0 <nil>}] <nil> <nil>}",
"severity": 1,
"timestamp": "2022-04-05T13:10:10.865963Z"
},
{
"description": "Resolver state updated: {Addresses:[{Addr:localhost:15999 ServerName: Attributes:<nil> BalancerAttributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} ()",
"severity": 1,
"timestamp": "2022-04-05T13:10:10.865985Z"
},
{
"description": "Channel Connectivity change to CONNECTING",
"severity": 1,
"timestamp": "2022-04-05T13:10:10.866262Z"
},
{
"description": "Channel Connectivity change to READY",
"severity": 1,
"timestamp": "2022-04-05T13:10:10.867929Z"
},
{
"description": "Channel Connectivity change to IDLE",
"severity": 1,
"timestamp": "2022-04-05T13:12:50.880935Z"
},
{
"description": "ccResolverWrapper: sending update to cc: {[{localhost:15999 <nil> <nil> 0 <nil>}] <nil> <nil>}",
"severity": 1,
"timestamp": "2022-04-05T13:12:50.881122Z"
},
{
"description": "Resolver state updated: {Addresses:[{Addr:localhost:15999 ServerName: Attributes:<nil> BalancerAttributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} ()",
"severity": 1,
"timestamp": "2022-04-05T13:12:50.881134Z"
},
{
"description": "Channel Connectivity change to CONNECTING",
"severity": 1,
"timestamp": "2022-04-05T13:12:50.881238Z"
},
{
"description": "Channel Connectivity change to READY",
"severity": 1,
"timestamp": "2022-04-05T13:12:50.882664Z"
}
]
},
"calls_started": "7",
"calls_succeeded": "7",
"calls_failed": "0",
"last_call_started_timestamp": "2022-04-05T13:08:20.814855Z"
},
"channel_ref": [],
"subchannel_ref": [
{
"subchannel_id": "7",
"name": ""
}
],
"socket_ref": []
},
{
"ref": {
"channel_id": "4",
"name": "local://vtgate/"
},
"data": {
"state": {
"state": 3
},
"target": "local://vtgate/",
"trace": {
"num_events_logged": "21",
"creation_timestamp": "2022-04-05T13:08:20.799926Z",
"events": [
{
"description": "Channel Created",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799930Z"
},
{
"description": "original dial target is: \"local://vtgate/\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799932Z"
},
{
"description": "parsed dial target is: {Scheme:local Authority:vtgate Endpoint: URL:{Scheme:local Opaque: User: Host:vtgate Path:/ RawPath: ForceQuery:false RawQuery: Fragment: RawFragment:}}",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799961Z"
},
{
"description": "Channel authority set to \"\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799962Z"
},
{
"description": "ccResolverWrapper: sending update to cc: {[{localhost:15991 <nil> <nil> 0 <nil>}] <nil> <nil>}",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800131Z"
},
{
"description": "Resolver state updated: {Addresses:[{Addr:localhost:15991 ServerName: Attributes:<nil> BalancerAttributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} (resolver returned new addresses)",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800147Z"
},
{
"description": "ClientConn switching balancer to \"pick_first\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800152Z"
},
{
"description": "Channel switches to new LB policy \"pick_first\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800154Z"
},
{
"description": "Subchannel(id:8) created",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800218Z",
"subchannel_ref": {
"subchannel_id": "8",
"name": ""
}
},
{
"description": "Channel Connectivity change to CONNECTING",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800273Z"
},
{
"description": "Channel Connectivity change to READY",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.801188Z"
},
{
"description": "Channel Connectivity change to IDLE",
"severity": 1,
"timestamp": "2022-04-05T13:09:00.826524Z"
},
{
"description": "ccResolverWrapper: sending update to cc: {[{localhost:15991 <nil> <nil> 0 <nil>}] <nil> <nil>}",
"severity": 1,
"timestamp": "2022-04-05T13:09:00.827132Z"
},
{
"description": "Resolver state updated: {Addresses:[{Addr:localhost:15991 ServerName: Attributes:<nil> BalancerAttributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} ()",
"severity": 1,
"timestamp": "2022-04-05T13:09:00.827150Z"
},
{
"description": "Channel Connectivity change to CONNECTING",
"severity": 1,
"timestamp": "2022-04-05T13:09:00.827261Z"
},
{
"description": "Channel Connectivity change to READY",
"severity": 1,
"timestamp": "2022-04-05T13:09:00.828700Z"
},
{
"description": "Channel Connectivity change to IDLE",
"severity": 1,
"timestamp": "2022-04-05T13:10:20.833865Z"
},
{
"description": "ccResolverWrapper: sending update to cc: {[{localhost:15991 <nil> <nil> 0 <nil>}] <nil> <nil>}",
"severity": 1,
"timestamp": "2022-04-05T13:10:20.833989Z"
},
{
"description": "Resolver state updated: {Addresses:[{Addr:localhost:15991 ServerName: Attributes:<nil> BalancerAttributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} ()",
"severity": 1,
"timestamp": "2022-04-05T13:10:20.833994Z"
},
{
"description": "Channel Connectivity change to CONNECTING",
"severity": 1,
"timestamp": "2022-04-05T13:10:20.834022Z"
},
{
"description": "Channel Connectivity change to READY",
"severity": 1,
"timestamp": "2022-04-05T13:10:20.834671Z"
}
]
},
"calls_started": "1",
"calls_succeeded": "1",
"calls_failed": "0",
"last_call_started_timestamp": "2022-04-05T13:08:20.800244Z"
},
"channel_ref": [],
"subchannel_ref": [
{
"subchannel_id": "8",
"name": ""
}
],
"socket_ref": []
},
{
"ref": {
"channel_id": "5",
"name": "local://vtgate/"
},
"data": {
"state": {
"state": 3
},
"target": "local://vtgate/",
"trace": {
"num_events_logged": "26",
"creation_timestamp": "2022-04-05T13:08:20.799957Z",
"events": [
{
"description": "Channel Created",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799959Z"
},
{
"description": "original dial target is: \"local://vtgate/\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799960Z"
},
{
"description": "parsed dial target is: {Scheme:local Authority:vtgate Endpoint: URL:{Scheme:local Opaque: User: Host:vtgate Path:/ RawPath: ForceQuery:false RawQuery: Fragment: RawFragment:}}",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799973Z"
},
{
"description": "Channel authority set to \"\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799974Z"
},
{
"description": "ccResolverWrapper: sending update to cc: {[{localhost:15991 <nil> <nil> 0 <nil>}] <nil> <nil>}",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799996Z"
},
{
"description": "Resolver state updated: {Addresses:[{Addr:localhost:15991 ServerName: Attributes:<nil> BalancerAttributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} (resolver returned new addresses)",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.799999Z"
},
{
"description": "ClientConn switching balancer to \"pick_first\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800014Z"
},
{
"description": "Channel switches to new LB policy \"pick_first\"",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800015Z"
},
{
"description": "Subchannel(id:6) created",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800035Z",
"subchannel_ref": {
"subchannel_id": "6",
"name": ""
}
},
{
"description": "Channel Connectivity change to CONNECTING",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.800171Z"
},
{
"description": "Channel Connectivity change to READY",
"severity": 1,
"timestamp": "2022-04-05T13:08:20.801348Z"
},
{
"description": "Channel Connectivity change to IDLE",
"severity": 1,
"timestamp": "2022-04-05T13:08:50.814579Z"
},
{
"description": "ccResolverWrapper: sending update to cc: {[{localhost:15991 <nil> <nil> 0 <nil>}] <nil> <nil>}",
"severity": 1,
"timestamp": "2022-04-05T13:08:50.814687Z"
},
{
"description": "Resolver state updated: {Addresses:[{Addr:localhost:15991 ServerName: Attributes:<nil> BalancerAttributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} ()",
"severity": 1,
"timestamp": "2022-04-05T13:08:50.814695Z"
},
{
"description": "Channel Connectivity change to CONNECTING",
"severity": 1,
"timestamp": "2022-04-05T13:08:50.814731Z"
},
{
"description": "Channel Connectivity change to READY",
"severity": 1,
"timestamp": "2022-04-05T13:08:50.815364Z"
},
{
"description": "Channel Connectivity change to IDLE",
"severity": 1,
"timestamp": "2022-04-05T13:10:10.822673Z"
},
{
"description": "ccResolverWrapper: sending update to cc: {[{localhost:15991 <nil> <nil> 0 <nil>}] <nil> <nil>}",
"severity": 1,
"timestamp": "2022-04-05T13:10:10.823558Z"
},
{
"description": "Resolver state updated: {Addresses:[{Addr:localhost:15991 ServerName: Attributes:<nil> BalancerAttributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} ()",
"severity": 1,
"timestamp": "2022-04-05T13:10:10.823577Z"
},
{
"description": "Channel Connectivity change to CONNECTING",
"severity": 1,
"timestamp": "2022-04-05T13:10:10.836203Z"
},
{
"description": "Channel Connectivity change to READY",
"severity": 1,
"timestamp": "2022-04-05T13:10:10.839116Z"
},
{
"description": "Channel Connectivity change to IDLE",
"severity": 1,
"timestamp": "2022-04-05T13:12:50.853877Z"
},
{
"description": "ccResolverWrapper: sending update to cc: {[{localhost:15991 <nil> <nil> 0 <nil>}] <nil> <nil>}",
"severity": 1,
"timestamp": "2022-04-05T13:12:50.857608Z"
},
{
"description": "Resolver state updated: {Addresses:[{Addr:localhost:15991 ServerName: Attributes:<nil> BalancerAttributes:<nil> Type:0 Metadata:<nil>}] ServiceConfig:<nil> Attributes:<nil>} ()",
"severity": 1,
"timestamp": "2022-04-05T13:12:50.857629Z"
},
{
"description": "Channel Connectivity change to CONNECTING",
"severity": 1,
"timestamp": "2022-04-05T13:12:50.857752Z"
},
{
"description": "Channel Connectivity change to READY",
"severity": 1,
"timestamp": "2022-04-05T13:12:50.860531Z"
}
]
},
"calls_started": "1",
"calls_succeeded": "1",
"calls_failed": "0",
"last_call_started_timestamp": "2022-04-05T13:08:20.800053Z"
},
"channel_ref": [],
"subchannel_ref": [
{
"subchannel_id": "6",
"name": ""
}
],
"socket_ref": []
}
],
"end": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment