1 #ifndef PUBSEQ_GATEWAY_STAT__HPP
2 #define PUBSEQ_GATEWAY_STAT__HPP
3 
4 /*  $Id: pubseq_gateway_stat.hpp 629837 2021-04-22 12:47:49Z ivanov $
5  * ===========================================================================
6  *
7  *                            PUBLIC DOMAIN NOTICE
8  *               National Center for Biotechnology Information
9  *
10  *  This software/database is a "United States Government Work" under the
11  *  terms of the United States Copyright Act.  It was written as part of
12  *  the author's official duties as a United States Government employee and
13  *  thus cannot be copyrighted.  This software/database is freely available
14  *  to the public for use. The National Library of Medicine and the U.S.
15  *  Government have not placed any restriction on its use or reproduction.
16  *
17  *  Although all reasonable efforts have been taken to ensure the accuracy
18  *  and reliability of the software and data, the NLM and the U.S.
19  *  Government do not and cannot warrant the performance or results that
20  *  may be obtained by using this software or data. The NLM and the U.S.
21  *  Government disclaim all warranties, express or implied, including
22  *  warranties of performance, merchantability or fitness for any particular
23  *  purpose.
24  *
25  *  Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Sergey Satskiy
30  *
31  * File Description:
32  *
33  */
34 
35 
36 #include <connect/services/json_over_uttp.hpp>
37 USING_NCBI_SCOPE;
38 
39 class CPSGSCounters
40 {
41     public:
42         CPSGSCounters();
43         ~CPSGSCounters();
44 
45     public:
46         enum EPSGS_CounterType {
47             ePSGS_BadUrlPath = 0,
48             ePSGS_InsufficientArgs,
49             ePSGS_MalformedArgs,
50             ePSGS_GetBlobNotFound,
51             ePSGS_UnknownError,
52             ePSGS_ClientSatToSatNameError,
53             ePSGS_ServerSatToSatNameError,
54             ePSGS_BlobPropsNotFoundError,
55             ePSGS_LMDBError,
56             ePSGS_CassQueryTimeoutError,
57             ePSGS_InvalidId2InfoError,
58             ePSGS_SplitHistoryNotFoundError,
59             ePSGS_MaxHopsExceededError,
60             ePSGS_InputSeqIdNotResolved,
61             ePSGS_TSEChunkSplitVersionCacheMatched,
62             ePSGS_TSEChunkSplitVersionCacheNotMatched,
63             ePSGS_AdminRequest,
64             ePSGS_ResolveRequest,
65             ePSGS_GetBlobBySeqIdRequest,
66             ePSGS_GetBlobBySatSatKeyRequest,
67             ePSGS_GetNamedAnnotations,
68             ePSGS_TestIORequest,
69             ePSGS_GetTSEChunk,
70             ePSGS_HealthRequest,
71             ePSGS_Si2csiCacheHit,
72             ePSGS_Si2csiCacheMiss,
73             ePSGS_BioseqInfoCacheHit,
74             ePSGS_BioseqInfoCacheMiss,
75             ePSGS_BlobPropCacheHit,
76             ePSGS_BlobPropCacheMiss,
77             ePSGS_Si2csiNotFound,
78             ePSGS_Si2csiFoundOne,
79             ePSGS_Si2csiFoundMany,
80             ePSGS_BioseqInfoNotFound,
81             ePSGS_BioseqInfoFoundOne,
82             ePSGS_BioseqInfoFoundMany,
83             ePSGS_Si2csiError,
84             ePSGS_BioseqInfoError,
85 
86             // Not pure monotonic counters;
87             // They participate in the output though so the name and identifier will be
88             // required for them too
89             ePSGS_TotalRequest,
90             ePSGS_TotalError,
91             ePSGS_CassandraActiveStatements,
92             ePSGS_NumberOfConnections,
93             ePSGS_ActiveRequest,
94             ePSGS_ShutdownRequested,
95             ePSGS_GracefulShutdownExpiredInSec
96         };
97 
98     void Increment(EPSGS_CounterType  counter);
99     void UpdateConfiguredNameDescription(
100                             const map<string, tuple<string, string>> &  conf);
101 
102     public:
103         void PopulateDictionary(CJsonNode &  dict);
104         void AppendValueNode(CJsonNode &  dict, const string &  id,
105                              const string &  name, const string &  description,
106                              uint64_t  value);
107         void AppendValueNode(CJsonNode &  dict, const string &  id,
108                              const string &  name, const string &  description,
109                              bool  value);
110         void AppendValueNode(CJsonNode &  dict, const string &  id,
111                              const string &  name, const string &  description,
112                              const string &  value);
113         void AppendValueNode(CJsonNode &  dict, EPSGS_CounterType  counter_type,
114                              uint64_t  value);
115         void AppendValueNode(CJsonNode &  dict, EPSGS_CounterType  counter_type,
116                              bool  value);
117         void AppendValueNode(CJsonNode &  dict, EPSGS_CounterType  counter_type,
118                              const string &  value);
119 
120         struct SCounterInfo
121         {
122             string                  m_Identifier;
123             string                  m_Name;
124             string                  m_Description;
125             bool                    m_IsMonotonicCounter;   // Some counters are sums
126                                                             // (like total number of errors) or
127                                                             // not really monotonic
128                                                             // like number of
129                                                             // connections. For them
130                                                             // this is 'false'
131             bool                    m_IsErrorCounter;
132             bool                    m_IsRequestCounter;
133             atomic_uint_fast64_t    m_Value;
134 
SCounterInfoCPSGSCounters::SCounterInfo135             SCounterInfo(const string &  identifier,
136                          const string &  name,
137                          const string &  description,
138                          bool  is_monotonic = true,
139                          bool  is_error = false,
140                          bool  is_request = false) :
141                 m_Identifier(identifier), m_Name(name),
142                 m_Description(description), m_IsMonotonicCounter(is_monotonic),
143                 m_IsErrorCounter(is_error), m_IsRequestCounter(is_request),
144                 m_Value(0)
145             {}
146         };
147 
148     private:
149         map<EPSGS_CounterType, SCounterInfo *>        m_Counters;
150 };
151 
152 
153 
154 /*
155 void AppendValueNode(CJsonNode &  dict,
156                      const string &  id,
157                      bool  value);
158 */
159 void AppendValueNode(CJsonNode &  dict,
160                      const string &  id,
161                      const string &  value);
162 
163 #endif
164