Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/plugins/advanced_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
advancedMetricsPluginVersion = "v0.8.0"
advancedMetricsPluginName = "Advanced Metrics Plugin"

// ordinal positions of data collected by metrics module.
httpUriDimension = "http.uri"
httpResponseCodeDimension = "http.response_code"
httpRequestMethodDimension = "http.request_method"
Expand All @@ -30,6 +31,13 @@ const (
environmentDimension = "environment"
appDimension = "app"
componentDimension = "component"
acmInfraWorkspacesNameDimension = "acm_infra_workspaces_name"
acmServiceWorkspacesNameDimension = "acm_service_workspaces_name"
acmEnvironmentsNameDimension = "acm_environments_name"
acmEnvironmentsTypeDimension = "acm_environments_type"
acmApiProxyNameDimension = "acm_api_proxy_name"
acmApiProxyHostnameDimension = "acm_api_proxy_hostname"
acmProxyApiVersionDimension = "acm_api_proxy_version"
countryCodeDimension = "country_code"
httpVersionSchemaDimension = "http.version_schema"
httpUpstreamAddrDimension = "http.upstream_addr" // TODO this should not contain http. prefix probably
Expand Down Expand Up @@ -103,6 +111,13 @@ func NewAdvancedMetrics(env core.Environment, conf *config.Config) *AdvancedMetr
NewDimension(environmentDimension, 32).
NewDimension(appDimension, 32).
NewDimension(componentDimension, 256).
NewDimension(acmInfraWorkspacesNameDimension, 256).
NewDimension(acmServiceWorkspacesNameDimension, 256).
NewDimension(acmEnvironmentsNameDimension, 256).
NewDimension(acmEnvironmentsTypeDimension, 256).
NewDimension(acmApiProxyNameDimension, 256).
NewDimension(acmApiProxyHostnameDimension, 256).
NewDimension(acmProxyApiVersionDimension, 256).
NewDimension(countryCodeDimension, 256). //TODO should be implemented as GeoIP
NewDimension(httpVersionSchemaDimension, 16).
NewDimension(httpUpstreamAddrDimension, 1024).
Expand Down
115 changes: 115 additions & 0 deletions test/integration/advanced_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ func SetupAdvancedMetrics(t *testing.T, socketLocation string) *advanced_metrics
NewDimension("environment", 32).
NewDimension("app", 32).
NewDimension("component", 256).
NewDimension("acm_infra_workspaces_name", 256).
NewDimension("acm_service_workspaces_name", 256).
NewDimension("acm_environments_name", 256).
NewDimension("acm_environments_type", 256).
NewDimension("acm_api_proxy_name", 256).
NewDimension("acm_api_proxy_hostname", 256).
NewDimension("acm_api_proxy_version", 256).
NewDimension("country_code", 256).
NewDimension("http.version_schema", 16).
NewDimension("http.upstream_addr", 1024).
Expand Down Expand Up @@ -1130,3 +1137,111 @@ func TestStreamUdpMetrics(t *testing.T) {
assert.Fail(t, "failed to receive message")
}
}

func TestAppCentricACMDimensions(t *testing.T) {
httpServerListenAddress := fmt.Sprintf("%s:8080", httpServerAddress)

socket := "/tmp/advanced_metrics.sr"
acm := SetupAdvancedMetrics(t, socket)

httpUpstream := upstream.HttpTestUpstream{
Name: "returns_200_ok",
Address: fmt.Sprintf("%s:%d", upstreamHost, upstreamPort),
Handlers: map[string]upstream.Handler{
location1: {
Handler: func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "OK")
},
},
},
}
httpUpstream.Serve(t)

var (
// acm centric
acmInfraWorkspace1 = "acm_infra_1"
acmServicesWorkspace1 = "acm_service_1"
acmEnvName1 = "acm_env_1"
envType1 = "env_type_1"
apiProxyName1 = "api_proxy_name_1"
apiHostname1 = "api_proxy_hostname_1"
apiProxyVersion1 = "api_proxy_version_1"
)

// generate config that exercises ACM dimensions using metrics marker directive
cfg := conf.NginxConf{
HttpBlock: &conf.HttpBlock{
F5MetricsServer: socket,
Upstreams: map[string]conf.Upstream{
httpUpstream.Name: httpUpstream.AsUpstream(),
},
Servers: []conf.Server{
httpUpstream.AsServer(httpServerListenAddress,
map[string]string{
conf.MarkerEnvironment: env1,
conf.MarkerGateway: gw1,
conf.AcmInfraWorkspacesNameDimension: acmInfraWorkspace1,
conf.AcmServiceWorkspacesNameDimension: acmServicesWorkspace1,
conf.AcmEnvironmentsNameDimension: acmEnvName1,
conf.AcmEnvironmentsTypeDimension: envType1,
},
upstream.LocationsMarkers{
location1: map[string]string{
conf.MarkerApp: app1,
conf.MarkerComponent: comp1,
conf.AcmApiProxyNameDimension: apiProxyName1,
conf.AcmApiProxyHostnameDimension: apiHostname1,
conf.AcmProxyApiVersionDimension: apiProxyVersion1,
},
},
upstream.LocationsDirectives{},
),
},
},
}

cmd, err := conf.NewNginxCommand(&cfg)
require.NoError(t, err)
cmd.Start(t)

location1Url := fmt.Sprintf("http://%s/loc1", httpServerListenAddress)

_, err = http.Get(location1Url)
assert.NoError(t, err)
_, err = http.Get(location1Url)
assert.NoError(t, err)

expectedDimensions := []publisher.Dimension{
{Name: "app", Value: app1},
{Name: "component", Value: comp1},
{Name: "gateway", Value: gw1},
{Name: "environment", Value: env1},
{Name: "http.uri", Value: location1},
{Name: "http.request_method", Value: "GET"},
{Name: "http.response_code", Value: "200"},
{Name: "country_code", Value: "0100007fffff00000000000000000000"},
{Name: "http.version_schema", Value: "4"},
{Name: "http.upstream_addr", Value: fmt.Sprintf("%s:%d", upstreamAddress, upstreamPort)},
{Name: "http.hostname", Value: httpServerAddress},
{Name: "family", Value: "web"},
{Name: "proxied_protocol", Value: "http"},
{Name: "request_outcome", Value: "PASSED"},
{Name: "upstream_response_code", Value: "200"},
{Name: conf.AcmInfraWorkspacesNameDimension, Value: acmInfraWorkspace1},
{Name: conf.AcmServiceWorkspacesNameDimension, Value: acmServicesWorkspace1},
{Name: conf.AcmEnvironmentsNameDimension, Value: acmEnvName1},
{Name: conf.AcmEnvironmentsTypeDimension, Value: envType1},
{Name: conf.AcmApiProxyHostnameDimension, Value: apiHostname1},
{Name: conf.AcmProxyApiVersionDimension, Value: apiProxyVersion1},
{Name: conf.AcmApiProxyNameDimension, Value: apiProxyName1},
}

select {
case metrics := <-acm.OutChannel():
assert.NotEmpty(t, metrics)
assert.Len(t, metrics, 1)
validator.AssertDimensionsEqual(t, expectedDimensions, metrics[0])
case <-time.After(time.Second * 15):
assert.Fail(t, "failed to receive message")
}
}
9 changes: 9 additions & 0 deletions test/integration/nginx/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ const (
MarkerComponent = "component"
MarkerGateway = "gateway"
MarkerPublishedApi = "published_api"

// ACM dimensions
AcmInfraWorkspacesNameDimension = "acm_infra_workspaces_name"
AcmServiceWorkspacesNameDimension = "acm_service_workspaces_name"
AcmEnvironmentsNameDimension = "acm_environments_name"
AcmEnvironmentsTypeDimension = "acm_environments_type"
AcmApiProxyNameDimension = "acm_api_proxy_name"
AcmApiProxyHostnameDimension = "acm_api_proxy_hostname"
AcmProxyApiVersionDimension = "acm_api_proxy_version"
)

type NginxConf struct {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/nginx/nginx_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const (
master_process on;
worker_processes auto;

error_log /dev/stderr;
error_log /var/log/nginx/error.log warn;

load_module modules/ngx_http_f5_metrics_module.so;
load_module modules/ngx_stream_f5_metrics_module.so;
Expand Down
4 changes: 4 additions & 0 deletions test/integration/validator/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func AssertMetricSetEqual(t *testing.T, expectedMetrics []ExpectedMetric, expect
assertMetricsEqual(t, expectedMetrics, actuallMetrics.Metrics)
}

func AssertDimensionsEqual(t *testing.T, expectedDimensions []publisher.Dimension, actualMetrics *publisher.MetricSet) {
assertDimensionsEqual(t, expectedDimensions, actualMetrics)
}

func assertMetricsEqual(t *testing.T, expectedMetrics []ExpectedMetric,
actualMetrics []publisher.Metric) {

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.