From c6a85ad35c2df99b6bbf98f83eacbbecae4c3ea7 Mon Sep 17 00:00:00 2001 From: heyanlong Date: Thu, 6 Dec 2018 09:52:22 +0800 Subject: [PATCH] report --- sky-php7ext/skywalking.c | 31 ++++++++++++++++++++++++------- sky-php7ext/src/greeter_client.cc | 16 +++++++++++----- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/sky-php7ext/skywalking.c b/sky-php7ext/skywalking.c index d727b2f..e23e3b5 100644 --- a/sky-php7ext/skywalking.c +++ b/sky-php7ext/skywalking.c @@ -43,6 +43,8 @@ #include #include +#include + #include #include #include @@ -509,7 +511,14 @@ static void module_init() { application_instance = -100000; application_id = -100000; - application_id = applicationCodeRegister(SKYWALKING_G(grpc), SKYWALKING_G(app_code)); + + int i = 0; + + do { + application_id = applicationCodeRegister(SKYWALKING_G(grpc), SKYWALKING_G(app_code)); + + i++; + } while (application_id == -100000 && i <= 3); if (application_id == -100000) { sky_close = 1; @@ -517,9 +526,11 @@ static void module_init() { } char *ipv4s = _get_current_machine_ip(); - char uuid[80]; - strcat(uuid, SKYWALKING_G(app_code)); - strcat(uuid, ipv4s); + char uuid[37]; + uuid_t uuid1; + uuid_generate_random(uuid1); + + uuid_unparse_lower(uuid1, uuid); char hostname[100] = {0}; if (gethostname(hostname, sizeof(hostname)) < 0) { @@ -529,10 +540,16 @@ static void module_init() { char *l_millisecond = get_millisecond(); long millisecond = zend_atol(l_millisecond, strlen(l_millisecond)); efree(l_millisecond); - application_instance = registerInstance(SKYWALKING_G(grpc), application_id, millisecond, uuid, SKY_OS_NAME, hostname, getpid(), - ipv4s); - if (application_id == -100000) { + i = 0; + do { + application_instance = registerInstance(SKYWALKING_G(grpc), application_id, millisecond, uuid, SKY_OS_NAME, + hostname, getpid(), + ipv4s); + i++; + } while (application_instance == -100000 && i <= 3); + + if (application_instance == -100000) { sky_close = 1; return; } diff --git a/sky-php7ext/src/greeter_client.cc b/sky-php7ext/src/greeter_client.cc index edc17c2..2e50d16 100644 --- a/sky-php7ext/src/greeter_client.cc +++ b/sky-php7ext/src/greeter_client.cc @@ -62,13 +62,16 @@ public: Status status = stub_->applicationCodeRegister(&context, request, &reply); if (status.ok()) { - return reply.application().value(); + if (reply.has_application()) { + return reply.application().value(); + } + return -100000; } return -100000; } - int registerInstance(int applicationid, int registertime, char *uuid, char *osname, char *hostname, int processno, + int registerInstance(int applicationid, long registertime, char *uuid, char *osname, char *hostname, int processno, char *ipv4s) { std::unique_ptr stub_; @@ -80,8 +83,8 @@ public: request.set_applicationid(applicationid); request.set_registertime(registertime); - OSInfo *osInfo = new OSInfo; + request.set_allocated_osinfo(osInfo); osInfo->set_osname(osname); osInfo->set_hostname(hostname); @@ -96,10 +99,13 @@ public: Status status = stub_->registerInstance(&context, request, &reply); if (status.ok()) { - return reply.applicationinstanceid(); + if (reply.applicationinstanceid() != 0) { + return reply.applicationinstanceid(); + } + return -100000; } - return -1; + return -100000; } -- GitLab