mirror of
https://github.com/facebook/sapling.git
synced 2024-09-11 10:36:52 +03:00
Add fb303 stubs in common/ to support building in the opensource repo
Summary: This adds a common/ directory with stub files required for building eden. These stubs are the same ones as used in the fboss repository: https://github.com/facebook/fboss/ Our goal is to eventually create an opensource fb303 repository with complete implementations of these files, but for now these basic stubs allow building eden. (Most of the underlying stats code that supports fb303 is already available in folly/stats/ in the folly repository.) Test Plan: Tested building eden on Ubuntu 16.04
This commit is contained in:
parent
7de5d1d90c
commit
7f58caffe4
7
common/README.md
Normal file
7
common/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
This directory mostly contains stub implementations of Facebook libraries that
|
||||
are not fully open source yet. These stubs allow the FBOSS code to build while
|
||||
we are still working on fully open sourcing these libraries.
|
||||
|
||||
The code in common/stats is the main piece that is not fully open source yet.
|
||||
We are working to eventually make all of this code available in the
|
||||
facebook/folly repository.
|
25
common/fb303/cpp/FacebookBase2.h
Normal file
25
common/fb303/cpp/FacebookBase2.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2004-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace folly {
|
||||
class EventBaseManager;
|
||||
}
|
||||
|
||||
namespace facebook { namespace fb303 {
|
||||
|
||||
class FacebookBase2 {
|
||||
public:
|
||||
explicit FacebookBase2(const char*) {}
|
||||
|
||||
void setEventBaseManager(folly::EventBaseManager*) {}
|
||||
};
|
||||
|
||||
}}
|
8
common/fb303/cpp/TARGETS
Normal file
8
common/fb303/cpp/TARGETS
Normal file
@ -0,0 +1,8 @@
|
||||
cpp_library(
|
||||
name = 'fb303',
|
||||
srcs = glob(['*.cpp']),
|
||||
headers = glob(['*.h']),
|
||||
deps = [
|
||||
'@/common/fb303/if:fb303-cpp2',
|
||||
],
|
||||
)
|
7
common/fb303/if/TARGETS
Normal file
7
common/fb303/if/TARGETS
Normal file
@ -0,0 +1,7 @@
|
||||
thrift_library(
|
||||
name = 'fb303',
|
||||
thrift_srcs = {
|
||||
'fb303.thrift': ['FacebookService'],
|
||||
},
|
||||
languages = ['cpp2'],
|
||||
)
|
53
common/fb303/if/fb303.thrift
Normal file
53
common/fb303/if/fb303.thrift
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* fb303.thrift
|
||||
*
|
||||
* Copyright (c) 2006- Facebook
|
||||
* Distributed under the Thrift Software License
|
||||
*
|
||||
* See accompanying file LICENSE or visit the Thrift site at:
|
||||
* http://developers.facebook.com/thrift/
|
||||
*
|
||||
*
|
||||
* Definition of common Facebook data types and status reporting mechanisms
|
||||
* common to all Facebook services. In some cases, these methods are
|
||||
* provided in the base implementation, and in other cases they simply define
|
||||
* methods that inheriting applications should implement (i.e. status report)
|
||||
*
|
||||
* @author Mark Slee <mcslee@facebook.com>
|
||||
*/
|
||||
|
||||
namespace cpp facebook.fb303
|
||||
|
||||
/**
|
||||
* Common status reporting mechanism across all services
|
||||
*/
|
||||
enum fb_status {
|
||||
DEAD = 0,
|
||||
STARTING = 1,
|
||||
ALIVE = 2,
|
||||
STOPPING = 3,
|
||||
STOPPED = 4,
|
||||
WARNING = 5,
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard base service
|
||||
*/
|
||||
service FacebookService {
|
||||
|
||||
/**
|
||||
* Gets the status of this service
|
||||
*/
|
||||
fb_status getStatus(),
|
||||
|
||||
/**
|
||||
* Gets the counters for this service
|
||||
*/
|
||||
map<string, i64> getCounters(),
|
||||
|
||||
/**
|
||||
* Suggest a shutdown to the server
|
||||
*/
|
||||
oneway void shutdown(),
|
||||
|
||||
} (priority = 'IMPORTANT')
|
24
common/network/if/Address.thrift
Executable file
24
common/network/if/Address.thrift
Executable file
@ -0,0 +1,24 @@
|
||||
namespace cpp facebook.network.thrift
|
||||
namespace py facebook.network.Address
|
||||
namespace d facebook.network.Address
|
||||
|
||||
# fbstring uses the small internal buffer to store the data
|
||||
# if the data is small enough (< 24 bytes).
|
||||
typedef binary (cpp.type = "::folly::fbstring") fbbinary
|
||||
|
||||
enum AddressType {
|
||||
VUNSPEC = 0,
|
||||
V4 = 1,
|
||||
V6 = 2,
|
||||
}
|
||||
|
||||
struct Address {
|
||||
1: required string addr,
|
||||
2: required AddressType type,
|
||||
3: optional i64 port = 0,
|
||||
}
|
||||
|
||||
struct BinaryAddress {
|
||||
1: required fbbinary addr,
|
||||
2: optional i64 port = 0,
|
||||
}
|
58
common/stats/ExportedHistogramMap.h
Normal file
58
common/stats/ExportedHistogramMap.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2004-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "common/stats/ExportedStatMap.h"
|
||||
|
||||
namespace facebook { namespace stats {
|
||||
|
||||
class ExportedHistogram {
|
||||
public:
|
||||
ExportedHistogram() {}
|
||||
ExportedHistogram(int, int, size_t) {}
|
||||
void addValue(std::chrono::seconds, int, int64_t) {}
|
||||
int numLevels() {return 1;}
|
||||
int sum(int numLevels) {return 0;}
|
||||
};
|
||||
|
||||
class ExportedHistogramMap {
|
||||
public:
|
||||
class SpinLockGuard {
|
||||
/* no op */
|
||||
};
|
||||
|
||||
struct LockAndHistogram {
|
||||
std::shared_ptr<SpinLock> first;
|
||||
std::shared_ptr<ExportedHistogram> second;
|
||||
};
|
||||
|
||||
LockAndHistogram getOrCreateLockAndHistogram(folly::StringPiece,
|
||||
const ExportedHistogram*,
|
||||
bool* createdPtr = nullptr) {
|
||||
if (createdPtr) *createdPtr = true;
|
||||
return LockAndHistogram();
|
||||
}
|
||||
|
||||
struct LockableHistogram : public ExportedHistogram {
|
||||
SpinLockGuard makeLockGuard() {return SpinLockGuard();}
|
||||
void addValueLocked(SpinLockGuard&, std::chrono::seconds::rep, int, uint64_t) {}
|
||||
};
|
||||
|
||||
LockableHistogram getOrCreateLockableHistogram(folly::StringPiece,
|
||||
const ExportedHistogram*,
|
||||
bool* createdPtr = nullptr) {
|
||||
if (createdPtr) {
|
||||
*createdPtr = true;
|
||||
}
|
||||
return LockableHistogram();
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
22
common/stats/ExportedHistogramMapImpl.h
Normal file
22
common/stats/ExportedHistogramMapImpl.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2004-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <folly/Range.h>
|
||||
#include <chrono>
|
||||
|
||||
#include "common/stats/ExportedHistogramMap.h"
|
||||
|
||||
namespace facebook { namespace stats {
|
||||
|
||||
class ExportedHistogramMapImpl : public ExportedHistogramMap {
|
||||
};
|
||||
|
||||
}}
|
78
common/stats/ExportedStatMap.h
Normal file
78
common/stats/ExportedStatMap.h
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2004-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <folly/Range.h>
|
||||
#include <chrono>
|
||||
|
||||
namespace facebook {
|
||||
|
||||
class SpinLock {
|
||||
};
|
||||
|
||||
class SpinLockHolder {
|
||||
public:
|
||||
explicit SpinLockHolder(SpinLock*) {}
|
||||
};
|
||||
|
||||
namespace stats {
|
||||
|
||||
enum ExportType {
|
||||
SUM,
|
||||
COUNT,
|
||||
AVG,
|
||||
RATE,
|
||||
PERCENT,
|
||||
NUM_TYPES,
|
||||
};
|
||||
|
||||
struct ExportedStat {
|
||||
void addValue(std::chrono::seconds, int64_t) {}
|
||||
void addValue(std::chrono::seconds::rep, uint64_t) {}
|
||||
void addValueLocked(std::chrono::seconds::rep, uint64_t) {}
|
||||
int numLevels() {return 1;}
|
||||
int getSum(int level) {return 0;}
|
||||
int sum(int level) {return 0;}
|
||||
};
|
||||
|
||||
class ExportedStatMap {
|
||||
public:
|
||||
class LockAndStatItem {
|
||||
public:
|
||||
std::shared_ptr<SpinLock> first;
|
||||
std::shared_ptr<ExportedStat> second;
|
||||
};
|
||||
LockAndStatItem getLockAndStatItem(folly::StringPiece,
|
||||
const ExportType* = nullptr) {
|
||||
static LockAndStatItem it = {
|
||||
std::make_shared<SpinLock>(), std::make_shared<ExportedStat>()
|
||||
};
|
||||
return it;
|
||||
}
|
||||
|
||||
class LockableStat : public ExportedStat {
|
||||
};
|
||||
|
||||
LockableStat getLockableStat(folly::StringPiece,
|
||||
const ExportType* = nullptr) {
|
||||
static LockableStat stat;
|
||||
return stat;
|
||||
}
|
||||
|
||||
std::shared_ptr<ExportedStat> getLockedStatPtr(folly::StringPiece name) {
|
||||
return std::make_shared<ExportedStat>();
|
||||
}
|
||||
|
||||
std::shared_ptr<ExportedStat> getStatPtr(folly::StringPiece name) {
|
||||
return std::make_shared<ExportedStat>();
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
22
common/stats/ExportedStatMapImpl.h
Normal file
22
common/stats/ExportedStatMapImpl.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2004-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <folly/Range.h>
|
||||
#include <chrono>
|
||||
|
||||
#include "common/stats/ExportedStatMap.h"
|
||||
|
||||
namespace facebook { namespace stats {
|
||||
|
||||
class ExportedStatMapImpl : public ExportedStatMap {
|
||||
};
|
||||
|
||||
}}
|
23
common/stats/MonotonicCounter.h
Normal file
23
common/stats/MonotonicCounter.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2004-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "common/stats/ExportedHistogramMap.h"
|
||||
#include <folly/Range.h>
|
||||
|
||||
namespace facebook { namespace stats {
|
||||
|
||||
class MonotonicCounter {
|
||||
public:
|
||||
MonotonicCounter(folly::StringPiece, ExportType, ExportType) {}
|
||||
void updateValue(std::chrono::seconds, int64_t) {}
|
||||
};
|
||||
|
||||
}}
|
16
common/stats/ServiceData.cpp
Normal file
16
common/stats/ServiceData.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2004-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
#include "common/stats/ServiceData.h"
|
||||
|
||||
static facebook::stats::ServiceData payload;
|
||||
|
||||
namespace facebook {
|
||||
facebook::stats::ServiceData* fbData = &payload;
|
||||
}
|
39
common/stats/ServiceData.h
Normal file
39
common/stats/ServiceData.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2004-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "common/stats/ExportedStatMap.h"
|
||||
#include "common/stats/ExportedHistogramMap.h"
|
||||
#include <map>
|
||||
|
||||
namespace facebook { namespace stats {
|
||||
|
||||
class ServiceData {
|
||||
public:
|
||||
ExportedStatMap* getStatMap() {
|
||||
static ExportedStatMap it;
|
||||
return ⁢
|
||||
}
|
||||
ExportedHistogramMap* getHistogramMap() {
|
||||
static ExportedHistogramMap it;
|
||||
return ⁢
|
||||
}
|
||||
void getCounters(std::map<std::string, int64_t>&) {}
|
||||
long getCounter(std::string) {return 0;};
|
||||
long clearCounter(std::string) {return 0;};
|
||||
void setUseOptionsAsFlags(bool) {}
|
||||
void setCounter(folly::StringPiece, uint32_t) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
extern stats::ServiceData* fbData;
|
||||
|
||||
}
|
55
common/stats/ThreadCachedServiceData.h
Normal file
55
common/stats/ThreadCachedServiceData.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2004-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <folly/Range.h>
|
||||
#include "common/stats/ExportedStatMap.h"
|
||||
|
||||
namespace facebook { namespace stats {
|
||||
|
||||
class ThreadCachedServiceData {
|
||||
public:
|
||||
class ThreadLocalStatsMap {
|
||||
};
|
||||
|
||||
class TLTimeseries {
|
||||
public:
|
||||
TLTimeseries(ThreadLocalStatsMap*, folly::StringPiece,
|
||||
ExportType, ExportType = ExportType()) {}
|
||||
void addValue(int64_t) {}
|
||||
};
|
||||
|
||||
class TLHistogram {
|
||||
public:
|
||||
TLHistogram(ThreadLocalStatsMap*, folly::StringPiece, int, int, int) {}
|
||||
TLHistogram(
|
||||
ThreadLocalStatsMap*, folly::StringPiece, int, int, int,
|
||||
facebook::stats::ExportType, int, int) {}
|
||||
void addValue(int64_t) {}
|
||||
void addRepeatedValue(int64_t /*value*/, int64_t /*nsamples*/) {}
|
||||
};
|
||||
|
||||
static ThreadCachedServiceData* get() {
|
||||
static ThreadCachedServiceData it;
|
||||
return ⁢
|
||||
}
|
||||
ThreadLocalStatsMap* getThreadStats() {
|
||||
static ThreadLocalStatsMap it;
|
||||
return ⁢
|
||||
}
|
||||
bool publishThreadRunning() const {
|
||||
return false;
|
||||
}
|
||||
void publishStats() {
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
Loading…
Reference in New Issue
Block a user