Skip to content

Commit

Permalink
Merge pull request #5 from OSC/monorepo
Browse files Browse the repository at this point in the history
Monorepo for infrastructure
  • Loading branch information
MorganRodgers authored Oct 10, 2018
2 parents c8463d0 + eebc226 commit 01731b7
Show file tree
Hide file tree
Showing 81 changed files with 4,782 additions and 21 deletions.
14 changes: 13 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,20 @@ all_components.each do |c|
end
end

def proxy_components
%w(ood-portal-generator mod_ood_proxy ood_auth_map nginx_stage).map {|name| BUILD_ROOT.join(name) }
end

proxy_components.each do |build_root|
file build_root => 'VERSION_PROXY' do
rm_rf build_root if build_root.directory?
cp_r build_root.basename, build_root
end
end


desc "Build OnDemand"
task :build => all_components.map(&:build_root)
task :build => all_components.map(&:build_root) + proxy_components

directory INSTALL_ROOT.to_s

Expand Down
1 change: 1 addition & 0 deletions VERSION_PROXY
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
20 changes: 0 additions & 20 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
[
{
"name": "ood-portal-generator",
"url": "https://github.com/OSC/ood-portal-generator",
"tag": "v0.7.1"
},
{
"name": "mod_ood_proxy",
"url": "https://github.com/OSC/mod_ood_proxy",
"tag": "v0.5.0"
},
{
"name": "ood_auth_map",
"url": "https://github.com/OSC/ood_auth_map",
"tag": "v0.0.3"
},
{
"name": "nginx_stage",
"url": "https://github.com/OSC/nginx_stage",
"tag": "v0.5.0"
},
{
"name": "dashboard",
"url": "https://github.com/OSC/ood-dashboard",
Expand Down
40 changes: 40 additions & 0 deletions mod_ood_proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Compiled Lua sources
luac.out

# luarocks build files
*.src.rock
*.zip
*.tar.gz

# Object files
*.o
*.os
*.ko
*.obj
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo
*.def
*.exp

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
106 changes: 106 additions & 0 deletions mod_ood_proxy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.5.0] - 2018-03-26
### Added
- Add logging tag to logger to distinguish from other Lua log lines.

### Changed
- Changed log level for analytics and user mapping to debug to make logs less
chatty.

### Fixed
- Fixed `req_handler` sometimes missing from logs.
[#14](https://github.com/OSC/mod_ood_proxy/issues/14)

## [0.4.0] - 2018-02-13
### Added
- Added more verbose logging feature.
[#12](https://github.com/OSC/mod_ood_proxy/issues/12)

### Changed
- Updated date in `LICENSE.txt`.

## [0.3.1] - 2017-07-25
### Fixed
- Fixed link to documentation in `README.md`.
- Fixed version number in Lua code.

## [0.3.0] - 2017-07-24
### Added
- Add `OOD_USER_ENV` to specify CGI env var used for authenticated username

### Changed
- Replaced unnecessary 307 redirects with 302 redirects.
- Ignore errors when stopping NGINX with a redirect URL.
- Modified `CHANGELOG.md` format.

### Removed
- Removed the `/nginx/start` URL option.

### Fixed
- Fix for GA session blow up due to changing document referrer.
[#11](https://github.com/OSC/mod_ood_proxy/issues/11)

## [0.2.0] - 2017-01-30
### Removed
- Remove support for client-side analytics (prefer server-side analytics).

### Fixed
- Fix query params not being passed with `/rnode`.

## [0.1.0] - 2017-01-13
### Added
- Parse backend node server info from Apache supplied env vars instead of
determining it from within mod

## [0.0.6] - 2016-11-10
### Changed
- Strip off query params in doc referer arg sent to analytics server.
- Allow redirects in analytics request.
- Increase network timeout of analytics request to 5 seconds.

## [0.0.5] - 2016-10-27
### Added
- Added server side analytics feature.

### Removed
- Reverted the `sub-uri` option when staging a PUN.

## [0.0.4] - 2016-10-11
### Fixed
- Fixed `nginx_stage pun` call with included `sub_uri` option.

## [0.0.3] - 2016-09-23
### Added
- Added sequence diagram to `README.md`.

### Removed
- Removed user map caching and made mapping more verbose.

## [0.0.2] - 2016-08-04
### Added
- Add cookie to help invalidate cache.

## [0.0.1] - 2016-06-03
### Added
- Initial release!

[Unreleased]: https://github.com/OSC/mod_ood_proxy/compare/v0.5.0...HEAD
[0.5.0]: https://github.com/OSC/mod_ood_proxy/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/OSC/mod_ood_proxy/compare/v0.3.1...v0.4.0
[0.3.1]: https://github.com/OSC/mod_ood_proxy/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/OSC/mod_ood_proxy/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/OSC/mod_ood_proxy/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/OSC/mod_ood_proxy/compare/v0.0.6...v0.1.0
[0.0.6]: https://github.com/OSC/mod_ood_proxy/compare/v0.0.5...v0.0.6
[0.0.5]: https://github.com/OSC/mod_ood_proxy/compare/v0.0.4...v0.0.5
[0.0.4]: https://github.com/OSC/mod_ood_proxy/compare/v0.0.3...v0.0.4
[0.0.3]: https://github.com/OSC/mod_ood_proxy/compare/v0.0.2...v0.0.3
[0.0.2]: https://github.com/OSC/mod_ood_proxy/compare/v0.0.1...v0.0.2
22 changes: 22 additions & 0 deletions mod_ood_proxy/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2016-2018 Jeremy Nicklas

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 changes: 18 additions & 0 deletions mod_ood_proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# mod_ood_proxy

![GitHub Release](https://img.shields.io/github/release/osc/mod_ood_proxy.svg)
[![GitHub License](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT)

An Apache HTTP Server module implementing the Open OnDemand proxy API.

For more information please visit the [Documentation].

[Documentation]: https://osc.github.io/ood-documentation/master/infrastructure/mod-ood-proxy.html

## Contributing

1. Fork it ( https://github.com/OSC/mod_ood_proxy/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
26 changes: 26 additions & 0 deletions mod_ood_proxy/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Build options
PREFIX ||= ENV['PREFIX'] || '/opt/ood/mod_ood_proxy'

#
# Tasks
#

task :default => :install

directory PREFIX

# Dynamically generate tasks for copying required files
FileList['lib/**/*.lua'].each do |source|
target = "#{PREFIX}/#{source}"
file target => [source, PREFIX] do
mkdir_p File.dirname(target) unless File.directory? File.dirname(target)
cp source, target
end
task :required_files => target
end

desc <<-DESC
Install mod_ood_proxy into PREFIX
Default: PREFIX=/opt/ood/mod_ood_proxy
DESC
task :install => :required_files
89 changes: 89 additions & 0 deletions mod_ood_proxy/lib/analytics.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
--[[
analytics_handler
Hooks into the final logging stage to parse the response headers before
phoning home with analytics (required by OOD proposal).
--]]
function analytics_handler(r)
-- read in OOD specific settings defined in the Apache config
local tracking_url = r.subprocess_env['OOD_ANALYTICS_TRACKING_URL']
local tracking_id = r.subprocess_env['OOD_ANALYTICS_TRACKING_ID']

-- read in variables set previously in the request by mod_ood_proxy
local user = r.subprocess_env['MAPPED_USER'] -- set by the user mapping code
local time_user_map = r.subprocess_env['OOD_TIME_USER_MAP'] -- set by the user mapping code
local time_begin_proxy = r.subprocess_env['OOD_TIME_BEGIN_PROXY'] -- set by the proxy code

-- only track HTML pages and authenticated users
if (r.headers_out['Content-Type'] or ''):match('text/html') and user then
local version = '1'
local hit_type = 'pageview'

-- user
local client_id = user .. '@' .. r.server_name
local user_id = user .. '@' .. r.server_name

-- session
local user_ip = r.useragent_ip
local user_agent = r.headers_in['User-Agent'] or ''

-- traffic sources
local doc_referrer = (r.headers_in['Referer'] or ''):match('^([^?]*)')

-- system info
local doc_encoding = ((r.headers_out['Content-Type'] or ''):match('charset=([%w-]+)') or ''):lower()
local user_language = ((r.headers_in['Accept-Language'] or ''):match('^([%w-]+)') or ''):lower()

-- content information
local doc_host = r.server_name
local doc_path = r.uri

-- extra computed properties
local unique_id = r:sha1(user .. user_ip .. doc_host .. doc_path .. r:clock())
local time_proxy = time_begin_proxy and math.floor((r:clock() - time_begin_proxy)/1000.0) or 0
local time_user_map = time_user_map and math.floor(time_user_map) or 0

-- custom dimensions / metrics
local cd1 = user -- Username (User)
local cd2 = unique_id -- Session ID (Session)
local cd3 = os.date('!%Y-%m-%dT%TZ') -- Timestamp (Hit)
local cd4 = r.user -- Remote Username (Hit)
local cd5 = r.method -- Request Method (Hit)
local cd6 = tostring(r.status) -- Request Status (Hit)
local cd7 = doc_referrer -- Document Referrer (Hit)
local cm1 = tostring(time_proxy) -- Proxy Time (Hit/Integer)
local cm2 = tostring(time_user_map) -- User Map Time (Hit/Integer)

-- process analytics
-- NB: Do not use the measurement protocol's document referrer as it can
-- start a new session when it changes (so we use a custom dimension)
local now = r:clock()
local query = 'v=' .. r:escape(version) ..
'&t=' .. r:escape(hit_type) ..
'&tid=' .. r:escape(tracking_id) ..
'&cid=' .. r:escape(client_id) ..
'&uid=' .. r:escape(user_id) ..
'&uip=' .. r:escape(user_ip) ..
'&ua=' .. r:escape(user_agent) ..
'&de=' .. r:escape(doc_encoding) ..
'&ul=' .. r:escape(user_language) ..
'&dh=' .. r:escape(doc_host) ..
'&dp=' .. r:escape(doc_path) ..
'&cd1=' .. r:escape(cd1) ..
'&cd2=' .. r:escape(cd2) ..
'&cd3=' .. r:escape(cd3) ..
'&cd4=' .. r:escape(cd4) ..
'&cd5=' .. r:escape(cd5) ..
'&cd6=' .. r:escape(cd6) ..
'&cd7=' .. r:escape(cd7) ..
'&cm1=' .. r:escape(cm1) ..
'&cm2=' .. r:escape(cm2)
local handle = io.popen("wget --post-data='" .. query .. "' " .. tracking_url .. " -O /dev/null -T 5 -nv 2>&1")
output = handle:read('*all'):match('^%s*(.-)%s*$')
handle:close()
r:debug("Analytics input: '" .. query .. "'")
r:debug("Analytics output: '" .. r:escape_logitem(output) .. "' [" .. (r:clock() - now)/1000.0 .. " ms]")
end

return apache2.DECLINED
end
Loading

0 comments on commit 01731b7

Please sign in to comment.