Skip to content

Commit aa32614

Browse files
committed
httpserver: add read-only monitoring module
This patch adds new module httpserver-monitoring-api that provides read-only subset of the API intended for monitoring purposes only. The monitoring flavor of httpserver provides following routes: - /api - /env - /file - /fs - /hardware - /network - /os where each of the routes expose GET-only paths. The monitoring module disables YAML file based configuration as well as SSL connectivity. It is also possible to add trace plugin - libhttpserver-api_trace.so. Please note that monitoring module re-uses the same httpserver-api source code however when compiling we pass '-DMONITORING' flag to disable subset of code not needed for monitoring functionality. We also compile the code with '-fvisibility=hidden' to further reduce size of the monitoring executable (<800K). Fixes #820 Signed-off-by: Waldemar Kozaczuk <[email protected]>
1 parent 9f3bdda commit aa32614

File tree

11 files changed

+1123
-0
lines changed

11 files changed

+1123
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.so
2+
autogen/*
3+
obj/*
4+
*.manifest
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
SRC = $(shell readlink -f ../..)
2+
include $(SRC)/modules/java-base/common.gmk
3+
INCLUDES += -I. -I../httpserver-api -I $(SRC)/libc/internal
4+
5+
# compiler flags:
6+
# -g adds debugging information to the executable file
7+
# -Wall turns on most, but not all, compiler warnings
8+
autodepend = -MD -MT $@ -MP
9+
CXXFLAGS = -g -Wall -std=c++11 -fPIC $(INCLUDES) -O2 $(autodepend) -DMONITORING -fvisibility=hidden
10+
#TODO: Figure out why lto breaks exception handling
11+
#CXXFLAGS = -g -Wall -std=c++11 -fPIC $(INCLUDES) -O2 $(autodepend) -DMONITORING -fvisibility=hidden -flto
12+
#LDFLAGS = -flto
13+
src = $(shell readlink -f ../..)
14+
15+
ifndef ARCH
16+
ARCH = x64
17+
endif
18+
19+
ifndef mode
20+
mode = release
21+
endif
22+
23+
ifndef OSV_BUILD_PATH
24+
OSV_BUILD_PATH = $(src)/build/$(mode).$(ARCH)
25+
endif
26+
boost-libs := -lboost_system -lboost_filesystem
27+
28+
# the build target executable:
29+
TARGET = httpserver-api
30+
JSON_FILES := $(wildcard api-doc/listings/*.json)
31+
JSON_CC_FILES := $(subst .json,.json.cc,$(subst api-doc/listings/,autogen/,$(JSON_FILES)))
32+
CPP_FILES := $(addprefix json/,$(notdir $(wildcard ../httpserver-api/json/*.cc))) \
33+
api/fs.cc api/os.cc api/network.cc api/hardware.cc api/env.cc api/file.cc api/api.cc \
34+
common.cc main.cc plain_server.cc server.cc connection.cc matcher.cc \
35+
reply.cc connection_manager.cc mime_types.cc request_handler.cc \
36+
transformers.cc global_server.cc request_parser.cc handlers.cc \
37+
path_holder.cc routes.cc $(JSON_CC_FILES)
38+
OBJ_FILES := $(addprefix obj/,$(CPP_FILES:.cc=.o))
39+
40+
DYN_LIBS = -lpthread -ldl -L../libtools -ltools $(boost-libs)
41+
42+
LIBS = $(DYN_LIBS) $(STATIC_LIBS)
43+
44+
quiet = $(if $V, $1, @echo " $2"; $1)
45+
very-quiet = $(if $V, $1, @$1)
46+
47+
DEPS := $(OBJ_FILES:.o=.d)
48+
49+
module: all
50+
51+
all: lib$(TARGET).so
52+
$(call very-quiet, $(SRC)/scripts/manifest_from_host.sh lib$(TARGET).so > usr.manifest)
53+
54+
lib$(TARGET).so: $(OBJ_FILES)
55+
$(call quiet, $(CXX) $(CXXFLAGS) -shared $(STATIC_LIBS) -o $@ $^ $(DYN_LIBS), LINK $@)
56+
57+
ifneq ($(MAKECMDGOALS),clean)
58+
-include $(DEPS)
59+
endif
60+
61+
autogen/%.cc: api-doc/listings/% ../httpserver-api/json2code.py
62+
$(call very-quiet, mkdir -p autogen)
63+
$(call quiet,../httpserver-api/json2code.py -outdir autogen -f $< -ns json, GEN $@)
64+
65+
$(OBJ_FILES): obj/%.o: ../httpserver-api/%.cc
66+
$(call very-quiet, mkdir -p obj/stub obj/json obj/api obj/autogen)
67+
$(call quiet, $(CXX) $(CXXFLAGS) -c -MMD -o $@ $<, CXX $@)
68+
69+
clean:
70+
$(call quiet, $(RM) -f $(TARGET), CLEAN)
71+
$(call very-quiet, $(RM) -f lib*.so)
72+
$(call very-quiet, $(RM) -rf obj)
73+
$(call very-quiet, $(RM) -rf autogen)
74+
$(call very-quiet, $(RM) -f *usr*.manifest)
75+
76+
check:
77+
# Test plain readonly HTTP
78+
cd $(src) && \
79+
make image=httpserver-monitoring-api.fg && \
80+
PYTHONPATH=$(src)/scripts modules/httpserver-api/tests/testhttpserver-monitoring-api.py
81+
82+
.PHONY: check
83+
84+
.SECONDARY:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"apiVersion":"0.0.1",
3+
"swaggerVersion":"1.2",
4+
"basePath":"{{Protocol}}://{{Host}}",
5+
"resourcePath":"/api",
6+
"produces":[
7+
"application/json"
8+
],
9+
"apis":[
10+
{
11+
"path":"/api/batch",
12+
"operations":[
13+
{
14+
"method":"POST",
15+
"summary":"Batch process API calls",
16+
"notes":"Perform batch API calls in a single command. Commands are performed sequentially and independently. Each command has its own response code",
17+
"type":"string",
18+
"errorResponses":[
19+
{
20+
"code":400,
21+
"reason":"Bad request"
22+
}
23+
],
24+
"nickname":"api_batch",
25+
"produces":[
26+
"application/json"
27+
],
28+
"parameters":[
29+
{
30+
"name":"batch",
31+
"paramType":"form",
32+
"type":"string",
33+
"required":true
34+
}
35+
]
36+
}
37+
]
38+
}
39+
]
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"apiVersion":"0.0.1",
3+
"swaggerVersion":"1.2",
4+
"basePath":"{{Protocol}}://{{Host}}",
5+
"resourcePath":"/env",
6+
"produces":[
7+
"application/json"
8+
],
9+
"apis":[
10+
{
11+
"path":"/env/{var}",
12+
"operations":[
13+
{
14+
"method":"GET",
15+
"summary":"Get an environment variable",
16+
"notes":"return the environment variable value",
17+
"type":"string",
18+
"errorResponses":[
19+
{
20+
"code":400,
21+
"reason":"Variable not found"
22+
}
23+
],
24+
"nickname":"getEnv",
25+
"produces":[
26+
"application/json"
27+
],
28+
"parameters":[
29+
{
30+
"name":"var",
31+
"description":"name of the environment variable",
32+
"required":true,
33+
"allowMultiple":true,
34+
"type":"string",
35+
"paramType":"path"
36+
}
37+
]
38+
}
39+
]
40+
},
41+
{
42+
"path":"/env/",
43+
"operations":[
44+
{
45+
"method":"GET",
46+
"summary":"Returns a list of all environment variables in the system.",
47+
"type":"array",
48+
"items": {"type": "string"},
49+
"nickname":"list_env",
50+
"produces":[
51+
"application/json"
52+
]
53+
}
54+
]
55+
}
56+
]
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
{
2+
"apiVersion":"0.0.1",
3+
"swaggerVersion":"1.2",
4+
"basePath":"{{Protocol}}://{{Host}}",
5+
"resourcePath":"/file",
6+
"produces":[
7+
"application/json"
8+
],
9+
"apis":[
10+
{
11+
"path":"/file/{path-par}",
12+
"operations":[
13+
{
14+
"method":"GET",
15+
"summary":"Get File/Directory information",
16+
"notes":"return File or Directory related information",
17+
"type":"string",
18+
"errorResponses":[
19+
{
20+
"code":404,
21+
"reason":"File not found"
22+
},
23+
{
24+
"code":400,
25+
"reason":"Bad Request"
26+
}
27+
],
28+
"nickname":"getFile",
29+
"produces":[
30+
"application/json"
31+
],
32+
"parameters":[
33+
{
34+
"name":"path-par",
35+
"description":"Full path of file or directory",
36+
"required":true,
37+
"allowMultiple":true,
38+
"type":"string",
39+
"paramType":"path"
40+
},
41+
{
42+
"name":"op",
43+
"description":"The operation to perform",
44+
"required":true,
45+
"allowMultiple":false,
46+
"type":"string",
47+
"paramType":"query",
48+
"enum":["GET", "LISTSTATUS", "GETFILESTATUS"]
49+
},
50+
{
51+
"name":"offset",
52+
"description":"Offset in a file",
53+
"required":false,
54+
"allowMultiple":false,
55+
"type":"long",
56+
"paramType":"query"
57+
},
58+
{
59+
"name":"length",
60+
"description":"The number of bytes to be processed.",
61+
"required":false,
62+
"allowMultiple":false,
63+
"type":"long",
64+
"paramType":"query"
65+
}
66+
]
67+
}
68+
]
69+
}
70+
],
71+
"models":{
72+
"ContentSummary":{
73+
"id": "ContentSummary",
74+
"properties":{
75+
"directoryCount":{
76+
"description":"The number of directories.",
77+
"type":"int",
78+
"required":true
79+
},
80+
"fileCount":{
81+
"description":"The number of files.",
82+
"type":"int",
83+
"required":true
84+
},
85+
"length":{
86+
"description":"The number of bytes used by the content.",
87+
"type":"int",
88+
"required":true
89+
},
90+
"quota":{
91+
"description":"The namespace quota of this directory.",
92+
"type":"int",
93+
"required":true
94+
},
95+
"spaceConsumed":{
96+
"description":"The disk space consumed by the content.",
97+
"type":"int",
98+
"required":true
99+
},
100+
"spaceQuota":{
101+
"description":"The disk space quota.",
102+
"type":"int",
103+
"required":true
104+
}
105+
}
106+
},
107+
"FileChecksum":{
108+
"id": "FileChecksum",
109+
"properties":{
110+
"algorithm":{
111+
"description":"The name of the checksum algorithm.",
112+
"type":"string",
113+
"required":true
114+
},
115+
"bytes":{
116+
"description":"The byte sequence of the checksum in hexadecimal.",
117+
"type":"string",
118+
"required":true
119+
},
120+
"length":{
121+
"description":"The length of the bytes (not the length of the string).",
122+
"type":"int",
123+
"required":true
124+
}
125+
}
126+
},
127+
"FileStatusProperties":{
128+
"id": "FileStatusProperties",
129+
"properties":{
130+
"accessTime":{
131+
"description":"The access time.",
132+
"type":"int",
133+
"required":true
134+
},
135+
"blockSize":{
136+
"description":"The block size of a file.",
137+
"type":"int",
138+
"required":true
139+
},
140+
"group":{
141+
"description":"The group owner.",
142+
"type":"string",
143+
"required":true
144+
},
145+
"length":{
146+
"description":"The number of bytes in a file.",
147+
"type":"long",
148+
"required":true
149+
},
150+
"modificationTime":{
151+
"description":"The modification time.",
152+
"type":"int",
153+
"required":true
154+
},
155+
"owner":{
156+
"description":"The user who is the owner.",
157+
"type":"string",
158+
"required":true
159+
},
160+
"pathSuffix":{
161+
"description":"The path suffix.",
162+
"type":"string",
163+
"required":true
164+
},
165+
"permission":{
166+
"description":"The permission represented as a octal string.",
167+
"type":"string",
168+
"required":true
169+
},
170+
"replication":{
171+
"description":"The number of replication of a file.",
172+
"type":"int",
173+
"required":true
174+
},
175+
"symlink":{
176+
"description":"The link target of a symlink.",
177+
"type":"string"
178+
},
179+
"type":{
180+
"description":"The type of the path object.",
181+
"type":"string",
182+
"required":true
183+
}
184+
}
185+
}
186+
}
187+
}

0 commit comments

Comments
 (0)