• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3558

17 Dec 2024 06:05AM UTC coverage: 59.778% (+1.6%) from 58.204%
#3558

push

travis-ci

web-flow
Merge pull request #29179 from taosdata/merge/mainto3.0

merge: form main to 3.0 branch

132787 of 287595 branches covered (46.17%)

Branch coverage included in aggregate %.

104 of 191 new or added lines in 5 files covered. (54.45%)

6085 existing lines in 168 files now uncovered.

209348 of 284746 relevant lines covered (73.52%)

8164844.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.59
/source/dnode/mnode/impl/src/mndTelem.c
1
/*
2
 * Copyright (c) 2020 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define _DEFAULT_SOURCE
17
#include "mndTelem.h"
18
#include "mndCluster.h"
19
#include "mndSync.h"
20
#include "thttp.h"
21
#include "tjson.h"
22

23
typedef struct {
24
  int64_t numOfDnode;
25
  int64_t numOfMnode;
26
  int64_t numOfVgroup;
27
  int64_t numOfDatabase;
28
  int64_t numOfSuperTable;
29
  int64_t numOfChildTable;
30
  int64_t numOfNormalTable;
31
  int64_t numOfColumn;
32
  int64_t totalPoints;
33
  int64_t totalStorage;
34
  int64_t compStorage;
35
} SMnodeStat;
36

37
static void mndGetStat(SMnode* pMnode, SMnodeStat* pStat) {
2✔
38
  memset(pStat, 0, sizeof(SMnodeStat));
2✔
39

40
  SSdb* pSdb = pMnode->pSdb;
2✔
41
  pStat->numOfDnode = sdbGetSize(pSdb, SDB_DNODE);
2✔
42
  pStat->numOfMnode = sdbGetSize(pSdb, SDB_MNODE);
2✔
43
  pStat->numOfVgroup = sdbGetSize(pSdb, SDB_VGROUP);
2✔
44
  pStat->numOfDatabase = sdbGetSize(pSdb, SDB_DB);
2✔
45
  pStat->numOfSuperTable = sdbGetSize(pSdb, SDB_STB);
2✔
46

47
  void* pIter = NULL;
2✔
48
  while (1) {
8✔
49
    SVgObj* pVgroup = NULL;
10✔
50
    pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup);
10✔
51
    if (pIter == NULL) break;
10✔
52

53
    pStat->numOfChildTable += pVgroup->numOfTables;
8✔
54
    pStat->numOfColumn += pVgroup->numOfTimeSeries;
8✔
55
    pStat->totalPoints += pVgroup->pointsWritten;
8✔
56
    pStat->totalStorage += pVgroup->totalStorage;
8✔
57
    pStat->compStorage += pVgroup->compStorage;
8✔
58

59
    sdbRelease(pSdb, pVgroup);
8✔
60
  }
61

62
  pStat->numOfChildTable = 100;
2✔
63
  pStat->numOfColumn = 200;
2✔
64
  pStat->totalPoints = 300;
2✔
65
  pStat->totalStorage = 400;
2✔
66
  pStat->compStorage = 500;
2✔
67
}
2✔
68

69
static void mndBuildRuntimeInfo(SMnode* pMnode, SJson* pJson) {
2✔
70
  SMnodeStat mstat = {0};
2✔
71
  int32_t    code = 0;
2✔
72
  int32_t    lino = 0;
2✔
73
  mndGetStat(pMnode, &mstat);
2✔
74

75
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfDnode", mstat.numOfDnode), &lino, _OVER);
2!
76
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfMnode", mstat.numOfMnode), &lino, _OVER);
2!
77
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfVgroup", mstat.numOfVgroup), &lino, _OVER);
2!
78
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfDatabase", mstat.numOfDatabase), &lino, _OVER);
2!
79
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfSuperTable", mstat.numOfSuperTable), &lino, _OVER);
2!
80
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfChildTable", mstat.numOfChildTable), &lino, _OVER);
2!
81
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfColumn", mstat.numOfColumn), &lino, _OVER);
2!
82
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfPoint", mstat.totalPoints), &lino, _OVER);
2!
83
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "totalStorage", mstat.totalStorage), &lino, _OVER);
2!
84
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "compStorage", mstat.compStorage), &lino, _OVER);
2!
85
_OVER:
2✔
86
  if (code != 0) mError("failed to mndBuildRuntimeInfo at line:%d since %s", lino, tstrerror(code));
2!
87
}
2✔
88

89
static char* mndBuildTelemetryReport(SMnode* pMnode) {
2✔
90
  char        tmp[4096] = {0};
2✔
91
  STelemMgmt* pMgmt = &pMnode->telemMgmt;
2✔
92
  int32_t     code = 0;
2✔
93
  int32_t     lino = 0;
2✔
94

95
  SJson* pJson = tjsonCreateObject();
2✔
96
  if (pJson == NULL) return NULL;
2!
97

98
  char clusterName[64] = {0};
2✔
99
  if ((terrno = mndGetClusterName(pMnode, clusterName, sizeof(clusterName))) != 0) return NULL;
2!
100
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "instanceId", clusterName), &lino, _OVER);
2!
101
  TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "reportVersion", 1), &lino, _OVER);
2!
102

103
  if (taosGetOsReleaseName(tmp, NULL, NULL, sizeof(tmp)) == 0) {
2!
104
    TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "os", tmp), &lino, _OVER);
2!
105
  }
106

107
  float numOfCores = 0;
2✔
108
  if (taosGetCpuInfo(tmp, sizeof(tmp), &numOfCores) == 0) {
2!
109
    TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "cpuModel", tmp), &lino, _OVER);
2!
110
    TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfCpu", numOfCores), &lino, _OVER);
2!
111
  } else {
112
    TAOS_CHECK_GOTO(tjsonAddDoubleToObject(pJson, "numOfCpu", tsNumOfCores), &lino, _OVER);
×
113
  }
114

115
  snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB);
2✔
116
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "memory", tmp), &lino, _OVER);
2!
117

118
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "version", td_version), &lino, _OVER);
2!
119
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "buildInfo", td_buildinfo), &lino, _OVER);
2!
120
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "gitInfo", td_gitinfo), &lino, _OVER);
2!
121
  TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "email", pMgmt->email), &lino, _OVER);
2!
122

123
  mndBuildRuntimeInfo(pMnode, pJson);
2✔
124

125
_OVER:
2✔
126
  if (code != 0) {
2!
127
    mError("failed to build telemetry report at lino:%d, since %s", lino, tstrerror(code));
×
128
  }
129
  char* pCont = tjsonToString(pJson);
2✔
130
  tjsonDelete(pJson);
2✔
131
  return pCont;
2✔
132
}
133

134
static int32_t mndProcessTelemTimer(SRpcMsg* pReq) {
2✔
135
  int32_t     code = 0;
2✔
136
  int32_t     line = 0;
2✔
137
  SMnode*     pMnode = pReq->info.node;
2✔
138
  STelemMgmt* pMgmt = &pMnode->telemMgmt;
2✔
139
  if (!tsEnableTelem) return 0;
2!
140

141
  (void)taosThreadMutexLock(&pMgmt->lock);
2✔
142
  char* pCont = mndBuildTelemetryReport(pMnode);
2✔
143
  (void)taosThreadMutexUnlock(&pMgmt->lock);
2✔
144

145
  if (pCont == NULL) {
2!
NEW
146
    return 0;
×
147
  }
148
  code = taosSendTelemReport(&pMgmt->addrMgt, tsTelemUri, tsTelemPort, pCont, strlen(pCont), HTTP_FLAT);
2✔
149
  taosMemoryFree(pCont);
2!
150
  return code;
2✔
151
_end:
152
  if (code != 0) {
153
    mError("%s failed to send at line %d since %s", __func__, line, tstrerror(code));
154
  }
155
  taosMemoryFree(pCont);
156
  return code;
157
}
158

159
int32_t mndInitTelem(SMnode* pMnode) {
1,516✔
160
  int32_t     code = 0;
1,516✔
161
  STelemMgmt* pMgmt = &pMnode->telemMgmt;
1,516✔
162

163
  (void)taosThreadMutexInit(&pMgmt->lock, NULL);
1,516✔
164
  if ((code = taosGetEmail(pMgmt->email, sizeof(pMgmt->email))) != 0)
1,516!
165
    mWarn("failed to get email since %s", tstrerror(code));
1,516!
166
  code = taosTelemetryMgtInit(&pMgmt->addrMgt, tsTelemServer);
1,516✔
167
  if (code != 0) {
1,516!
NEW
168
    mError("failed to init telemetry management since %s", tstrerror(code));
×
NEW
169
    return code;
×
170
  }
171
  mndSetMsgHandle(pMnode, TDMT_MND_TELEM_TIMER, mndProcessTelemTimer);
1,516✔
172

173
  return 0;
1,516✔
174
}
175

176
void mndCleanupTelem(SMnode* pMnode) {
1,515✔
177
  STelemMgmt* pMgmt = &pMnode->telemMgmt;
1,515✔
178
  taosTelemetryDestroy(&pMgmt->addrMgt);
1,515✔
179
  (void)taosThreadMutexDestroy(&pMgmt->lock);
1,515✔
180
}
1,515✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc